From 3b3146f220e29bb623d9748802f9c7ebf3be2a7e Mon Sep 17 00:00:00 2001 From: RemixDev Date: Sun, 25 Jul 2021 13:09:12 +0200 Subject: [PATCH] Changes to make the lib work with deezer-py 1.0.2 --- deemix/downloader.py | 13 ++++++++----- deemix/types/Track.py | 8 +------- setup.py | 2 +- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/deemix/downloader.py b/deemix/downloader.py index 3e45267..e4513fd 100644 --- a/deemix/downloader.py +++ b/deemix/downloader.py @@ -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, diff --git a/deemix/types/Track.py b/deemix/types/Track.py index 81ea8e2..af16e6f 100644 --- a/deemix/types/Track.py +++ b/deemix/types/Track.py @@ -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) diff --git a/setup.py b/setup.py index 0ad7102..fd41d1b 100644 --- a/setup.py +++ b/setup.py @@ -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",