Added logging system using python logging library

This commit is contained in:
RemixDev 2020-05-08 18:06:43 +02:00
parent 3925a8d2fb
commit e07695047f
3 changed files with 48 additions and 26 deletions

View File

@ -26,7 +26,6 @@ Wait for it to finish, then run the `start.bat`<br>
## What's left to do? ## What's left to do?
Library: Library:
- Add a log system
- Write the API Documentation - Write the API Documentation
in the WebUI: in the WebUI:

View File

@ -15,6 +15,10 @@ from deemix.api.deezer import APIError, USER_AGENT_HEADER
from deemix.utils.misc import changeCase from deemix.utils.misc import changeCase
from deemix.utils.pathtemplates import generateFilename, generateFilepath, settingsRegexAlbum, settingsRegexArtist from deemix.utils.pathtemplates import generateFilename, generateFilepath, settingsRegexAlbum, settingsRegexArtist
from deemix.utils.taggers import tagID3, tagFLAC from deemix.utils.taggers import tagID3, tagFLAC
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger('deemix')
TEMPDIR = os.path.join(gettempdir(), 'deemix-imgs') TEMPDIR = os.path.join(gettempdir(), 'deemix-imgs')
if not os.path.isdir(TEMPDIR): if not os.path.isdir(TEMPDIR):
@ -80,7 +84,7 @@ def downloadImage(url, path):
sleep(1) sleep(1)
return downloadImage(url, path) return downloadImage(url, path)
except HTTPError: except HTTPError:
print("Couldn't download Image") logger.warn("Couldn't download Image")
remove(path) remove(path)
return None return None
else: else:
@ -199,6 +203,7 @@ def getTrackData(dz, trackAPI_gw, trackAPI=None, albumAPI_gw=None, albumAPI=None
if 'LYRICS_ID' in trackAPI_gw: if 'LYRICS_ID' in trackAPI_gw:
track['lyrics']['id'] = trackAPI_gw['LYRICS_ID'] track['lyrics']['id'] = trackAPI_gw['LYRICS_ID']
if not "LYRICS" in trackAPI_gw and int(track['lyrics']['id']) != 0: if not "LYRICS" in trackAPI_gw and int(track['lyrics']['id']) != 0:
logger.info(f"[{trackAPI_gw['ART_NAME']} - {track['title']}] Getting lyrics")
trackAPI_gw["LYRICS"] = dz.get_lyrics_gw(track['id']) trackAPI_gw["LYRICS"] = dz.get_lyrics_gw(track['id'])
if int(track['lyrics']['id']) != 0: if int(track['lyrics']['id']) != 0:
if "LYRICS_TEXT" in trackAPI_gw["LYRICS"]: if "LYRICS_TEXT" in trackAPI_gw["LYRICS"]:
@ -235,6 +240,7 @@ def getTrackData(dz, trackAPI_gw, trackAPI=None, albumAPI_gw=None, albumAPI=None
try: try:
if not albumAPI: if not albumAPI:
logger.info(f"[{track['mainArtist']['name']} - {track['title']}] Getting album infos")
albumAPI = dz.get_album(track['album']['id']) albumAPI = dz.get_album(track['album']['id'])
track['album']['mainArtist'] = { track['album']['mainArtist'] = {
'id': albumAPI['artist']['id'], 'id': albumAPI['artist']['id'],
@ -269,11 +275,13 @@ def getTrackData(dz, trackAPI_gw, trackAPI=None, albumAPI_gw=None, albumAPI=None
track['album']['genre'].append(genre['name']) track['album']['genre'].append(genre['name'])
except APIError: except APIError:
if not albumAPI_gw: if not albumAPI_gw:
logger.info(f"[{track['mainArtist']['name']} - {track['title']}] Getting more album infos")
albumAPI_gw = dz.get_album_gw(track['album']['id']) albumAPI_gw = dz.get_album_gw(track['album']['id'])
track['album']['mainArtist'] = { track['album']['mainArtist'] = {
'id': albumAPI_gw['ART_ID'], 'id': albumAPI_gw['ART_ID'],
'name': albumAPI_gw['ART_NAME'] 'name': albumAPI_gw['ART_NAME']
} }
logger.info(f"[{track['mainArtist']['name']} - {track['title']}] Getting artist picture fallback")
artistAPI = dz.get_artist(track['album']['mainArtist']['id']) artistAPI = dz.get_artist(track['album']['mainArtist']['id'])
track['album']['artists'] = albumAPI_gw['ART_NAME'] track['album']['artists'] = albumAPI_gw['ART_NAME']
track['album']['mainArtist']['pic'] = artistAPI['picture_small'][ track['album']['mainArtist']['pic'] = artistAPI['picture_small'][
@ -297,6 +305,7 @@ def getTrackData(dz, trackAPI_gw, trackAPI=None, albumAPI_gw=None, albumAPI=None
track['date'] = track['album']['date'] track['date'] = track['album']['date']
if not trackAPI: if not trackAPI:
logger.info(f"[{track['mainArtist']['name']} - {track['title']}] Getting extra track infos")
trackAPI = dz.get_track(track['id']) trackAPI = dz.get_track(track['id'])
track['bpm'] = trackAPI['bpm'] track['bpm'] = trackAPI['bpm']
if not 'replayGain' in track or not track['replayGain']: if not 'replayGain' in track or not track['replayGain']:
@ -316,10 +325,12 @@ def getTrackData(dz, trackAPI_gw, trackAPI=None, albumAPI_gw=None, albumAPI=None
if not 'discTotal' in track['album'] or not track['album']['discTotal']: if not 'discTotal' in track['album'] or not track['album']['discTotal']:
if not albumAPI_gw: if not albumAPI_gw:
logger.info(f"[{track['mainArtist']['name']} - {track['title']}] Getting more album infos")
albumAPI_gw = dz.get_album_gw(track['album']['id']) albumAPI_gw = dz.get_album_gw(track['album']['id'])
track['album']['discTotal'] = albumAPI_gw['NUMBER_DISK'] track['album']['discTotal'] = albumAPI_gw['NUMBER_DISK']
if not 'copyright' in track or not track['copyright']: if not 'copyright' in track or not track['copyright']:
if not albumAPI_gw: if not albumAPI_gw:
logger.info(f"[{track['mainArtist']['name']} - {track['title']}] Getting more album infos")
albumAPI_gw = dz.get_album_gw(track['album']['id']) albumAPI_gw = dz.get_album_gw(track['album']['id'])
track['copyright'] = albumAPI_gw['COPYRIGHT'] track['copyright'] = albumAPI_gw['COPYRIGHT']
@ -399,6 +410,7 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
'error': "Track not available on Deezer!"}) 'error': "Track not available on Deezer!"})
return result return result
# Get the metadata # Get the metadata
logger.info(f"[{trackAPI['ART_NAME']} - {trackAPI['SNG_TITLE']}] Getting the tags")
if extraTrack: if extraTrack:
track = extraTrack track = extraTrack
else: else:
@ -410,17 +422,16 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
if 'cancel' in queueItem: if 'cancel' in queueItem:
result['cancel'] = True result['cancel'] = True
return result return result
print('Downloading: {} - {}'.format(track['mainArtist']['name'], track['title']))
if track['MD5'] == '': if track['MD5'] == '':
if track['fallbackId'] != 0: if track['fallbackId'] != 0:
print("Track not yet encoded, using fallback id") logger.warn(f"[{track['mainArtist']['name']} - {track['title']}] Track not yet encoded, using fallback id")
trackNew = dz.get_track_gw(track['fallbackId']) trackNew = dz.get_track_gw(track['fallbackId'])
if not 'MD5_ORIGIN' in trackNew: if not 'MD5_ORIGIN' in trackNew:
trackNew['MD5_ORIGIN'] = dz.get_track_md5(trackNew['SNG_ID']) trackNew['MD5_ORIGIN'] = dz.get_track_md5(trackNew['SNG_ID'])
track = parseEssentialTrackData(track, trackNew) track = parseEssentialTrackData(track, trackNew)
return downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=track, interface=interface) return downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=track, interface=interface)
elif not 'searched' in track and settings['fallbackSearch']: elif not 'searched' in track and settings['fallbackSearch']:
print("Track not yet encoded, searching for alternative") logger.warn(f"[{track['mainArtist']['name']} - {track['title']}] Track not yet encoded, searching for alternative")
searchedId = dz.get_track_from_metadata(track['mainArtist']['name'], track['title'], searchedId = dz.get_track_from_metadata(track['mainArtist']['name'], track['title'],
track['album']['title']) track['album']['title'])
if searchedId != 0: if searchedId != 0:
@ -432,7 +443,7 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
return downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=track, return downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=track,
interface=interface) interface=interface)
else: else:
print("ERROR: Track not yet encoded and no alternative found!") logger.error(f"[{track['mainArtist']['name']} - {track['title']}] Track not yet encoded and no alternative found!")
result['error'] = { result['error'] = {
'message': "Track not yet encoded and no alternative found!", 'message': "Track not yet encoded and no alternative found!",
'data': track 'data': track
@ -443,7 +454,7 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
'error': "Track not yet encoded and no alternative found!"}) 'error': "Track not yet encoded and no alternative found!"})
return result return result
else: else:
print("ERROR: Track not yet encoded!") logger.error(f"[{track['mainArtist']['name']} - {track['title']}] Track not yet encoded!")
result['error'] = { result['error'] = {
'message': "Track not yet encoded!", 'message': "Track not yet encoded!",
'data': track 'data': track
@ -457,7 +468,7 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
# Get the selected bitrate # Get the selected bitrate
format = getPreferredBitrate(dz, track, bitrate, settings['fallbackBitrate']) format = getPreferredBitrate(dz, track, bitrate, settings['fallbackBitrate'])
if format == -100: if format == -100:
print("ERROR: Track not found at desired bitrate. Enable fallback to lower bitrates to fix this issue.") logger.error(f"[{track['mainArtist']['name']} - {track['title']}] Track not found at desired bitrate. Enable fallback to lower bitrates to fix this issue.")
result['error'] = { result['error'] = {
'message': "Track not found at desired bitrate.", 'message': "Track not found at desired bitrate.",
'data': track 'data': track
@ -468,7 +479,7 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
'error': "Track not found at desired bitrate."}) 'error': "Track not found at desired bitrate."})
return result return result
elif format == -200: elif format == -200:
print("ERROR: This track is not available in 360 Reality Audio format. Please select another format.") logger.error(f"[{track['mainArtist']['name']} - {track['title']}] This track is not available in 360 Reality Audio format. Please select another format.")
result['error'] = { result['error'] = {
'message': "Track is not available in Reality Audio 360.", 'message': "Track is not available in Reality Audio 360.",
'data': track 'data': track
@ -564,6 +575,7 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
else: else:
track['album']['picPath'] = os.path.join(TEMPDIR, track['album']['picPath'] = os.path.join(TEMPDIR,
f"alb{track['album']['id']}_{settings['embeddedArtworkSize']}.{'png' if settings['PNGcovers'] else 'jpg'}") f"alb{track['album']['id']}_{settings['embeddedArtworkSize']}.{'png' if settings['PNGcovers'] else 'jpg'}")
logger.info(f"[{track['mainArtist']['name']} - {track['title']}] Getting the album cover")
track['album']['picPath'] = downloadImage(track['album']['picUrl'], track['album']['picPath']) track['album']['picPath'] = downloadImage(track['album']['picUrl'], track['album']['picPath'])
if os.path.sep in filename: if os.path.sep in filename:
@ -575,7 +587,6 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
# Save lyrics in lrc file # Save lyrics in lrc file
if settings['syncedLyrics'] and 'sync' in track['lyrics']: if settings['syncedLyrics'] and 'sync' in track['lyrics']:
print(filepath, filename)
with open(os.path.join(filepath, filename + '.lrc'), 'wb') as f: with open(os.path.join(filepath, filename + '.lrc'), 'wb') as f:
f.write(track['lyrics']['sync'].encode('utf-8')) f.write(track['lyrics']['sync'].encode('utf-8'))
@ -602,6 +613,7 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
track['downloadUrl'] = dz.get_track_stream_url(track['id'], track['MD5'], track['mediaVersion'], track['downloadUrl'] = dz.get_track_stream_url(track['id'], track['MD5'], track['mediaVersion'],
track['selectedFormat']) track['selectedFormat'])
logger.info(f"[{track['mainArtist']['name']} - {track['title']}] Downloading the track")
try: try:
with open(writepath, 'wb') as stream: with open(writepath, 'wb') as stream:
stream_track(dz, track, stream, trackAPI, queueItem, interface) stream_track(dz, track, stream, trackAPI, queueItem, interface)
@ -612,14 +624,14 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
except HTTPError: except HTTPError:
remove(writepath) remove(writepath)
if track['fallbackId'] != 0: if track['fallbackId'] != 0:
print("Track not available, using fallback id") logger.warn(f"[{track['mainArtist']['name']} - {track['title']}] Track not available, using fallback id")
trackNew = dz.get_track_gw(track['fallbackId']) trackNew = dz.get_track_gw(track['fallbackId'])
if not 'MD5_ORIGIN' in trackNew: if not 'MD5_ORIGIN' in trackNew:
trackNew['MD5_ORIGIN'] = dz.get_track_md5(trackNew['SNG_ID']) trackNew['MD5_ORIGIN'] = dz.get_track_md5(trackNew['SNG_ID'])
track = parseEssentialTrackData(track, trackNew) track = parseEssentialTrackData(track, trackNew)
return downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=track, interface=interface) return downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=track, interface=interface)
elif not 'searched' in track and settings['fallbackSearch']: elif not 'searched' in track and settings['fallbackSearch']:
print("Track not available, searching for alternative") logger.warn(f"[{track['mainArtist']['name']} - {track['title']}] Track not available, searching for alternative")
searchedId = dz.get_track_from_metadata(track['mainArtist']['name'], track['title'], searchedId = dz.get_track_from_metadata(track['mainArtist']['name'], track['title'],
track['album']['title']) track['album']['title'])
if searchedId != 0: if searchedId != 0:
@ -631,7 +643,7 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
return downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=track, return downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=track,
interface=interface) interface=interface)
else: else:
print("ERROR: Track not available on deezer's servers and no alternative found!") logger.error(f"[{track['mainArtist']['name']} - {track['title']}] Track not available on deezer's servers and no alternative found!")
result['error'] = { result['error'] = {
'message': "Track not available on deezer's servers and no alternative found!", 'message': "Track not available on deezer's servers and no alternative found!",
'data': track 'data': track
@ -642,7 +654,7 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
'error': "Track not available on deezer's servers and no alternative found!"}) 'error': "Track not available on deezer's servers and no alternative found!"})
return result return result
else: else:
print("ERROR: Track not available on deezer's servers!") logger.error(f"[{track['mainArtist']['name']} - {track['title']}] Track not available on deezer's servers!")
result['error'] = { result['error'] = {
'message': "Track not available on deezer's servers!", 'message': "Track not available on deezer's servers!",
'data': track 'data': track
@ -652,13 +664,14 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': track, interface.send("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': track,
'error': "Track not available on deezer's servers!"}) 'error': "Track not available on deezer's servers!"})
return result return result
logger.info(f"[{track['mainArtist']['name']} - {track['title']}] Applying tags to the track")
if track['selectedFormat'] in [3, 1, 8]: if track['selectedFormat'] in [3, 1, 8]:
tagID3(writepath, track, settings['tags']) tagID3(writepath, track, settings['tags'])
elif track['selectedFormat'] == 9: elif track['selectedFormat'] == 9:
tagFLAC(writepath, track, settings['tags']) tagFLAC(writepath, track, settings['tags'])
if 'searched' in track: if 'searched' in track:
result['searched'] = f'{track["mainArtist"]["name"]} - {track["title"]}' result['searched'] = f'{track["mainArtist"]["name"]} - {track["title"]}'
print("Done!") logger.info(f"[{track['mainArtist']['name']} - {track['title']}] Track download completed")
if interface: if interface:
queueItem['downloaded'] += 1 queueItem['downloaded'] += 1
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'downloaded': True}) interface.send("updateQueue", {'uuid': queueItem['uuid'], 'downloaded': True})
@ -713,7 +726,6 @@ def download(dz, queueItem, interface=None):
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'failed': True}) interface.send("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")
playlist = [None] * len(queueItem['collection']) playlist = [None] * len(queueItem['collection'])
with ThreadPoolExecutor(settings['queueConcurrency']) as executor: with ThreadPoolExecutor(settings['queueConcurrency']) as executor:
for pos, track in enumerate(queueItem['collection'], start=0): for pos, track in enumerate(queueItem['collection'], start=0):

