From be3f88278d9cd8cf019c5e63837b2faba7ab30bf Mon Sep 17 00:00:00 2001 From: HF0 Date: Fri, 1 Jun 2018 14:19:28 +0200 Subject: [PATCH 1/2] Improve genius search, try getting lyrics without removing letters between parenthesis --- backend.py | 25 +++++++++++++++++++------ services.py | 2 +- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/backend.py b/backend.py index 8a2ea5b..418365b 100644 --- a/backend.py +++ b/backend.py @@ -40,7 +40,6 @@ def load_lyrics(artist, song, sync=False): - error = "Error: Could not find lyrics." global current_service if current_service == len(services_list2)-1: current_service = -1 @@ -49,12 +48,12 @@ def load_lyrics(artist, song, sync=False): lyrics, url, service_name, timed = s._minilyrics(artist, song) current_service = -1 - if sync == True and lyrics == error or sync == False: + if sync == True and not lyrics_found(lyrics) or sync == False: timed = False for i in range (current_service+1, len(services_list2)): lyrics, url, service_name = services_list2[i](artist, song) current_service = i - if lyrics != error: + if lyrics_found(lyrics): lyrics = lyrics.replace("&", "&").replace("`", "'").strip() break @@ -62,6 +61,11 @@ def load_lyrics(artist, song, sync=False): return(lyrics, url, service_name, timed) +def lyrics_found(lyrics): + error = "Error: Could not find lyrics." + return lyrics != error + + def getlyrics(songname, sync=False): global artist, song, url, current_service artist = "" @@ -75,9 +79,18 @@ def getlyrics(songname, sync=False): artist, song, garbage = songname.rsplit(" - ", 2) if " / " in song: song, garbage = song.rsplit(" / ", 1) - song = re.sub(' \(.*?\)', '', song, flags=re.DOTALL) - - return load_lyrics(artist, song, sync) + + # remove letters between parenthesis from song title + song_name_without_parenthesis_content = re.sub(' \(.*?\)', '', song, flags=re.DOTALL) + lyrics_content = load_lyrics(artist, song_name_without_parenthesis_content, sync) + + # if not found try without removing letters between parenthesis + if not lyrics_found(lyrics_content[0]): + song_name_with_parenthesis_content = re.sub('[\(\\.)]', '', song) + print("second",song_name_with_parenthesis_content) + lyrics_content = load_lyrics(artist, song_name_with_parenthesis_content, sync) + + return lyrics_content def next_lyrics(): diff --git a/services.py b/services.py index 15e3c08..89b8e71 100644 --- a/services.py +++ b/services.py @@ -122,7 +122,7 @@ def _genius(artist, song): service_name = "Genius" url = "" try: - url = "http://genius.com/%s-%s-lyrics" % (artist.replace(' ', '-'), song.replace(' ', '-')) + url = "http://genius.com/%s-%s-lyrics" % (artist.replace(' ', '-'), song.replace(' ', '-').replace('\'', '')) lyricspage = requests.get(url, proxies=proxy) soup = BeautifulSoup(lyricspage.text, 'html.parser') lyrics = soup.find("div", {"class": "lyrics"}).get_text() From fd4af2103f8621fea4e37692b9ab672269acaaa9 Mon Sep 17 00:00:00 2001 From: HF0 Date: Fri, 1 Jun 2018 14:31:56 +0200 Subject: [PATCH 2/2] remove debug message --- backend.py | 1 - 1 file changed, 1 deletion(-) diff --git a/backend.py b/backend.py index 418365b..caf0d21 100644 --- a/backend.py +++ b/backend.py @@ -87,7 +87,6 @@ def getlyrics(songname, sync=False): # if not found try without removing letters between parenthesis if not lyrics_found(lyrics_content[0]): song_name_with_parenthesis_content = re.sub('[\(\\.)]', '', song) - print("second",song_name_with_parenthesis_content) lyrics_content = load_lyrics(artist, song_name_with_parenthesis_content, sync) return lyrics_content