Created
March 30, 2017 18:07
-
-
Save vectorman1/2eb964b9515894cb9a2ff1b4c187789b to your computer and use it in GitHub Desktop.
Python script to get Lyrics from an API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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