Fixed downloading related issues

- Fixed album cover download and saving
- Fixed download list initialization on reload
- Adjusted download object layout
This commit is contained in:
RemixDev 2020-04-14 12:58:31 +02:00
parent 3fdbc0174a
commit 1ed8e7bb20
2 changed files with 25 additions and 10 deletions

View File

@ -14,7 +14,7 @@ from Cryptodome.Cipher import Blowfish
from time import sleep from time import sleep
import re import re
TEMPDIR = os.path.join(gettempdir(), 'deezloader-imgs') TEMPDIR = os.path.join(gettempdir(), 'deemix-imgs')
if not os.path.isdir(TEMPDIR): if not os.path.isdir(TEMPDIR):
makedirs(TEMPDIR) makedirs(TEMPDIR)
@ -61,17 +61,19 @@ def stream_track(dz, track, stream, trackAPI, queueItem, socket=None):
if round(downloadPercentage) != lastPercentage and round(percentage) % 5 == 0: if round(downloadPercentage) != lastPercentage and round(percentage) % 5 == 0:
lastPercentage = round(downloadPercentage) lastPercentage = round(downloadPercentage)
if socket: if socket:
queueItem['progress'] = lastPercentage
socket.emit("updateQueue", {'uuid': queueItem['uuid'], 'progress': lastPercentage}) socket.emit("updateQueue", {'uuid': queueItem['uuid'], 'progress': lastPercentage})
i += 1 i += 1
def downloadImage(url, path): def downloadImage(url, path):
if not os.path.isfile(path): if not os.path.isfile(path):
with open(path, 'wb') as f:
try: try:
f.write(get(url, headers={'User-Agent': USER_AGENT_HEADER}, timeout=30).content) image = get(url, headers={'User-Agent': USER_AGENT_HEADER}, timeout=30)
with open(path, 'wb') as f:
f.write(image.content)
return path return path
except ConnectionError: except ConnectionError:
sleep(2) sleep(1)
return downloadImage(url, path) return downloadImage(url, path)
except HTTPError: except HTTPError:
print("Couldn't download Image") print("Couldn't download Image")
@ -413,6 +415,7 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
'data': track 'data': track
} }
if socket: if socket:
queueItem['failed'] += 1
socket.emit("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': track, 'error': "Track not yet encoded and no alternative found!"}) socket.emit("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': track, 'error': "Track not yet encoded and no alternative found!"})
return result return result
else: else:
@ -422,6 +425,7 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
'data': track 'data': track
} }
if socket: if socket:
queueItem['failed'] += 1
socket.emit("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': track, 'error': "Track not yet encoded!"}) socket.emit("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': track, 'error': "Track not yet encoded!"})
return result return result
@ -434,6 +438,7 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
'data': track 'data': track
} }
if socket: if socket:
queueItem['failed'] += 1
socket.emit("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': track, 'error': "Track not found at desired bitrate."}) socket.emit("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': track, 'error': "Track not found at desired bitrate."})
return result return result
elif format == -200: elif format == -200:
@ -443,6 +448,7 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
'data': track 'data': track
} }
if socket: if socket:
queueItem['failed'] += 1
socket.emit("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': track, 'error': "Track is not available in Reality Audio 360."}) socket.emit("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': track, 'error': "Track is not available in Reality Audio 360."})
return result return result
track['selectedFormat'] = format track['selectedFormat'] = format
@ -561,6 +567,7 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
'data': track 'data': track
} }
if socket: if socket:
queueItem['failed'] += 1
socket.emit("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': track, 'error': "Track not available on deezer's servers and no alternative found!"}) socket.emit("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': track, 'error': "Track not available on deezer's servers and no alternative found!"})
return result return result
else: else:
@ -570,6 +577,7 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
'data': track 'data': track
} }
if socket: if socket:
queueItem['failed'] += 1
socket.emit("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': track, 'error': "Track not available on deezer's servers!"}) socket.emit("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': track, 'error': "Track not available on deezer's servers!"})
return result return result
if track['selectedFormat'] in [3, 1, 8]: if track['selectedFormat'] in [3, 1, 8]:
@ -580,6 +588,7 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
result['searched'] = f'{track["mainArtist"]["name"]} - {track["title"]}' result['searched'] = f'{track["mainArtist"]["name"]} - {track["title"]}'
print("Done!") print("Done!")
if socket: if socket:
queueItem['downloaded'] += 1
socket.emit("updateQueue", {'uuid': queueItem['uuid'], 'downloaded': True}) socket.emit("updateQueue", {'uuid': queueItem['uuid'], 'downloaded': True})
return result return result
@ -596,6 +605,9 @@ def downloadTrackObj_wrap(dz, track, settings, bitrate, queueItem, socket):
} }
} }
} }
if socket:
queueItem['failed'] += 1
socket.emit("updateQueue", {'uuid': queueItem['uuid'], 'failed': True})
return result return result
def download(dz, queueItem, socket=None): def download(dz, queueItem, socket=None):
@ -617,6 +629,9 @@ def download(dz, queueItem, socket=None):
} }
} }
} }
if socket:
queueItem['failed'] += 1
socket.emit("updateQueue", {'uuid': queueItem['uuid'], 'failed': True})
download_path = after_download_single(result, settings, queueItem) download_path = after_download_single(result, settings, queueItem)
elif 'collection' in queueItem: elif 'collection' in queueItem:
print("Downloading collection") print("Downloading collection")

View File

@ -206,7 +206,7 @@ def callbackQueueDone(result):
nextItem(result['dz'], result['socket']) nextItem(result['dz'], result['socket'])
def getQueue(): def getQueue():
return (queue, queueList) return (queue, queueList, currentItem)
def removeFromQueue(uuid, socket=None): def removeFromQueue(uuid, socket=None):
if uuid == currentItem: if uuid == currentItem: