From b73d533c2b6b5ed18f1ce48ce9a6efe71a2100fc Mon Sep 17 00:00:00 2001 From: kermit Date: Thu, 1 Oct 2020 11:54:42 +0100 Subject: [PATCH 1/4] Fix post-download command for collections --- deemix/app/downloadjob.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deemix/app/downloadjob.py b/deemix/app/downloadjob.py index 4d948c0..3c501c7 100644 --- a/deemix/app/downloadjob.py +++ b/deemix/app/downloadjob.py @@ -211,7 +211,7 @@ class DownloadJob: f.write((line + "\n").encode('utf-8')) # Execute command after download if self.settings['executeCommand'] != "": - execute(self.settings['executeCommand'].replace("%folder%", self.extrasPath)) + execute(self.settings['executeCommand'].replace("%folder%", str(self.extrasPath))) def download(self, trackAPI_gw, track=None): result = {} From 0a11f53c4c13ea689c3d82798081fbbc61236910 Mon Sep 17 00:00:00 2001 From: kermit Date: Thu, 1 Oct 2020 11:56:39 +0100 Subject: [PATCH 2/4] Consistent logging --- deemix/app/downloadjob.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/deemix/app/downloadjob.py b/deemix/app/downloadjob.py index 3c501c7..c283071 100644 --- a/deemix/app/downloadjob.py +++ b/deemix/app/downloadjob.py @@ -651,6 +651,8 @@ class DownloadJob: chunkLength = start percentage = 0 + itemName = f"[{track.mainArtist['name']} - {track.title}]" + try: with self.dz.session.get(track.downloadUrl, headers=headers, stream=True, timeout=10) as request: request.raise_for_status() @@ -662,9 +664,9 @@ class DownloadJob: raise DownloadEmpty if start != 0: responseRange = request.headers["Content-Range"] - logger.info(f'{track.title} downloading range {responseRange}') + logger.info(f'{itemName} downloading range {responseRange}') else: - logger.info(f'{track.title} downloading {complete} bytes') + logger.info(f'{itemName} downloading {complete} bytes') for chunk in request.iter_content(2048 * 3): if self.queueItem.cancel: raise DownloadCancelled @@ -685,7 +687,7 @@ class DownloadJob: self.updatePercentage() except SSLError as e: - logger.info(f'retrying {track.title} from byte {chunkLength}') + logger.info(f'{itemName} retrying from byte {chunkLength}') return self.streamTrack(stream, track, chunkLength) except (request_exception.ConnectionError, requests.exceptions.ReadTimeout): eventlet.sleep(2) From 314beb682fa568a14f3005ef3ff0c6ebbfd75d28 Mon Sep 17 00:00:00 2001 From: kermit Date: Thu, 1 Oct 2020 11:56:51 +0100 Subject: [PATCH 3/4] Expose extrasPath to queue item --- deemix/app/downloadjob.py | 3 ++- deemix/app/queueitem.py | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/deemix/app/downloadjob.py b/deemix/app/downloadjob.py index c283071..107ac3b 100644 --- a/deemix/app/downloadjob.py +++ b/deemix/app/downloadjob.py @@ -577,8 +577,9 @@ class DownloadJob: logger.info(f"[{track.mainArtist['name']} - {track.title}] Track download completed\n{str(writepath)}") self.queueItem.downloaded += 1 self.queueItem.files.append(str(writepath)) + self.queueItem.extrasPath = str(self.extrasPath) if self.interface: - self.interface.send("updateQueue", {'uuid': self.queueItem.uuid, 'downloaded': True, 'downloadPath': str(writepath)}) + self.interface.send("updateQueue", {'uuid': self.queueItem.uuid, 'downloaded': True, 'downloadPath': str(writepath), 'extrasPath': str(self.extrasPath)}) return result def getPreferredBitrate(self, track): diff --git a/deemix/app/queueitem.py b/deemix/app/queueitem.py index 819f331..49e223b 100644 --- a/deemix/app/queueitem.py +++ b/deemix/app/queueitem.py @@ -9,6 +9,7 @@ class QueueItem: self.type = queueItemDict['type'] self.id = queueItemDict['id'] self.bitrate = queueItemDict['bitrate'] + self.extrasPath = queueItemDict.get('extrasPath', '') self.files = queueItemDict['files'] self.downloaded = queueItemDict['downloaded'] self.failed = queueItemDict['failed'] @@ -24,6 +25,7 @@ class QueueItem: self.type = type self.id = id self.bitrate = bitrate + self.extrasPath = None self.files = [] self.settings = settings self.downloaded = 0 @@ -41,6 +43,7 @@ class QueueItem: 'cover': self.cover, 'explicit': self.explicit, 'size': self.size, + 'extrasPath': self.extrasPath, 'files': self.files, 'downloaded': self.downloaded, 'failed': self.failed, From 43676f9f342e98f01222cd2b320ef91468b9f26b Mon Sep 17 00:00:00 2001 From: kermit Date: Thu, 1 Oct 2020 13:30:40 +0100 Subject: [PATCH 4/4] Green the post-download commands so socketio connection doesn't drop --- deemix/app/downloadjob.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/deemix/app/downloadjob.py b/deemix/app/downloadjob.py index 107ac3b..4cc7e2d 100644 --- a/deemix/app/downloadjob.py +++ b/deemix/app/downloadjob.py @@ -1,4 +1,6 @@ import eventlet +from eventlet.green.subprocess import call as execute + from os.path import sep as pathSep from pathlib import Path import re @@ -9,7 +11,7 @@ get = requests.get request_exception = requests.exceptions from ssl import SSLError -from os import makedirs, remove, system as execute +from os import makedirs from tempfile import gettempdir from deemix.app.queueitem import QISingle, QICollection @@ -156,7 +158,7 @@ class DownloadJob: f.write(orig.encode('utf-8')) # Execute command after download if self.settings['executeCommand'] != "": - execute(self.settings['executeCommand'].replace("%folder%", str(self.extrasPath)).replace("%filename%", result['filename'])) + execute(self.settings['executeCommand'].replace("%folder%", str(self.extrasPath)).replace("%filename%", result['filename']), shell=True) def collectionAfterDownload(self, tracks): if not self.extrasPath: @@ -211,7 +213,7 @@ class DownloadJob: f.write((line + "\n").encode('utf-8')) # Execute command after download if self.settings['executeCommand'] != "": - execute(self.settings['executeCommand'].replace("%folder%", str(self.extrasPath))) + execute(self.settings['executeCommand'].replace("%folder%", str(self.extrasPath)), shell=True) def download(self, trackAPI_gw, track=None): result = {}