Merge branch 'master' of uh_wot/deemix into master

This commit is contained in:
RemixDev 2020-03-04 22:11:55 +00:00 committed by Gogs
commit a837389e8b
1 changed files with 38 additions and 61 deletions

View File

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