Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add file song #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions get_song.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright Anshuman73.
# Visit anshuman73.github.io for more info.
# Released under MIT License.
# Works with Python 2.7

import json
import requests

def main(query):
#get the data
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)'
'Chrome/53.0.2785.116 Safari/537.36'}
raw_data = requests.get("https://www.musixmatch.com/search/%s/lyrics" % query, headers=headers).text.encode('utf-8')
#raw_data is now a HTML dump, parse it to make it perfect json
raw_data = raw_data[raw_data.find('{', raw_data.find('mxmProps')) : raw_data.find('</script>', raw_data.find('mxmProps'))]
data = json.loads(raw_data) # Data ready to be queried

total_results = data['lyricsTracks']['length']

print "Top 5 results are:\n"

for x in xrange(5):
song = data['lyricsTracks'][str(x)]['attributes']['track_name']
artist = data['lyricsTracks'][str(x)]['attributes']['artist_name']
album = data['lyricsTracks'][str(x)]['attributes']['album_name']

print "\n\nSong Name:", song
print "\nArtist:", artist
print "\nAlbum:", album

main(str(raw_input("\nEnter the lyrics: \n\n")))