Specify version in get_track_url

This commit is contained in:
RemixDev 2021-07-25 13:05:23 +02:00
parent d8b04b15a1
commit 1231ca0685
No known key found for this signature in database
GPG key ID: B33962B465BDB51C
2 changed files with 26 additions and 26 deletions

View file

@ -2,7 +2,7 @@ import requests
from deezer.gw import GW from deezer.gw import GW
from deezer.api import API from deezer.api import API
__version__ = "1.0.1" __version__ = "1.0.2"
class TrackFormats(): class TrackFormats():
"""Number associtation for formats""" """Number associtation for formats"""
@ -135,33 +135,33 @@ class Deezer:
return (self.current_user, self.selected_account) 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): if not isinstance(track_tokens, list):
track_tokens = [track_tokens, ] track_tokens = [track_tokens, ]
if not self.current_user['license_token']: if not self.current_user['license_token']:
return [] return []
response = self.session.post( try:
"https://media.deezer.com/v1/get_url", request = self.session.post(
json={ "https://media.deezer.com/v1/get_url",
'license_token': self.current_user['license_token'], json={
'media': [{ 'license_token': self.current_user['license_token'],
'type': "FULL", 'media': [{
'formats': [ 'type': "FULL",
{ 'cipher': "BF_CBC_STRIPE", 'format': "FLAC" }, 'formats': [
{ 'cipher': "BF_CBC_STRIPE", 'format': "MP3_320" }, { 'cipher': "BF_CBC_STRIPE", 'format': track_format }
{ 'cipher': "BF_CBC_STRIPE", 'format': "MP3_256" }, ]
{ 'cipher': "BF_CBC_STRIPE", 'format': "MP3_128" }, }],
{ 'cipher': "BF_CBC_STRIPE", 'format': "MP3_64" }, 'track_tokens': track_tokens
{ 'cipher': "BF_CBC_STRIPE", 'format': "MP3_MISC" }, },
{ 'cipher': "BF_CBC_STRIPE", 'format': "MP4_RA3" }, headers = self.http_headers
{ 'cipher': "BF_CBC_STRIPE", 'format': "MP4_RA2" }, )
{ 'cipher': "BF_CBC_STRIPE", 'format': "MP4_RA1" } request.raise_for_status()
] response = request.json()
}], except requests.exceptions.HTTPError:
'track_tokens': track_tokens return None
},
headers = self.http_headers
).json()
return response['data'] return response['data'][0]['media'][0]['sources'][0]['url']

View file

@ -7,7 +7,7 @@ README = (HERE / "README.md").read_text()
setup( setup(
name="deezer-py", name="deezer-py",
version="1.0.1", version="1.0.2",
description="A wrapper for all Deezer's APIs", description="A wrapper for all Deezer's APIs",
long_description=README, long_description=README,
long_description_content_type="text/markdown", long_description_content_type="text/markdown",