import string, sys
import urllib
import xmms
def find_song2():
[artist,tune] = xmms.get_playlist_title(xmms.get_playlist_pos()).split('-')
#find artist and tune by looking at the current playing song and splitting by a - bar which ois hopefully configuered
#fix whitespace
artist = artist.rstrip()
artist = artist.replace('and','%26')
tune = tune.lstrip()
print artist
# We+Rule+the+School&submit=search&category=song
BASEURL = "http://search.sing365.com/search.php?searchstr="
# ARTIST = "artist=" + artist.replace(' ','+')
# ALBUM = "&albummode=0&album=&songmode=0&"
SONG = tune.replace(' ','+') +"&submit=search&category=song"
print BASEURL + SONG
try:
txt = urllib.urlopen(BASEURL + SONG).readlines()
except Exception,e :
print "Bad url probably some error with the tune name"
return (['not found'],artist + " - " +tune)
# print artist.replace(' ','%20').lower()
nr = 0
for x in range(0,len(txt)):
if (txt[x].lower().find(artist.replace(' ','%20').lower())!=-1):
nr = x
break
print nr #185
# print txt[185]
temp = txt[nr].split('click.php?')
# print temp
nr = 0
# print temp[1].lower()
# print artist.replace(' ','%20'
for x in range(0,len(temp)):
if (temp[x].lower().find(artist.replace(' ','%20').lower())!=-1):
nr = x
break
if (nr == 0):
print "Song not found (not avail)"
return (['not found'],artist + " - " +tune)
print nr
# print 'http://search.sing365.com/click.php?'+temp[2].split('>',1)[0]
try:
txt = urllib.urlopen('http://search.sing365.com/click.php?'+temp[nr+1].split('>',1)[0]).readlines()
except Exception,e :
print "Bad url probably some error with the tune name"
return (['not found'],artist + " - " +tune)
nr = 0
for x in range(0,len(txt)):
if (txt[x].find("Print the Lyrics")!=-1): #best row...
nr = x
break
for x in range(nr,len(txt)):
if (txt[x].find("pagead2.googlesyndication.com")!=-1):
#...if there are no google ads below
nr = x
break
nr2 = 0
for x in range(nr,len(txt)):
if (txt[x].find("color=#cccccc")!=-1):
nr2 = x
break
# print nr #132
lyric = txt[nr+2:nr2-1]
for row in range(len(lyric)):
lyric[row] = lyric[row].replace('
','')
lyric[row] = lyric[row].replace('\n','')
lyric[row] = lyric[row].replace('\r','')
# lyric[row] = lyric[row].replace(''','\'')
# lyric[row] = lyric[row].replace('"','\"')
lyric[row] = lyric[row].lstrip()
print lyric[row]
return [lyric,artist +" - " +tune]
def find_song():
[artist,tune] = xmms.get_playlist_title(xmms.get_playlist_pos()).split('-')
#find artist and tune by looking at the current playing song and splitting by a - bar which ois hopefully configuered
#fix whitespace
artist = artist.rstrip()
tune = tune.lstrip()
BASEURL = "http://www.leoslyrics.com/advanced.php?artistmode=0&"
ARTIST = "artist=" + artist.replace(' ','+')
ALBUM = "&albummode=0&album=&songmode=0&"
SONG = "song=" + tune.replace(' ','+')
EXTRA = "++&lyrics=&mode=0"
"""
BASEURL = "http://www.leoslyrics.com/advanced.php?artistmode=0&"
ARTIST = "artist=death+cab+for+cutie"
ALBUM = "&albummode=0&album=&songmode=0&"
SONG = "song=Amputations"
EXTRA = "++&lyrics=&mode=0"
"""
print BASEURL + ARTIST + ALBUM +SONG +EXTRA
url = urllib.urlopen(BASEURL + ARTIST + ALBUM +SONG +EXTRA)
txt = url.readlines()
url.close()
nr = 0
for x in range(0,len(txt)):
if (txt[x].find("listlyrics.php")!=-1):
nr = x
# print x
try:
url = urllib.urlopen("http://www.leoslyrics.com/listlyrics.php?hid=" + txt[nr].split("=")[3].split("\"")[0])
except Exception,e :
print "Song not found :("
sys.exit()
lyricraw = url.readlines()
nr = 472
#for x in range(0,len(lyricraw)):
# if (lyricraw[x].find("wanted")!=-1):
# nr = x
#print nr
x = ""
lyric = []
while (x.find("")==-1):
lyric.append(x)
x = lyricraw[nr]
nr = nr+1
#print lyric[x]
for row in lyric:
row = row.replace('
','')
row = row.replace('\n','')
row = row.replace('\r','')
row = row.lstrip()
print row
#print lyric
if (find_song2()[0]==['not found']):
find_song()