mirror of
https://gitlab.com/RemixDev/deezer-py.git
synced 2024-12-28 18:36:23 +00:00
Specify version in get_track_url
This commit is contained in:
parent
d8b04b15a1
commit
1231ca0685
|
@ -2,7 +2,7 @@ import requests
|
|||
from deezer.gw import GW
|
||||
from deezer.api import API
|
||||
|
||||
__version__ = "1.0.1"
|
||||
__version__ = "1.0.2"
|
||||
|
||||
class TrackFormats():
|
||||
"""Number associtation for formats"""
|
||||
|
@ -135,33 +135,33 @@ class Deezer:
|
|||
|
||||
return (self.current_user, self.selected_account)
|
||||
|
||||
def get_tracks_urls(self, track_tokens):
|
||||
def get_track_url(self, track_token, track_format):
|
||||
return self.get_tracks_url([track_token, ], track_format)
|
||||
|
||||
def get_tracks_url(self, track_tokens, track_format):
|
||||
if not isinstance(track_tokens, list):
|
||||
track_tokens = [track_tokens, ]
|
||||
if not self.current_user['license_token']:
|
||||
return []
|
||||
|
||||
response = self.session.post(
|
||||
"https://media.deezer.com/v1/get_url",
|
||||
json={
|
||||
'license_token': self.current_user['license_token'],
|
||||
'media': [{
|
||||
'type': "FULL",
|
||||
'formats': [
|
||||
{ 'cipher': "BF_CBC_STRIPE", 'format': "FLAC" },
|
||||
{ 'cipher': "BF_CBC_STRIPE", 'format': "MP3_320" },
|
||||
{ 'cipher': "BF_CBC_STRIPE", 'format': "MP3_256" },
|
||||
{ 'cipher': "BF_CBC_STRIPE", 'format': "MP3_128" },
|
||||
{ 'cipher': "BF_CBC_STRIPE", 'format': "MP3_64" },
|
||||
{ 'cipher': "BF_CBC_STRIPE", 'format': "MP3_MISC" },
|
||||
{ 'cipher': "BF_CBC_STRIPE", 'format': "MP4_RA3" },
|
||||
{ 'cipher': "BF_CBC_STRIPE", 'format': "MP4_RA2" },
|
||||
{ 'cipher': "BF_CBC_STRIPE", 'format': "MP4_RA1" }
|
||||
]
|
||||
}],
|
||||
'track_tokens': track_tokens
|
||||
},
|
||||
headers = self.http_headers
|
||||
).json()
|
||||
try:
|
||||
request = self.session.post(
|
||||
"https://media.deezer.com/v1/get_url",
|
||||
json={
|
||||
'license_token': self.current_user['license_token'],
|
||||
'media': [{
|
||||
'type': "FULL",
|
||||
'formats': [
|
||||
{ 'cipher': "BF_CBC_STRIPE", 'format': track_format }
|
||||
]
|
||||
}],
|
||||
'track_tokens': track_tokens
|
||||
},
|
||||
headers = self.http_headers
|
||||
)
|
||||
request.raise_for_status()
|
||||
response = request.json()
|
||||
except requests.exceptions.HTTPError:
|
||||
return None
|
||||
|
||||
return response['data']
|
||||
return response['data'][0]['media'][0]['sources'][0]['url']
|
||||
|
|
Loading…
Reference in a new issue