Added error handling for new url system

This commit is contained in:
RemixDev 2021-07-25 11:34:20 +02:00
parent 90b3be50e9
commit aa69439967
No known key found for this signature in database
GPG Key ID: B33962B465BDB51C
1 changed files with 11 additions and 2 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, uuid=None, listener=None): def getPreferredBitrate(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
@ -134,6 +134,8 @@ def getPreferredBitrate(track, bitrate, shouldFallback, uuid=None, listener=None
if testedBitrate: return testedBitrate if testedBitrate: return testedBitrate
if not shouldFallback: if not shouldFallback:
if formatName == "FLAC" and not currentUser['can_stream_lossless'] or formatName == "MP3_320" and not currentUser['can_stream_hq']:
raise WrongLicense(formatName)
raise PreferredBitrateNotFound raise PreferredBitrateNotFound
if not falledBack: if not falledBack:
falledBack = True falledBack = True
@ -246,8 +248,10 @@ class Downloader:
track, track,
self.bitrate, self.bitrate,
self.settings['fallbackBitrate'], self.settings['fallbackBitrate'],
self.downloadObject.uuid, self.listener self.dz.current_user, self.downloadObject.uuid, self.listener
) )
except WrongLicense as e:
raise DownloadFailed("wrongLicense") from e
except PreferredBitrateNotFound as e: except PreferredBitrateNotFound as e:
raise DownloadFailed("wrongBitrate", track) from e raise DownloadFailed("wrongBitrate", track) from e
except TrackNot360 as e: except TrackNot360 as e:
@ -573,6 +577,7 @@ errorMessages = {
'notEncodedNoAlternative': "Track not yet encoded and no alternative found!", 'notEncodedNoAlternative': "Track not yet encoded and no alternative found!",
'wrongBitrate': "Track not found at desired bitrate.", 'wrongBitrate': "Track not found at desired bitrate.",
'wrongBitrateNoAlternative': "Track not found at desired bitrate and no alternative found!", 'wrongBitrateNoAlternative': "Track not found at desired bitrate and no alternative found!",
'wrongLicense': "Your account can't stream the track at the desired bitrate",
'no360RA': "Track is not available in Reality Audio 360.", 'no360RA': "Track is not available in Reality Audio 360.",
'notAvailable': "Track not available on deezer's servers!", 'notAvailable': "Track not available on deezer's servers!",
'notAvailableNoAlternative': "Track not available on deezer's servers and no alternative found!", 'notAvailableNoAlternative': "Track not available on deezer's servers and no alternative found!",
@ -592,3 +597,7 @@ class PreferredBitrateNotFound(DownloadError):
class TrackNot360(DownloadError): class TrackNot360(DownloadError):
pass pass
class WrongLicense(DownloadError):
def __init__(self, format):
self.message = f"Your account doesn't have the license to stream {format}"