forked from artyshko/smd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deezer.py
executable file
·105 lines (72 loc) · 2.5 KB
/
deezer.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import requests
class Deezer(object):
def __init__(self):
'''
Init function
Creating deezer object
:return: None
'''
self.__url = 'http://api.deezer.com/'
def getSongInfo(self, id):
try:
response = requests.get(f'{self.__url}/track/{id}').json()
return ({
'uri' : f"D{response['id']}T",
'name' : response['title'],
'artist' : [response['artist']['name']],
'album' : response['album']['title'],
'image' : response['album']['cover_xl'],
'duration_ms' : response['duration']
})
except: return None
def getAlbum(self, id):
try:
response = requests.get(f'{self.__url}/album/{id}').json()
alb = {
'name':response['title'],
'artist':response['artist']['name'],
'copyright': None,
'image':response['cover_xl'],
}
tracks = []
for item in response['tracks']['data']:
tracks.append({
'uri' : f"D{item['id']}T",
'name' : item['title'],
'artist' : [item['artist']['name']],
'album' : alb['name'],
'image' : alb['image'],
'preview_url' : item['preview'],
'duration_ms' : item['duration']
})
alb.setdefault(
'tracks', tracks
)
return alb
except: return None
def getPlaylist(self, id):
try:
response = requests.get(f'{self.__url}/playlist/{id}').json()
alb = {
'name':response['title']
}
tracks = []
for item in response['tracks']['data']:
tracks.append({
'uri' : f"D{item['id']}T",
'name' : item['title'],
'artist' : [item['artist']['name']],
'album' : item['album']['title'],
'image' : item['album']['cover_xl'],
'preview_url' : item['preview'],
'duration_ms' : item['duration']
})
alb.setdefault(
'tracks', tracks
)
return alb
except: return None
if __name__ == '__main__':
deezer = Deezer()
data = deezer.getSongInfo('636758392')
print(data)