switched to lyriki

This commit is contained in:
Martin Wagner 2020-09-22 18:40:11 +02:00
parent d7089a9784
commit 6ac830adb2

View File

@ -2485,31 +2485,18 @@ class LyricsWindow(FocusFrame):
) )
update_thread.start() update_thread.start()
def _get_lyrics(self, singer, song): # partially copied from PyLyrics 1.1.0 def _get_lyrics(self, singer, song):
# Replace spaces with _ # Replace spaces with _
singer=singer.replace(' ', '_') singer=singer.replace(' ', '_')
song=song.replace(' ', '_') song=song.replace(' ', '_')
r=requests.get('http://lyrics.wikia.com/{0}:{1}'.format(singer,song)) r=requests.get('http://www.lyriki.com/{0}:{1}'.format(singer,song))
s=BeautifulSoup(r.text) s=BeautifulSoup(r.text)
# Get main lyrics holder lyrics=s.p
lyrics=s.find("div",{'class':'lyricbox'})
if lyrics is None: if lyrics is None:
raise ValueError("Song or Singer does not exist or the API does not have Lyrics") raise ValueError("Not found")
return None elif str(lyrics).startswith("<p>There is currently no text in this page."):
# Remove Scripts raise ValueError("Not found")
[s.extract() for s in lyrics('script')] output=str(lyrics).encode('utf-8', errors='replace')[3:-4].decode("utf-8").replace('\n','').replace('<br/>','\n')
# Remove Comments
comments=lyrics.findAll(text=lambda text:isinstance(text, Comment))
[comment.extract() for comment in comments]
# Remove span tag (Needed for instrumantal)
if lyrics.span is not None:
lyrics.span.extract()
# Remove unecessary tags
for tag in ['div','i','b','a']:
for match in lyrics.findAll(tag):
match.replaceWithChildren()
# Get output as a string and remove non unicode characters and replace <br> with newlines
output=str(lyrics).encode('utf-8', errors='replace')[22:-6:].decode("utf-8").replace('\n','').replace('<br/>','\n')
try: try:
return output return output
except: except: