Beispiel #1
0
'''
	Simple example to demonstrate usage of LyricsParser
'''
from LyricsParser import Parser
import sys

if len(sys.argv) == 3:
	artist = sys.argv[1]
	songname = sys.argv[2]
	song = Parser(artist, songname)
	lyrics = song.parse()
	print lyrics
else :
	print "Usage python example.py <artist-name> <song-title>"
	print "Example: python example.py eminem \"space bound\""
		#extract the tags for artist and title
		song = tagpy.FileRef(path)

		#extact required tags
		tags = song.tag()
		artist = tags.artist.lower()
		title = tags.title.lower()

		#clean and extract the title and artist name
		title = clean_text(title)
		artist = clean_text(artist)

	print "Trying to retrieve lyrics for song:", title, "by", artist

	#create a new Parser instance for this song
	parser = Parser(artist, title)

	#parse lyrics the normal way using LyricsParser
	lyrics = parser.parse()
	
	if lyrics != "":	#lyrics found
		lyrics_found = True
	else :	#lyrics not found using normal method, possibly due to incorrectly formatted artist name or title
		#searching itunes for correct artist name
		it_artist = itunes_getartist(title, artist)
		if it_artist != "Not Found":	#found on apple itunes
			parser = Parser( it_artist, title)
			lyrics = parser.parse()
			if lyrics != "":
				lyrics_found = True
		#else:			#not found even on itunes