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 selectedFormat = 8
selectedFilesize = 0 selectedFilesize = filesize['default']
if int(bitrate) == 9: for format, formatNum in formats.items():
selectedFormat = 9 if formatNum <= int(bitrate) and filesize[format] > 0:
selectedFilesize = filesize['flac'] selectedFormat = formatNum
if filesize['flac'] > 0: selectedFilesize = filesize[format]
bitrateFound = True break
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
selectedFilesize = filesize['default']
return (selectedFormat, selectedFilesize) return (selectedFormat, selectedFilesize)
def parseEssentialTrackData(track, trackAPI): def parseEssentialTrackData(track, trackAPI):
@ -359,22 +338,21 @@ 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()
if not extrasPath: if not extrasPath:
extrasPath = result['extrasPath'] extrasPath = result['extrasPath']
if settings['saveArtwork'] and result['albumPath']: if settings['saveArtwork'] and result['albumPath']:
downloadImage(result['albumURL'], result['albumPath']) downloadImage(result['albumURL'], result['albumPath'])
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")
def download_artist(dz, id, settings, overwriteBitrate=False): def download_artist(dz, id, settings, overwriteBitrate=False):
artistAPI = dz.get_artist_albums(id) artistAPI = dz.get_artist_albums(id)
@ -392,19 +370,18 @@ 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()
if not extrasPath: if not extrasPath:
extrasPath = result['extrasPath'] extrasPath = result['extrasPath']
if settings['saveArtwork'] and result['albumPath']: if settings['saveArtwork'] and result['albumPath']:
downloadImage(result['albumURL'], result['albumPath']) downloadImage(result['albumURL'], result['albumPath'])
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")