SimonIT/spotifylyrics

How to use another source to find french rap lyrics ?

sanjuant opened this issue · 3 comments

Hello,

I noticed that unfortunately the bank of lyrics for French rap was rather weak.

Is it possible to include another source to have more lyrics available?

Currently via the Deezer API it is possible to retrieve a lot of lyrics. To do this you first need to retrieve the song id https://api.deezer.com/search?q=sch,marche%20noir .

Then you have to call the API with this id.

https://www.deezer.com/ajax/gw-light.php?method=song.getLyrics&api_version=1.0&api_token=[api-token]&sng_id=[song-id]

Source: https://stackoverflow.com/questions/42165724/how-to-get-lyrics-from-the-deezer-api#answer-59822502

I would be happy to contribute if you put me on the track to add sources ;).

Hi,

for adding a source you just have to write a function which fetches the lyrics like this:

spotifylyrics/services.py

Lines 299 to 316 in fb1fdc3

def _genius(song):
service_name = "Genius"
url = ""
lyrics = Config.ERROR
try:
url = "http://genius.com/%s-%s-lyrics" % (song.artist.replace(' ', '-'), song.name.replace(' ', '-'))
lyrics_page = requests.get(url, proxies=Config.PROXY)
soup = BeautifulSoup(lyrics_page.text, 'html.parser')
lyrics_container = soup.find("div", {"class": "lyrics"})
if lyrics_container:
lyrics = lyrics_container.get_text()
if song.artist.lower().replace(" ", "") not in soup.text.lower().replace(" ", ""):
lyrics = Config.ERROR
except requests.exceptions.RequestException as error:
print("%s: %s" % (service_name, error))
except Exception as e:
capture_exception(e)
return lyrics, url, service_name

The function has to be added than there (for not synchronized):

SERVICES_LIST2 = [s._musixmatch, s._songmeanings, s._songlyrics, s._genius, s._versuri, s._azapi]

The problem what I see is the api token. Every source fetches currently the lyrics from the webpage. There is no menu for setting an api token and because most of the users use the .exe file of this program, it would be necessary to add such menu to use the api. (I don't want that everyone uses mine token.) Another idea is to fetch the lyrics from the normal webpage like we do with the other pages

Okay, Thank you for the answer and the examples.

I understand what is at stake. Would it be possible to add the possibility of putting our identifiers for certain services?

Having a free account on Deezer allows you to get a lot of lyrics. But to display these lyrics, you must have a premium account and the lyrics are displayed as you read song with the time code.

To see example of JSON you can see this pastebin : https://pastebin.com/mLg3ZFLh

The current supported format for synchronized lyrics is lrc. With some extra effort, it will be surely possible to get the also the json format displayed.

The easiest way would be to use the settings.ini to set an api token. The file is loaded here:

def load_save_settings(self, save=False) -> None:
if self.is_loading_settings:
return
settings_file = Config.SETTINGS_DIR + "settings.ini"
section = "settings"
if not os.path.exists(settings_file):
directory = os.path.dirname(settings_file)
if not os.path.exists(directory):
os.makedirs(directory)
loaded_config = configparser.ConfigParser(strict=False)
if not save:
self.is_loading_settings = True
try:
loaded_config.read(settings_file)
except configparser.MissingSectionHeaderError:
pass
self.sync = loaded_config.getboolean(section, "syncedlyrics", fallback=False)
self.ontop = loaded_config.getboolean(section, "alwaysontop", fallback=False)
self.open_spotify = loaded_config.getboolean(section, "openspotify", fallback=False)
self.dark_theme = loaded_config.getboolean(section, "darktheme", fallback=False)
self.info = loaded_config.getboolean(section, "info", fallback=False)
self.minimize_to_tray = loaded_config.getboolean(section, "minimizetotray", fallback=False)
self.font_size_box.setValue(loaded_config.getint(section, "fontsize", fallback=10))
Config.LYRICS_DIR = loaded_config.get(section, "LyricsPath", fallback=Config.LYRICS_DIR)
streaming_service_name = loaded_config.get(section, "StreamingService", fallback=None)
if streaming_service_name:
for i in range(len(self.streaming_services)):
if str(self.streaming_services[i]) == streaming_service_name:
self.streaming_services_box.setCurrentIndex(i)
break
FORM.move(loaded_config.getint(section, "X", fallback=FORM.pos().x()),
loaded_config.getint(section, "Y", fallback=FORM.pos().y()))
if loaded_config.getboolean(section, "FullScreen", fallback=False):
FORM.showFullScreen()
elif loaded_config.getboolean(section, "Maximized", fallback=False):
FORM.showMaximized()
else:
FORM.resize(loaded_config.getint(section, "Width", fallback=FORM.width().real),
loaded_config.getint(section, "Height", fallback=FORM.height().real))
if loaded_config.getboolean(section, "disableErrorReporting", fallback=False):
self.disableErrorReporting = True
sentry_sdk.init()
self.options_combobox.setItemText(8, "Error reporting disabled")
else:
self.disableErrorReporting = False
if self.dark_theme:
self.set_dark_theme()
if self.sync:
self.options_combobox.setItemText(2, "Synced Lyrics (on)")
if self.ontop:
FORM.setWindowFlags(FORM.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)
self.options_combobox.setItemText(3, "Always on Top (on)")
FORM.show()
if self.open_spotify:
self.options_combobox.setItemText(4, "Open Spotify (on)")
if self.info:
self.options_combobox.setItemText(5, "Info (on)")
self.info_table.setVisible(True)
if self.minimize_to_tray:
self.options_combobox.setItemText(7, "Minimize to Tray (on)")
else:
loaded_config.add_section(section)
loaded_config[section]["SyncedLyrics"] = str(self.sync)
loaded_config[section]["AlwaysOnTop"] = str(self.ontop)
loaded_config[section]["OpenSpotify"] = str(self.open_spotify)
loaded_config[section]["DarkTheme"] = str(self.dark_theme)
loaded_config[section]["Info"] = str(self.info)
loaded_config[section]["MinimizeToTray"] = str(self.minimize_to_tray)
loaded_config[section]["FontSize"] = str(self.font_size_box.value())
loaded_config[section]["StreamingService"] = str(self.get_current_streaming_service())
loaded_config[section]["FullScreen"] = str(FORM.isFullScreen())
loaded_config[section]["Maximized"] = str(FORM.isMaximized())
loaded_config[section]["X"] = str(FORM.pos().x())
loaded_config[section]["Y"] = str(FORM.pos().y())
loaded_config[section]["Width"] = str(FORM.width().real)
loaded_config[section]["Height"] = str(FORM.height().real)
if self.disableErrorReporting:
loaded_config[section]["disableErrorReporting"] = str(self.disableErrorReporting)
if Config.LYRICS_DIR != Config.DEFAULT_LYRICS_DIR:
loaded_config[section]["LyricsPath"] = Config.LYRICS_DIR
with open(settings_file, 'w+') as settings:
loaded_config.write(settings)
self.is_loading_settings = False