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

View File

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

View File

@ -23,7 +23,7 @@ setup(
python_requires='>=3.7', python_requires='>=3.7',
packages=find_packages(exclude=("tests",)), packages=find_packages(exclude=("tests",)),
include_package_data=True, 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={ entry_points={
"console_scripts": [ "console_scripts": [
"deemix=deemix.__main__:download", "deemix=deemix.__main__:download",