-
Notifications
You must be signed in to change notification settings - Fork 2
/
deezer_utils.py
44 lines (36 loc) · 1.28 KB
/
deezer_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from pydeezer import Deezer
import os
from pydeezer.constants import track_formats
def download_track(track_id, track_directory, arl):
deezer, user = login(arl=arl)
track = deezer.get_track(track_id)
download_path = os.path.join(track_directory, str(track_id))
if not os.path.exists(track_directory):
os.makedirs(track_directory)
# TODO check if file already exists and return
try:
if not os.path.exists(download_path):
track["download"](download_path, quality=track_formats.MP3_320, filename=str(track_id))
except Exception:
pass
return os.path.join(download_path, str(track_id) + ".mp3")
def get_track_id(track_id, arl):
deezer, user = login(arl=arl)
return deezer.get_track(track_id)
def search_first_track(track_name, arl):
deezer, user = login(arl=arl)
result = deezer.search_tracks(query=track_name, limit=1)
if result:
return result[0]
def search_first_playlist(playlist_name, arl):
deezer, user = login(arl=arl)
result = deezer.search_playlists(query=playlist_name, limit=1)
if result:
return result[0]
def login(arl):
deezer = Deezer(arl=arl)
user = deezer.user
return deezer, user
def get_user_info(arl):
deezer, user = login(arl=arl)
return user["name"]