View File

@ -1,6 +1,10 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from deemix.app.downloader import download from deemix.app.downloader import download
from deemix.utils.misc import getIDFromLink, getTypeFromLink, getBitrateInt from deemix.utils.misc import getIDFromLink, getTypeFromLink, getBitrateInt
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger('deemix')
queue = [] queue = []
queueList = {} queueList = {}
@ -41,7 +45,7 @@ def generateQueueItem(dz, sp, url, settings, bitrate=None, albumAPI=None, interf
id = getIDFromLink(url, type) id = getIDFromLink(url, type)
result = {} result = {}
if type == None or id == None: if type == None or id == None:
print("URL not recognized") logger.warn("URL not recognized")
result['error'] = "URL not recognized" result['error'] = "URL not recognized"
elif type == "track": elif type == "track":
trackAPI = dz.get_track_gw(id) trackAPI = dz.get_track_gw(id)
@ -136,7 +140,7 @@ def generateQueueItem(dz, sp, url, settings, bitrate=None, albumAPI=None, interf
} }
playlistAPI = newPlaylist playlistAPI = newPlaylist
if not playlistAPI['public'] and playlistAPI['creator']['id'] != str(dz.user['id']): if not playlistAPI['public'] and playlistAPI['creator']['id'] != str(dz.user['id']):
print("You can't download others private playlists.") logger.warn("You can't download others private playlists.")
result['error'] = "You can't download others private playlists." result['error'] = "You can't download others private playlists."
return result return result
@ -182,31 +186,31 @@ def generateQueueItem(dz, sp, url, settings, bitrate=None, albumAPI=None, interf
elif type == "spotifytrack": elif type == "spotifytrack":
result = {} result = {}
if not sp.spotifyEnabled: if not sp.spotifyEnabled:
print("Spotify Features is not setted up correctly.") logger.warn("Spotify Features is not setted up correctly.")
result['error'] = "Spotify Features is not setted up correctly." result['error'] = "Spotify Features is not setted up correctly."
return result return result
track_id = sp.get_trackid_spotify(dz, id, settings['fallbackSearch']) track_id = sp.get_trackid_spotify(dz, id, settings['fallbackSearch'])
if track_id != 0: if track_id != 0:
return generateQueueItem(dz, sp, f'https://www.deezer.com/track/{track_id}', settings, bitrate) return generateQueueItem(dz, sp, f'https://www.deezer.com/track/{track_id}', settings, bitrate)
else: else:
print("Track not found on deezer!") logger.warn("Track not found on deezer!")
result['error'] = "Track not found on deezer!" result['error'] = "Track not found on deezer!"
elif type == "spotifyalbum": elif type == "spotifyalbum":
result = {} result = {}
if not sp.spotifyEnabled: if not sp.spotifyEnabled:
print("Spotify Features is not setted up correctly.") logger.warn("Spotify Features is not setted up correctly.")
result['error'] = "Spotify Features is not setted up correctly." result['error'] = "Spotify Features is not setted up correctly."
return result return result
album_id = sp.get_albumid_spotify(dz, id) album_id = sp.get_albumid_spotify(dz, id)
if album_id != 0: if album_id != 0:
return generateQueueItem(dz, sp, f'https://www.deezer.com/album/{album_id}', settings, bitrate) return generateQueueItem(dz, sp, f'https://www.deezer.com/album/{album_id}', settings, bitrate)
else: else:
print("Album not found on deezer!") logger.warn("Album not found on deezer!")
result['error'] = "Album not found on deezer!" result['error'] = "Album not found on deezer!"
elif type == "spotifyplaylist": elif type == "spotifyplaylist":
result = {} result = {}
if not sp.spotifyEnabled: if not sp.spotifyEnabled:
print("Spotify Features is not setted up correctly.") logger.warn("Spotify Features is not setted up correctly.")
result['error'] = "Spotify Features is not setted up correctly." result['error'] = "Spotify Features is not setted up correctly."
return result return result
if interface: if interface:
@ -221,7 +225,7 @@ def generateQueueItem(dz, sp, url, settings, bitrate=None, albumAPI=None, interf
interface.send("toast", {'msg': f"Spotify playlist converted", 'icon': 'done', 'dismiss': True, interface.send("toast", {'msg': f"Spotify playlist converted", 'icon': 'done', 'dismiss': True,
'id': 'spotifyplaylist_' + str(id)}) 'id': 'spotifyplaylist_' + str(id)})
else: else:
print("URL not supported yet") logger.warn("URL not supported yet")
result['error'] = "URL not supported yet" result['error'] = "URL not supported yet"
return result return result
@ -230,25 +234,29 @@ def addToQueue(dz, sp, url, settings, bitrate=None, interface=None):
global currentItem, queueList, queue global currentItem, queueList, queue
if not dz.logged_in: if not dz.logged_in:
return "Not logged in" return "Not logged in"
logger.info("Generating queue item for: "+url)
queueItem = generateQueueItem(dz, sp, url, settings, bitrate, interface=interface) queueItem = generateQueueItem(dz, sp, url, settings, bitrate, interface=interface)
if type(queueItem) is list: if type(queueItem) is list:
for x in queueItem: for x in queueItem:
if 'error' in x: if 'error' in x:
logger.error(f"[{x['uuid']}] {x['error']}")
continue continue
if x['uuid'] in list(queueList.keys()): if x['uuid'] in list(queueList.keys()):
print("Already in queue!") logger.warn(f"[{x['uuid']}] Already in queue, will not be added again.")
continue continue
if interface: if interface:
interface.send("addedToQueue", slimQueueItem(x)) interface.send("addedToQueue", slimQueueItem(x))
logger.info(f"[{x['uuid']}] Added to queue.")
queue.append(x['uuid']) queue.append(x['uuid'])
queueList[x['uuid']] = x queueList[x['uuid']] = x
else: else:
if 'error' in queueItem: if 'error' in queueItem:
logger.error(f"[{queueItem['uuid']}] {queueItem['error']}")
if interface: if interface:
interface.send("toast", {'msg': queueItem['error'], 'icon': 'error'}) interface.send("toast", {'msg': queueItem['error'], 'icon': 'error'})
return False return False
if queueItem['uuid'] in list(queueList.keys()): if queueItem['uuid'] in list(queueList.keys()):
print("Already in queue!") logger.warn(f"[{queueItem['uuid']}] Already in queue, will not be added again.")
if interface: if interface:
interface.send("toast", interface.send("toast",
{'msg': f"{queueItem['title']} is already in queue!", 'icon': 'playlist_add_check'}) {'msg': f"{queueItem['title']} is already in queue!", 'icon': 'playlist_add_check'})
@ -256,6 +264,7 @@ def addToQueue(dz, sp, url, settings, bitrate=None, interface=None):
if interface: if interface:
interface.send("addedToQueue", slimQueueItem(queueItem)) interface.send("addedToQueue", slimQueueItem(queueItem))
interface.send("toast", {'msg': f"{queueItem['title']} added to queue", 'icon': 'playlist_add'}) interface.send("toast", {'msg': f"{queueItem['title']} added to queue", 'icon': 'playlist_add'})
logger.info(f"[{queueItem['uuid']}] Added to queue.")
queue.append(queueItem['uuid']) queue.append(queueItem['uuid'])
queueList[queueItem['uuid']] = queueItem queueList[queueItem['uuid']] = queueItem
nextItem(dz, interface) nextItem(dz, interface)
@ -273,6 +282,7 @@ def nextItem(dz, interface=None):
return None return None
if interface: if interface:
interface.send("startDownload", currentItem) interface.send("startDownload", currentItem)
logger.info(f"[{currentItem}] Started downloading.")
result = download(dz, queueList[currentItem], interface) result = download(dz, queueList[currentItem], interface)
callbackQueueDone(result) callbackQueueDone(result)
@ -283,6 +293,7 @@ def callbackQueueDone(result):
del queueList[currentItem] del queueList[currentItem]
else: else:
queueComplete.append(currentItem) queueComplete.append(currentItem)
logger.info(f"[{currentItem}] Finished downloading.")
currentItem = "" currentItem = ""
nextItem(result['dz'], result['interface']) nextItem(result['dz'], result['interface'])