Skip to content

Instantly share code, notes, and snippets.

@akashrchandran
Created September 25, 2022 08:03
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save akashrchandran/95915c2081815397c454bd8aa4a118b5 to your computer and use it in GitHub Desktop.
Save akashrchandran/95915c2081815397c454bd8aa4a118b5 to your computer and use it in GitHub Desktop.
A simple way to get synchronised album lyrics from deezer and save it lrc file.
import requests
import contextlib
API_BASE = 'http://www.deezer.com/ajax/gw-light.php'
session = requests.Session()
def api_call(token, method, json=None):
params = {'api_version': "1.0", 'api_token': token,'input': '3', 'method': method}
req = session.post(API_BASE, params=params, json=json)
return req.json()
token = api_call('null', 'deezer.getUserData')["results"]["checkForm"]
alb_id = input("Please enter the album link: ").split("/")[-1]
album = api_call(token, "song.getListByAlbum", json={'alb_id': alb_id, 'nb': -1})
if album['error']:
print("The album link seems to be invalid.")
exit(0)
for song in album['results']['data']:
lyrics = api_call(token, 'song.getLyrics', json={'sng_id': song['SNG_ID']})
if lyrics['error']:
print("Something went wrong!")
break
with open(f'{song["TRACK_NUMBER"]}. {song["SNG_TITLE"]}.lrc', 'a+') as f:
for sync in lyrics['results']['LYRICS_SYNC_JSON']:
with contextlib.suppress(Exception):
f.write(f"{sync['lrc_timestamp']} {sync['line']}\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment