Changes to make the lib work with deezer-py 1.0.2

This commit is contained in:
RemixDev 2021-07-25 13:09:12 +02:00
parent d0cf20db8f
commit 3b3146f220
No known key found for this signature in database
GPG key ID: B33962B465BDB51C
3 changed files with 10 additions and 13 deletions

View file

@ -81,7 +81,7 @@ def downloadImage(url, path, overwrite=OverwriteOption.DONT_OVERWRITE):
logger.exception("Error while downloading an image, you should report this to the developers: %s", e)
return None
def getPreferredBitrate(track, bitrate, shouldFallback, currentUser, uuid=None, listener=None):
def getPreferredBitrate(dz, track, bitrate, shouldFallback, currentUser, uuid=None, listener=None):
bitrate = int(bitrate)
if track.local: return TrackFormats.LOCAL
@ -110,7 +110,9 @@ def getPreferredBitrate(track, bitrate, shouldFallback, currentUser, uuid=None,
def testBitrate(track, formatNumber, formatName):
if formatName not in track.urls:
track.urls[formatName] = generateCryptedStreamURL(track.id, track.MD5, track.mediaVersion, formatNumber)
url = dz.get_track_url(track.trackToken, formatName)
if not url: url = generateCryptedStreamURL(track.id, track.MD5, track.mediaVersion, formatNumber)
track.urls[formatName] = url
request = requests.head(
track.urls[formatName],
headers={'User-Agent': USER_AGENT_HEADER},
@ -245,6 +247,7 @@ class Downloader:
self.log(itemData, "getBitrate")
try:
selectedFormat = getPreferredBitrate(
self.dz,
track,
self.bitrate,
self.settings['fallbackBitrate'],
@ -360,7 +363,9 @@ class Downloader:
if not trackAlreadyDownloaded or self.settings['overwriteFile'] == OverwriteOption.OVERWRITE:
if formatsName[track.bitrate] not in track.urls:
track.urls[formatsName[track.bitrate]] = generateCryptedStreamURL(track.id, track.MD5, track.mediaVersion, track.bitrate)
url = self.dz.get_track_url(track.trackToken, formatsName[track.bitrate])
if not url: url = generateCryptedStreamURL(track.id, track.MD5, track.mediaVersion, track.bitrate)
track.urls[formatsName[track.bitrate]] = url
track.downloadURL = track.urls[formatsName[track.bitrate]]
try:
@ -434,7 +439,6 @@ class Downloader:
newTrack = self.dz.gw.get_track_with_fallback(track.fallbackID)
track.parseEssentialData(newTrack)
track.retriveFilesizes(self.dz)
track.retriveTrackURLs(self.dz)
return self.downloadWrapper(extraData, track)
if not track.searched and self.settings['fallbackSearch']:
self.warn(itemData, error.errid, 'search')
@ -443,7 +447,6 @@ class Downloader:
newTrack = self.dz.gw.get_track_with_fallback(searchedId)
track.parseEssentialData(newTrack)
track.retriveFilesizes(self.dz)
track.retriveTrackURLs(self.dz)
track.searched = True
if self.listener: self.listener.send('queueUpdate', {
'uuid': self.downloadObject.uuid,

View file

@ -68,6 +68,7 @@ class Track:
if 'FALLBACK' in trackAPI_gw:
self.fallbackID = trackAPI_gw['FALLBACK']['SNG_ID']
self.local = int(self.id) < 0
self.urls = {}
def retriveFilesizes(self, dz):
guest_sid = dz.session.cookies.get('sid')
@ -107,7 +108,6 @@ class Track:
except APIError: trackAPI = None
self.parseEssentialData(trackAPI_gw, trackAPI)
self.retriveTrackURLs(dz)
if self.local:
self.parseLocalTrackData(trackAPI_gw)
@ -245,12 +245,6 @@ class Track:
self.artist[artist['role']] = []
self.artist[artist['role']].append(artist['name'])
def retriveTrackURLs(self, dz):
urls = dz.get_tracks_urls(self.trackToken)
self.urls = {}
for url in urls[0]['media']:
self.urls[url['format']] = url['sources'][0]['url']
def removeDuplicateArtists(self):
(self.artist, self.artists) = removeDuplicateArtists(self.artist, self.artists)

View file

@ -23,7 +23,7 @@ setup(
python_requires='>=3.7',
packages=find_packages(exclude=("tests",)),
include_package_data=True,
install_requires=["click", "pycryptodomex", "mutagen", "requests", "spotipy>=2.11.0", "deezer-py>=1.0.1"],
install_requires=["click", "pycryptodomex", "mutagen", "requests", "spotipy>=2.11.0", "deezer-py>=1.0.2"],
entry_points={
"console_scripts": [
"deemix=deemix.__main__:download",