Fixed some issues to make the lib work

This commit is contained in:
RemixDev 2021-06-08 19:12:15 +02:00
parent 8b7417f8c4
commit 97cd903289
No known key found for this signature in database
GPG Key ID: B33962B465BDB51C
5 changed files with 17 additions and 14 deletions

View File

@ -154,8 +154,8 @@ class Downloader:
if isinstance(self.downloadObject, Single):
track = self.downloadWrapper({
'trackAPI_gw': self.downloadObject.single['trackAPI_gw'],
'trackAPI': self.downloadObject.single['trackAPI'],
'albumAPI': self.downloadObject.single['albumAPI']
'trackAPI': self.downloadObject.single.get('trackAPI'),
'albumAPI': self.downloadObject.single.get('albumAPI')
})
if track: self.afterDownloadSingle(track)
elif isinstance(self.downloadObject, Collection):
@ -164,8 +164,8 @@ class Downloader:
for pos, track in enumerate(self.downloadObject.collection['tracks_gw'], start=0):
tracks[pos] = executor.submit(self.downloadWrapper, {
'trackAPI_gw': track,
'albumAPI': self.downloadObject.collection['albumAPI'],
'playlistAPI': self.downloadObject.collection['playlistAPI']
'albumAPI': self.downloadObject.collection.get('albumAPI'),
'playlistAPI': self.downloadObject.collection.get('playlistAPI')
})
self.afterDownloadCollection(tracks)
@ -179,9 +179,9 @@ class Downloader:
def download(self, extraData, track=None):
returnData = {}
trackAPI_gw = extraData['trackAPI_gw']
trackAPI = extraData['trackAPI']
albumAPI = extraData['albumAPI']
playlistAPI = extraData['playlistAPI']
trackAPI = extraData.get('trackAPI')
albumAPI = extraData.get('albumAPI')
playlistAPI = extraData.get('playlistAPI')
if self.downloadObject.isCanceled: raise DownloadCanceled
if trackAPI_gw['SNG_ID'] == "0": raise DownloadFailed("notOnDeezer")
@ -327,6 +327,8 @@ class Downloader:
try:
with open(writepath, 'wb') as stream:
streamTrack(stream, track, downloadObject=self.downloadObject, listener=self.listener)
except requests.exceptions.HTTPError as e:
raise DownloadFailed('notAvailable', track) from e
except OSError as e:
if writepath.is_file(): writepath.unlink()
if e.errno == errno.ENOSPC: raise DownloadFailed("noSpaceLeft") from e
@ -386,7 +388,7 @@ class Downloader:
if trackAPI_gw.get('VERSION') and trackAPI_gw['VERSION'] not in trackAPI_gw['SNG_TITLE']:
tempTrack['title'] += f" {trackAPI_gw['VERSION']}".strip()
itemName = f"[{track.mainArtist.name} - {track.title}]"
itemName = f"[{tempTrack['artist']} - {tempTrack['title']}]"
try:
result = self.download(extraData, track)

View File

@ -20,7 +20,7 @@ class FeaturesOption():
MOVE_TITLE = "2" # Move to track title
DEFAULTS = {
"downloadLocation": localpaths.getMusicFolder(),
"downloadLocation": str(localpaths.getMusicFolder()),
"tracknameTemplate": "%artist% - %title%",
"albumTracknameTemplate": "%tracknumber% - %title%",
"playlistTracknameTemplate": "%position% - %artist% - %title%",
@ -122,11 +122,11 @@ def load(configFolder=None):
def check(settings):
changes = 0
for i_set in DEFAULTS:
if not i_set in settings or not isinstance(settings[i_set], DEFAULTS[i_set]):
if not i_set in settings or not isinstance(settings[i_set], type(DEFAULTS[i_set])):
settings[i_set] = DEFAULTS[i_set]
changes += 1
for i_set in DEFAULTS['tags']:
if not i_set in settings['tags'] or not isinstance(settings['tags'][i_set], DEFAULTS['tags'][i_set]):
if not i_set in settings['tags'] or not isinstance(settings['tags'][i_set], type(DEFAULTS['tags'][i_set])):
settings['tags'][i_set] = DEFAULTS['tags'][i_set]
changes += 1
if settings['downloadLocation'] == "":

View File

@ -8,7 +8,7 @@ class IDownloadObject:
self.artist = obj['artist']
self.cover = obj['cover']
self.explicit = obj.get('explicit', False)
self.size = obj['size']
self.size = obj.get('size', 0)
self.downloaded = obj.get('downloaded', 0)
self.failed = obj.get('failed', 0)
self.progress = obj.get('progress', 0)
@ -16,6 +16,7 @@ class IDownloadObject:
self.files = obj.get('files', [])
self.progressNext = 0
self.uuid = f"{self.type}_{self.id}_{self.bitrate}"
self.isCanceled = False
self.__type__ = None
def toDict(self):

View File

@ -11,7 +11,7 @@ class Lyrics:
syncLyricsJson = lyricsAPI["LYRICS_SYNC_JSON"]
timestamp = ""
milliseconds = 0
for line in enumerate(syncLyricsJson):
for line, _ in enumerate(syncLyricsJson):
if syncLyricsJson[line]["line"] != "":
timestamp = syncLyricsJson[line]["lrc_timestamp"]
milliseconds = int(syncLyricsJson[line]["milliseconds"])

View File

@ -74,7 +74,7 @@ def generatePath(track, downloadObject, settings):
elif downloadObject.type == "album":
filenameTemplate = settings['albumTracknameTemplate']
else:
filenameTemplate = settings['plyalistTracknameTemplate']
filenameTemplate = settings['playlistTracknameTemplate']
filename = generateTrackName(filenameTemplate, track, settings)