cleaned up some functions

This commit is contained in:
uh_wot 2020-03-04 23:02:18 +01:00
parent 880ee2a32e
commit b077b996ed
1 changed files with 38 additions and 61 deletions

View File

@ -39,35 +39,14 @@ def downloadImage(url, path):
def getPreferredBitrate(filesize, bitrate):
bitrateFound = False
selectedFormat = 0
selectedFilesize = 0
if int(bitrate) == 9:
selectedFormat = 9
selectedFilesize = filesize['flac']
if filesize['flac'] > 0:
bitrateFound = True
else:
bitrateFound = False
bitrate = 3
if int(bitrate) == 3:
selectedFormat = 3
selectedFilesize = filesize['mp3_320']
if filesize['mp3_320'] > 0:
bitrateFound = True
else:
bitrateFound = False
bitrate = 1
if int(bitrate) == 1:
selectedFormat = 1
selectedFilesize = filesize['mp3_128']
if filesize['mp3_128'] > 0:
bitrateFound = True
else:
bitrateFound = False
if not bitrateFound:
formats = {'flac': 9, 'mp3_320': 3, 'mp3_128': 1}
selectedFormat = 8
selectedFilesize = filesize['default']
for format, formatNum in formats.items():
if formatNum <= int(bitrate) and filesize[format] > 0:
selectedFormat = formatNum
selectedFilesize = filesize[format]
break
return (selectedFormat, selectedFilesize)
def parseEssentialTrackData(track, trackAPI):
@ -359,7 +338,7 @@ def download_album(dz, id, settings, overwriteBitrate=False):
trackAPI['POSITION'] = pos
trackAPI['FILENAME_TEMPLATE'] = settings['albumTracknameTemplate']
playlist[pos-1] = executor.submit(downloadTrackObj, dz, trackAPI, settings, overwriteBitrate)
executor.shutdown(wait=True)
extrasPath = None
for index in range(len(playlist)):
result = playlist[index].result()
@ -370,8 +349,7 @@ def download_album(dz, id, settings, overwriteBitrate=False):
if settings['saveArtworkArtist'] and result['artistPath']:
downloadImage(result['artistURL'], result['artistPath'])
playlist[index] = result['playlistPosition']
if settings['createM3U8File']:
if extrasPath != "" or extrasPath != None:
if settings['createM3U8File'] and extrasPath:
with open(os.path.join(extrasPath, 'playlist.m3u8'), 'w') as f:
for line in playlist:
f.write(line+"\n")
@ -392,7 +370,7 @@ def download_playlist(dz, id, settings, overwriteBitrate=False):
trackAPI['POSITION'] = pos
trackAPI['FILENAME_TEMPLATE'] = settings['playlistTracknameTemplate']
playlist[pos-1] = executor.submit(downloadTrackObj, dz, trackAPI, settings, overwriteBitrate)
executor.shutdown(wait=True)
extrasPath = None
for index in range(len(playlist)):
result = playlist[index].result()
@ -403,8 +381,7 @@ def download_playlist(dz, id, settings, overwriteBitrate=False):
if settings['saveArtworkArtist'] and result['artistPath']:
downloadImage(result['artistURL'], result['artistPath'])
playlist[index] = result['playlistPosition']
if settings['createM3U8File']:
if extrasPath != "" or extrasPath != None:
if settings['createM3U8File'] and extrasPath:
with open(os.path.join(extrasPath, 'playlist.m3u8'), 'w') as f:
for line in playlist:
f.write(line+"\n")