Skip to content

Instantly share code, notes, and snippets.

@vectorman1 vectorman1/lyrics.py
Created Mar 30, 2017

Embed
What would you like to do?
Python script to get Lyrics from an API
import json
from pip._vendor import requests
# You only need to input your API key
__APIKEY__ = ""
__APIURL__ = "http://api.musixmatch.com/ws/1.1/"
endpoints = ["track.search?q_track={}&page_size=10000&page=1&s_track_rating=desc", "track.lyrics.get?track_id={}"]
song = input("Enter the song's title:")
responsesForLyrics = []
responseForSong = requests.get(__APIURL__ + endpoints[0].format(song) + "&apikey={}".format(__APIKEY__))
json_dataSong = json.loads(responseForSong.content)
if json_dataSong['message']['header']['status_code'] is 200 and json_dataSong['message']['header']['available'] > 0:
songs = []
for song in json_dataSong['message']['body']['track_list']:
songs.append(song)
for song in songs:
requestedLyrics = requests.get(__APIURL__ +
endpoints[1].format(song['track']['track_id']) +
"&apikey={}".format(__APIKEY__)).content
lyric = json.loads(requestedLyrics)
if lyric['message']['header']['status_code'] is 200:
print(lyric['message']['body']['lyrics']['lyrics_body'])
print("Are these the lyrics? Song's by {}...".format(song['track']['artist_name']))
confirm = input("\ny(es) or n(o):")
if confirm is "n" or confirm is "no":
songs.pop(songs.index(song))
if songs is []:
print("No more lyrics were found...")
continue
elif confirm is "y" or confirm is "yes":
break
else:
print("You have not entered a valid choice.")
else:
print("Songs were found but no lyrics could be located.")
exit(2)
else:
print("No song found.")
exit(1)
exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.