Implemented formatListener

This commit is contained in:
RemixDev 2021-08-02 23:45:08 +02:00
parent 1859f07842
commit 3030140e15
No known key found for this signature in database
GPG Key ID: B33962B465BDB51C
3 changed files with 64 additions and 17 deletions

View File

@ -7,7 +7,7 @@ from deezer import TrackFormats
from deemix import generateDownloadObject from deemix import generateDownloadObject
from deemix.settings import load as loadSettings from deemix.settings import load as loadSettings
from deemix.utils import getBitrateNumberFromText from deemix.utils import getBitrateNumberFromText, formatListener
import deemix.utils.localpaths as localpaths import deemix.utils.localpaths as localpaths
from deemix.downloader import Downloader from deemix.downloader import Downloader
from deemix.itemgen import GenerationError from deemix.itemgen import GenerationError
@ -15,11 +15,9 @@ from deemix.plugins.spotify import Spotify
class LogListener: class LogListener:
@classmethod @classmethod
def send(cls, key, value): def send(cls, key, value=None):
if value: logString = formatListener(key, value)
print(key, value) if logString: print(logString)
else:
print(key)
@click.command() @click.command()

View File

@ -172,9 +172,9 @@ def getPreferredBitrate(dz, track, preferredBitrate, shouldFallback, uuid=None,
falledBack = True falledBack = True
logger.info("%s Fallback to lower bitrate", f"[{track.mainArtist.name} - {track.title}]") logger.info("%s Fallback to lower bitrate", f"[{track.mainArtist.name} - {track.title}]")
if listener and uuid: if listener and uuid:
listener.send('queueUpdate', { listener.send('downloadInfo', {
'uuid': uuid, 'uuid': uuid,
'bitrateFallback': True, 'state': 'bitrateFallback',
'data': { 'data': {
'id': track.id, 'id': track.id,
'title': track.title, 'title': track.title,
@ -472,15 +472,7 @@ class Downloader:
track.parseEssentialData(newTrack) track.parseEssentialData(newTrack)
track.retriveFilesizes(self.dz) track.retriveFilesizes(self.dz)
track.searched = True track.searched = True
if self.listener: self.listener.send('queueUpdate', { self.log(itemData, "searchFallback")
'uuid': self.downloadObject.uuid,
'searchFallback': True,
'data': {
'id': track.id,
'title': track.title,
'artist': track.mainArtist.name
},
})
return self.downloadWrapper(extraData, track) return self.downloadWrapper(extraData, track)
error.errid += "NoAlternative" error.errid += "NoAlternative"
error.message = ErrorMessages[error.errid] error.message = ErrorMessages[error.errid]

View File

@ -1,6 +1,7 @@
import string import string
from deezer import TrackFormats from deezer import TrackFormats
import os import os
from deemix.errors import ErrorMessages
USER_AGENT_HEADER = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) " \ USER_AGENT_HEADER = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) " \
"Chrome/79.0.3945.130 Safari/537.36" "Chrome/79.0.3945.130 Safari/537.36"
@ -73,3 +74,59 @@ def removeDuplicateArtists(artist, artists):
for role in artist.keys(): for role in artist.keys():
artist[role] = uniqueArray(artist[role]) artist[role] = uniqueArray(artist[role])
return (artist, artists) return (artist, artists)
def formatListener(key, data=None):
if key == "startAddingArtist":
return f"Started gathering {data.name}'s albums ({data.id})"
if key == "finishAddingArtist":
return f"Finished gathering {data.name}'s albums ({data.id})"
if key == "updateQueue":
uuid = f"[{data['uuid']}]"
if data.get('downloaded'):
shortFilepath = data['downloadPath'][len(data['extrasPath']):]
return f"{uuid} Completed download of {shortFilepath}"
if data.get('failed'):
return f"{uuid} {data['data']['artist']} - {data['data']['title']} :: {data['error']}"
if data.get('progress'):
return f"{uuid} Download at {data['progress']}%"
if data.get('conversion'):
return f"{uuid} Conversion at {data['conversion']}%"
return uuid
if key == "downloadInfo":
message = data['state']
if data['state'] == "getTags": message = "Getting tags."
elif data['state'] == "gotTags": message = "Tags got."
elif data['state'] == "getBitrate": message = "Getting download URL."
elif data['state'] == "bitrateFallback": message = "Desired bitrate not found, falling back to lower bitrate."
elif data['state'] == "searchFallback": message = "This track has been searched for, result might not be 100% exact."
elif data['state'] == "gotBitrate": message = "Download URL got."
elif data['state'] == "getAlbumArt": message = "Downloading album art."
elif data['state'] == "gotAlbumArt": message = "Album art downloaded."
elif data['state'] == "downloading":
message = "Downloading track."
if data['alreadyStarted']:
message += f" Recovering download from {data['value']}."
else:
message += f" Downloading {data['value']} bytes."
elif data['state'] == "downloaded": message = "Track downloaded."
elif data['state'] == "alreadyDownloaded": message = "Track already downloaded."
elif data['state'] == "tagging": message = "Tagging track."
elif data['state'] == "tagged": message = "Track tagged."
return f"[{data['uuid']}] {data['data']['artist']} - {data['data']['title']} :: {message}"
if key == "downloadWarn":
errorMessage = ErrorMessages[data['state']]
solutionMessage = ""
if data['solution'] == 'fallback': solutionMessage = "Using fallback id."
if data['solution'] == 'search': solutionMessage = "Searching for alternative."
return f"[{data['uuid']}] {data['data']['artist']} - {data['data']['title']} :: {errorMessage} {solutionMessage}"
if key == "currentItemCancelled":
return f"Cancelled download of {data}"
if key == "removedFromQueue":
return f"Removed {data} from the queue"
if key == "finishDownload":
return f"{data} finished downloading"
if key == "startConversion":
return f"Started converting {data}"
if key == "finishConversion":
return f"Finished converting {data}"
return ""