Skip to content
Open
Show file tree
Hide file tree
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
24 changes: 18 additions & 6 deletions backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -49,19 +48,24 @@ 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

#return "Error: Could not find lyrics." if the for loop doens't find any lyrics
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 = ""
Expand All @@ -75,9 +79,17 @@ 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)
lyrics_content = load_lyrics(artist, song_name_with_parenthesis_content, sync)

return lyrics_content


def next_lyrics():
Expand Down
2 changes: 1 addition & 1 deletion services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down