mirror of
https://gitlab.com/RemixDev/deemix-py.git
synced 2024-12-29 11:06:14 +00:00
Implemented formatListener
This commit is contained in:
parent
1859f07842
commit
3030140e15
|
@ -7,7 +7,7 @@ from deezer import TrackFormats
|
|||
|
||||
from deemix import generateDownloadObject
|
||||
from deemix.settings import load as loadSettings
|
||||
from deemix.utils import getBitrateNumberFromText
|
||||
from deemix.utils import getBitrateNumberFromText, formatListener
|
||||
import deemix.utils.localpaths as localpaths
|
||||
from deemix.downloader import Downloader
|
||||
from deemix.itemgen import GenerationError
|
||||
|
@ -15,11 +15,9 @@ from deemix.plugins.spotify import Spotify
|
|||
|
||||
class LogListener:
|
||||
@classmethod
|
||||
def send(cls, key, value):
|
||||
if value:
|
||||
print(key, value)
|
||||
else:
|
||||
print(key)
|
||||
def send(cls, key, value=None):
|
||||
logString = formatListener(key, value)
|
||||
if logString: print(logString)
|
||||
|
||||
|
||||
@click.command()
|
||||
|
|
|
@ -172,9 +172,9 @@ def getPreferredBitrate(dz, track, preferredBitrate, shouldFallback, uuid=None,
|
|||
falledBack = True
|
||||
logger.info("%s Fallback to lower bitrate", f"[{track.mainArtist.name} - {track.title}]")
|
||||
if listener and uuid:
|
||||
listener.send('queueUpdate', {
|
||||
listener.send('downloadInfo', {
|
||||
'uuid': uuid,
|
||||
'bitrateFallback': True,
|
||||
'state': 'bitrateFallback',
|
||||
'data': {
|
||||
'id': track.id,
|
||||
'title': track.title,
|
||||
|
@ -472,15 +472,7 @@ class Downloader:
|
|||
track.parseEssentialData(newTrack)
|
||||
track.retriveFilesizes(self.dz)
|
||||
track.searched = True
|
||||
if self.listener: self.listener.send('queueUpdate', {
|
||||
'uuid': self.downloadObject.uuid,
|
||||
'searchFallback': True,
|
||||
'data': {
|
||||
'id': track.id,
|
||||
'title': track.title,
|
||||
'artist': track.mainArtist.name
|
||||
},
|
||||
})
|
||||
self.log(itemData, "searchFallback")
|
||||
return self.downloadWrapper(extraData, track)
|
||||
error.errid += "NoAlternative"
|
||||
error.message = ErrorMessages[error.errid]
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import string
|
||||
from deezer import TrackFormats
|
||||
import os
|
||||
from deemix.errors import ErrorMessages
|
||||
|
||||
USER_AGENT_HEADER = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) " \
|
||||
"Chrome/79.0.3945.130 Safari/537.36"
|
||||
|
@ -73,3 +74,59 @@ def removeDuplicateArtists(artist, artists):
|
|||
for role in artist.keys():
|
||||
artist[role] = uniqueArray(artist[role])
|
||||
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 ""
|
||||
|
|
Loading…
Reference in a new issue