Merge pull request 'Assorted fixes' (#69) from kermit/deemix:fixes into main

Reviewed-on: https://codeberg.org/RemixDev/deemix/pulls/69
This commit is contained in:
RemixDev 2020-10-01 18:40:39 +02:00
commit d3c7ce8ce0
2 changed files with 15 additions and 7 deletions

View File

@ -1,4 +1,6 @@
import eventlet import eventlet
from eventlet.green.subprocess import call as execute
from os.path import sep as pathSep from os.path import sep as pathSep
from pathlib import Path from pathlib import Path
import re import re
@ -9,7 +11,7 @@ get = requests.get
request_exception = requests.exceptions request_exception = requests.exceptions
from ssl import SSLError from ssl import SSLError
from os import makedirs, remove, system as execute from os import makedirs
from tempfile import gettempdir from tempfile import gettempdir
from deemix.app.queueitem import QISingle, QICollection from deemix.app.queueitem import QISingle, QICollection
@ -156,7 +158,7 @@ class DownloadJob:
f.write(orig.encode('utf-8')) f.write(orig.encode('utf-8'))
# Execute command after download # Execute command after download
if self.settings['executeCommand'] != "": 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): def collectionAfterDownload(self, tracks):
if not self.extrasPath: if not self.extrasPath:
@ -211,7 +213,7 @@ class DownloadJob:
f.write((line + "\n").encode('utf-8')) f.write((line + "\n").encode('utf-8'))
# Execute command after download # Execute command after download
if self.settings['executeCommand'] != "": if self.settings['executeCommand'] != "":
execute(self.settings['executeCommand'].replace("%folder%", self.extrasPath)) execute(self.settings['executeCommand'].replace("%folder%", str(self.extrasPath)), shell=True)
def download(self, trackAPI_gw, track=None): def download(self, trackAPI_gw, track=None):
result = {} result = {}
@ -577,8 +579,9 @@ class DownloadJob:
logger.info(f"[{track.mainArtist['name']} - {track.title}] Track download completed\n{str(writepath)}") logger.info(f"[{track.mainArtist['name']} - {track.title}] Track download completed\n{str(writepath)}")
self.queueItem.downloaded += 1 self.queueItem.downloaded += 1
self.queueItem.files.append(str(writepath)) self.queueItem.files.append(str(writepath))
self.queueItem.extrasPath = str(self.extrasPath)
if self.interface: 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 return result
def getPreferredBitrate(self, track): def getPreferredBitrate(self, track):
@ -651,6 +654,8 @@ class DownloadJob:
chunkLength = start chunkLength = start
percentage = 0 percentage = 0
itemName = f"[{track.mainArtist['name']} - {track.title}]"
try: try:
with self.dz.session.get(track.downloadUrl, headers=headers, stream=True, timeout=10) as request: with self.dz.session.get(track.downloadUrl, headers=headers, stream=True, timeout=10) as request:
request.raise_for_status() request.raise_for_status()
@ -662,9 +667,9 @@ class DownloadJob:
raise DownloadEmpty raise DownloadEmpty
if start != 0: if start != 0:
responseRange = request.headers["Content-Range"] responseRange = request.headers["Content-Range"]
logger.info(f'{track.title} downloading range {responseRange}') logger.info(f'{itemName} downloading range {responseRange}')
else: else:
logger.info(f'{track.title} downloading {complete} bytes') logger.info(f'{itemName} downloading {complete} bytes')
for chunk in request.iter_content(2048 * 3): for chunk in request.iter_content(2048 * 3):
if self.queueItem.cancel: raise DownloadCancelled if self.queueItem.cancel: raise DownloadCancelled
@ -685,7 +690,7 @@ class DownloadJob:
self.updatePercentage() self.updatePercentage()
except SSLError as e: 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) return self.streamTrack(stream, track, chunkLength)
except (request_exception.ConnectionError, requests.exceptions.ReadTimeout): except (request_exception.ConnectionError, requests.exceptions.ReadTimeout):
eventlet.sleep(2) eventlet.sleep(2)

View File

@ -9,6 +9,7 @@ class QueueItem:
self.type = queueItemDict['type'] self.type = queueItemDict['type']
self.id = queueItemDict['id'] self.id = queueItemDict['id']
self.bitrate = queueItemDict['bitrate'] self.bitrate = queueItemDict['bitrate']
self.extrasPath = queueItemDict.get('extrasPath', '')
self.files = queueItemDict['files'] self.files = queueItemDict['files']
self.downloaded = queueItemDict['downloaded'] self.downloaded = queueItemDict['downloaded']
self.failed = queueItemDict['failed'] self.failed = queueItemDict['failed']
@ -24,6 +25,7 @@ class QueueItem:
self.type = type self.type = type
self.id = id self.id = id
self.bitrate = bitrate self.bitrate = bitrate
self.extrasPath = None
self.files = [] self.files = []
self.settings = settings self.settings = settings
self.downloaded = 0 self.downloaded = 0
@ -41,6 +43,7 @@ class QueueItem:
'cover': self.cover, 'cover': self.cover,
'explicit': self.explicit, 'explicit': self.explicit,
'size': self.size, 'size': self.size,
'extrasPath': self.extrasPath,
'files': self.files, 'files': self.files,
'downloaded': self.downloaded, 'downloaded': self.downloaded,
'failed': self.failed, 'failed': self.failed,