Started refactoring queuemanager as a class
This commit is contained in:
parent
8afdfc7042
commit
c611420bd9
|
@ -0,0 +1,104 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
"""
|
||||||
|
queueItem base structure
|
||||||
|
title
|
||||||
|
artist
|
||||||
|
cover
|
||||||
|
size
|
||||||
|
downloaded
|
||||||
|
failed
|
||||||
|
errors
|
||||||
|
progress
|
||||||
|
type
|
||||||
|
id
|
||||||
|
bitrate
|
||||||
|
uuid: type+id+bitrate
|
||||||
|
"""
|
||||||
|
|
||||||
|
class QueueItem:
|
||||||
|
def __init__(self, id=None, bitrate=None, title=None, artist=None, cover=None, size=None, type=None, settings=None, queueItemList=None):
|
||||||
|
if queueItemList:
|
||||||
|
self.title = queueItemList['title']
|
||||||
|
self.artist = queueItemList['artist']
|
||||||
|
self.cover = queueItemList['cover']
|
||||||
|
self.size = queueItemList['size']
|
||||||
|
self.type = queueItemList['type']
|
||||||
|
self.id = queueItemList['id']
|
||||||
|
self.bitrate = queueItemList['bitrate']
|
||||||
|
self.settings = queueItemList['settings']
|
||||||
|
else:
|
||||||
|
self.title = title
|
||||||
|
self.artist = artist
|
||||||
|
self.cover = cover
|
||||||
|
self.size = size
|
||||||
|
self.type = type
|
||||||
|
self.id = id
|
||||||
|
self.bitrate = bitrate
|
||||||
|
self.settings = settings
|
||||||
|
self.downloaded = 0
|
||||||
|
self.failed = 0
|
||||||
|
self.errors = []
|
||||||
|
self.progress = 0
|
||||||
|
self.uuid = f"{self.type}_{self.id}_{self.bitrate}"
|
||||||
|
|
||||||
|
def toDict(self):
|
||||||
|
queueItem = {
|
||||||
|
'title': self.title,
|
||||||
|
'artist': self.artist,
|
||||||
|
'cover': self.cover,
|
||||||
|
'size': self.size,
|
||||||
|
'downloaded': self.downloaded,
|
||||||
|
'failed': self.failed,
|
||||||
|
'errors': self.errors,
|
||||||
|
'progress': self.progress,
|
||||||
|
'type': self.type,
|
||||||
|
'id': self.id,
|
||||||
|
'bitrate': self.bitrate,
|
||||||
|
'uuid': self.uuid
|
||||||
|
}
|
||||||
|
return queueItem
|
||||||
|
|
||||||
|
def getResettedItem(self):
|
||||||
|
item = self.toDict()
|
||||||
|
item['downloaded'] = 0
|
||||||
|
item['failed'] = 0
|
||||||
|
item['progress'] = 0
|
||||||
|
item['errors'] = []
|
||||||
|
return item
|
||||||
|
|
||||||
|
def getSlimmedItem(self):
|
||||||
|
light = self.toDict()
|
||||||
|
propertiesToDelete = ['single', 'collection', '_EXTRA']
|
||||||
|
for property in propertiesToDelete:
|
||||||
|
if property in light:
|
||||||
|
del light[property]
|
||||||
|
return light
|
||||||
|
|
||||||
|
class QISingle(QueueItem):
|
||||||
|
def __init__(self, id=None, bitrate=None, title=None, artist=None, cover=None, type=None, settings=None, single=None, queueItemList=None):
|
||||||
|
if queueItemList:
|
||||||
|
super().__init__(queueItemList=queueItemList)
|
||||||
|
self.single = queueItemList['single']
|
||||||
|
else:
|
||||||
|
super().__init__(id, bitrate, title, artist, cover, 1, type, settings)
|
||||||
|
self.single = single
|
||||||
|
|
||||||
|
def toDict(self):
|
||||||
|
queueItem = super().toDict()
|
||||||
|
queueItem['single'] = self.single
|
||||||
|
return queueItem
|
||||||
|
|
||||||
|
class QICollection(QueueItem):
|
||||||
|
def __init__(self, id=None, bitrate=None, title=None, artist=None, cover=None, size=None, type=None, settings=None, collection=None, queueItemList=None):
|
||||||
|
if queueItemList:
|
||||||
|
super().__init__(queueItemList=queueItemList)
|
||||||
|
self.collection = queueItemList['collection']
|
||||||
|
else:
|
||||||
|
super().__init__(id, bitrate, title, artist, cover, size, type, settings)
|
||||||
|
self.collection = collection
|
||||||
|
|
||||||
|
def toDict(self):
|
||||||
|
queueItem = super().toDict()
|
||||||
|
queueItem['collection'] = self.collection
|
||||||
|
return queueItem
|
|
@ -3,73 +3,31 @@ from deemix.app.downloader import download
|
||||||
from deemix.utils.misc import getIDFromLink, getTypeFromLink, getBitrateInt
|
from deemix.utils.misc import getIDFromLink, getTypeFromLink, getBitrateInt
|
||||||
from deemix.api.deezer import APIError
|
from deemix.api.deezer import APIError
|
||||||
from spotipy.exceptions import SpotifyException
|
from spotipy.exceptions import SpotifyException
|
||||||
|
from deemix.app.queueitem import QISingle, QICollection
|
||||||
import logging
|
import logging
|
||||||
import json
|
import json
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
logger = logging.getLogger('deemix')
|
logger = logging.getLogger('deemix')
|
||||||
|
|
||||||
queue = []
|
class QueueManager:
|
||||||
queueList = {}
|
def __init__(self):
|
||||||
queueComplete = []
|
self.queue = []
|
||||||
currentItem = ""
|
self.queueList = {}
|
||||||
|
self.queueComplete = []
|
||||||
|
self.currentItem = ""
|
||||||
|
|
||||||
"""
|
def generateQueueItem(self, dz, sp, url, settings, bitrate=None, albumAPI=None, interface=None):
|
||||||
queueItem base structure
|
|
||||||
title
|
|
||||||
artist
|
|
||||||
cover
|
|
||||||
size
|
|
||||||
downloaded
|
|
||||||
failed
|
|
||||||
errors
|
|
||||||
progress
|
|
||||||
type
|
|
||||||
id
|
|
||||||
bitrate
|
|
||||||
uuid: type+id+bitrate
|
|
||||||
if its a single track
|
|
||||||
single
|
|
||||||
if its an album/playlist
|
|
||||||
collection
|
|
||||||
"""
|
|
||||||
|
|
||||||
def resetQueueItems(items, q):
|
|
||||||
result = {}
|
|
||||||
for item in items.keys():
|
|
||||||
result[item] = items[item].copy()
|
|
||||||
if item in q:
|
|
||||||
result[item]['downloaded'] = 0
|
|
||||||
result[item]['failed'] = 0
|
|
||||||
result[item]['progress'] = 0
|
|
||||||
result[item]['errors'] = []
|
|
||||||
return result
|
|
||||||
|
|
||||||
def slimQueueItems(items):
|
|
||||||
result = {}
|
|
||||||
for item in items.keys():
|
|
||||||
result[item] = slimQueueItem(items[item])
|
|
||||||
return result
|
|
||||||
|
|
||||||
def slimQueueItem(item):
|
|
||||||
light = item.copy()
|
|
||||||
propertiesToDelete = ['single', 'collection', 'unconverted', '_EXTRA']
|
|
||||||
for property in propertiesToDelete:
|
|
||||||
if property in light:
|
|
||||||
del light[property]
|
|
||||||
return light
|
|
||||||
|
|
||||||
def generateQueueItem(dz, sp, url, settings, bitrate=None, albumAPI=None, interface=None):
|
|
||||||
forcedBitrate = getBitrateInt(bitrate)
|
forcedBitrate = getBitrateInt(bitrate)
|
||||||
bitrate = forcedBitrate if forcedBitrate else settings['maxBitrate']
|
bitrate = forcedBitrate if forcedBitrate else settings['maxBitrate']
|
||||||
type = getTypeFromLink(url)
|
type = getTypeFromLink(url)
|
||||||
id = getIDFromLink(url, type)
|
id = getIDFromLink(url, type)
|
||||||
result = {}
|
|
||||||
result['link'] = url
|
|
||||||
if type == None or id == None:
|
if type == None or id == None:
|
||||||
logger.warn("URL not recognized")
|
logger.warn("URL not recognized")
|
||||||
result['error'] = "URL not recognized"
|
return queueError(url, "URL not recognized", "invalidURL")
|
||||||
result['errid'] = "invalidURL"
|
|
||||||
elif type == "track":
|
elif type == "track":
|
||||||
if id.startswith("isrc"):
|
if id.startswith("isrc"):
|
||||||
try:
|
try:
|
||||||
|
@ -77,21 +35,18 @@ def generateQueueItem(dz, sp, url, settings, bitrate=None, albumAPI=None, interf
|
||||||
if 'id' in trackAPI and 'title' in trackAPI:
|
if 'id' in trackAPI and 'title' in trackAPI:
|
||||||
id = trackAPI['id']
|
id = trackAPI['id']
|
||||||
else:
|
else:
|
||||||
result['error'] = "Track ISRC is not available on deezer"
|
|
||||||
result['errid'] = "ISRCnotOnDeezer"
|
|
||||||
return result
|
|
||||||
except APIError as e:
|
except APIError as e:
|
||||||
e = json.loads(str(e))
|
e = json.loads(str(e))
|
||||||
result['error'] = f"Wrong URL: {e['type']+': ' if 'type' in e else ''}{e['message'] if 'message' in e else ''}"
|
return queueError(url, f"Wrong URL: {e['type']+': ' if 'type' in e else ''}{e['message'] if 'message' in e else ''}")
|
||||||
return result
|
|
||||||
try:
|
try:
|
||||||
trackAPI = dz.get_track_gw(id)
|
trackAPI = dz.get_track_gw(id)
|
||||||
except APIError as e:
|
except APIError as e:
|
||||||
e = json.loads(str(e))
|
e = json.loads(str(e))
|
||||||
result['error'] = "Wrong URL"
|
message = "Wrong URL"
|
||||||
if "DATA_ERROR" in e:
|
if "DATA_ERROR" in e:
|
||||||
result['error'] += f": {e['DATA_ERROR']}"
|
message += f": {e['DATA_ERROR']}"
|
||||||
return result
|
return queueError(url, message)
|
||||||
if albumAPI:
|
if albumAPI:
|
||||||
trackAPI['_EXTRA_ALBUM'] = albumAPI
|
trackAPI['_EXTRA_ALBUM'] = albumAPI
|
||||||
if settings['createSingleFolder']:
|
if settings['createSingleFolder']:
|
||||||
|
@ -100,31 +55,26 @@ def generateQueueItem(dz, sp, url, settings, bitrate=None, albumAPI=None, interf
|
||||||
trackAPI['FILENAME_TEMPLATE'] = settings['tracknameTemplate']
|
trackAPI['FILENAME_TEMPLATE'] = settings['tracknameTemplate']
|
||||||
trackAPI['SINGLE_TRACK'] = True
|
trackAPI['SINGLE_TRACK'] = True
|
||||||
|
|
||||||
result['title'] = trackAPI['SNG_TITLE']
|
title = trackAPI['SNG_TITLE']
|
||||||
if 'VERSION' in trackAPI and trackAPI['VERSION']:
|
if 'VERSION' in trackAPI and trackAPI['VERSION']:
|
||||||
result['title'] += " " + trackAPI['VERSION']
|
title += " " + trackAPI['VERSION']
|
||||||
result['artist'] = trackAPI['ART_NAME']
|
return QISingle(
|
||||||
result[
|
id,
|
||||||
'cover'] = f"https://e-cdns-images.dzcdn.net/images/cover/{trackAPI['ALB_PICTURE']}/75x75-000000-80-0-0.jpg"
|
bitrate,
|
||||||
result['size'] = 1
|
title,
|
||||||
result['downloaded'] = 0
|
trackAPI['ART_NAME'],
|
||||||
result['failed'] = 0
|
f"https://e-cdns-images.dzcdn.net/images/cover/{trackAPI['ALB_PICTURE']}/75x75-000000-80-0-0.jpg",
|
||||||
result['errors'] = []
|
'track',
|
||||||
result['progress'] = 0
|
settings,
|
||||||
result['type'] = 'track'
|
trackAPI,
|
||||||
result['id'] = id
|
)
|
||||||
result['bitrate'] = bitrate
|
|
||||||
result['uuid'] = f"{result['type']}_{id}_{bitrate}"
|
|
||||||
result['settings'] = settings or {}
|
|
||||||
result['single'] = trackAPI
|
|
||||||
|
|
||||||
elif type == "album":
|
elif type == "album":
|
||||||
try:
|
try:
|
||||||
albumAPI = dz.get_album(id)
|
albumAPI = dz.get_album(id)
|
||||||
except APIError as e:
|
except APIError as e:
|
||||||
e = json.loads(str(e))
|
e = json.loads(str(e))
|
||||||
result['error'] = f"Wrong URL: {e['type']+': ' if 'type' in e else ''}{e['message'] if 'message' in e else ''}"
|
return queueError(url, f"Wrong URL: {e['type']+': ' if 'type' in e else ''}{e['message'] if 'message' in e else ''}")
|
||||||
return result
|
|
||||||
if id.startswith('upc'):
|
if id.startswith('upc'):
|
||||||
id = albumAPI['id']
|
id = albumAPI['id']
|
||||||
albumAPI_gw = dz.get_album_gw(id)
|
albumAPI_gw = dz.get_album_gw(id)
|
||||||
|
@ -137,30 +87,32 @@ def generateQueueItem(dz, sp, url, settings, bitrate=None, albumAPI=None, interf
|
||||||
if albumAPI['nb_tracks'] == 255:
|
if albumAPI['nb_tracks'] == 255:
|
||||||
albumAPI['nb_tracks'] = len(tracksArray)
|
albumAPI['nb_tracks'] = len(tracksArray)
|
||||||
|
|
||||||
result['title'] = albumAPI['title']
|
|
||||||
result['artist'] = albumAPI['artist']['name']
|
|
||||||
if albumAPI['cover_small'] != None:
|
if albumAPI['cover_small'] != None:
|
||||||
result['cover'] = albumAPI['cover_small'][:-24] + '/75x75-000000-80-0-0.jpg'
|
cover = albumAPI['cover_small'][:-24] + '/75x75-000000-80-0-0.jpg'
|
||||||
else:
|
else:
|
||||||
result['cover'] = f"https://e-cdns-images.dzcdn.net/images/cover/{albumAPI_gw['ALB_PICTURE']}/75x75-000000-80-0-0.jpg"
|
cover = f"https://e-cdns-images.dzcdn.net/images/cover/{albumAPI_gw['ALB_PICTURE']}/75x75-000000-80-0-0.jpg"
|
||||||
result['size'] = albumAPI['nb_tracks']
|
|
||||||
result['downloaded'] = 0
|
|
||||||
result['failed'] = 0
|
|
||||||
result['errors'] = []
|
|
||||||
result['progress'] = 0
|
|
||||||
result['type'] = 'album'
|
|
||||||
result['id'] = id
|
|
||||||
result['bitrate'] = bitrate
|
|
||||||
result['uuid'] = f"{result['type']}_{id}_{bitrate}"
|
|
||||||
result['settings'] = settings or {}
|
|
||||||
totalSize = len(tracksArray)
|
totalSize = len(tracksArray)
|
||||||
result['collection'] = []
|
collection = []
|
||||||
for pos, trackAPI in enumerate(tracksArray, start=1):
|
for pos, trackAPI in enumerate(tracksArray, start=1):
|
||||||
trackAPI['_EXTRA_ALBUM'] = albumAPI
|
trackAPI['_EXTRA_ALBUM'] = albumAPI
|
||||||
trackAPI['POSITION'] = pos
|
trackAPI['POSITION'] = pos
|
||||||
trackAPI['SIZE'] = totalSize
|
trackAPI['SIZE'] = totalSize
|
||||||
trackAPI['FILENAME_TEMPLATE'] = settings['albumTracknameTemplate']
|
trackAPI['FILENAME_TEMPLATE'] = settings['albumTracknameTemplate']
|
||||||
result['collection'].append(trackAPI)
|
collection.append(trackAPI)
|
||||||
|
|
||||||
|
return return QICollection(
|
||||||
|
id,
|
||||||
|
bitrate,
|
||||||
|
albumAPI['title'],
|
||||||
|
albumAPI['artist']['name'],
|
||||||
|
cover,
|
||||||
|
totalSize,
|
||||||
|
'album',
|
||||||
|
settings,
|
||||||
|
collection,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
elif type == "playlist":
|
elif type == "playlist":
|
||||||
try:
|
try:
|
||||||
|
@ -170,10 +122,10 @@ def generateQueueItem(dz, sp, url, settings, bitrate=None, albumAPI=None, interf
|
||||||
playlistAPI = dz.get_playlist_gw(id)['results']['DATA']
|
playlistAPI = dz.get_playlist_gw(id)['results']['DATA']
|
||||||
except APIError as e:
|
except APIError as e:
|
||||||
e = json.loads(str(e))
|
e = json.loads(str(e))
|
||||||
result['error'] = "Wrong URL"
|
message = "Wrong URL"
|
||||||
if "DATA_ERROR" in e:
|
if "DATA_ERROR" in e:
|
||||||
result['error'] += f": {e['DATA_ERROR']}"
|
message += f": {e['DATA_ERROR']}"
|
||||||
return result
|
return queueError(url, message)
|
||||||
newPlaylist = {
|
newPlaylist = {
|
||||||
'id': playlistAPI['PLAYLIST_ID'],
|
'id': playlistAPI['PLAYLIST_ID'],
|
||||||
'title': playlistAPI['TITLE'],
|
'title': playlistAPI['TITLE'],
|
||||||
|
@ -205,28 +157,13 @@ 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']):
|
||||||
logger.warn("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."
|
return return queueError(url, "You can't download others private playlists.", "notYourPrivatePlaylist")
|
||||||
result['errid'] = "notYourPrivatePlaylist"
|
|
||||||
return result
|
|
||||||
|
|
||||||
playlistTracksAPI = dz.get_playlist_tracks_gw(id)
|
playlistTracksAPI = dz.get_playlist_tracks_gw(id)
|
||||||
playlistAPI['various_artist'] = dz.get_artist(5080)
|
playlistAPI['various_artist'] = dz.get_artist(5080)
|
||||||
|
|
||||||
result['title'] = playlistAPI['title']
|
|
||||||
result['artist'] = playlistAPI['creator']['name']
|
|
||||||
result['cover'] = playlistAPI['picture_small'][:-24] + '/75x75-000000-80-0-0.jpg'
|
|
||||||
result['size'] = playlistAPI['nb_tracks']
|
|
||||||
result['downloaded'] = 0
|
|
||||||
result['failed'] = 0
|
|
||||||
result['errors'] = []
|
|
||||||
result['progress'] = 0
|
|
||||||
result['type'] = 'playlist'
|
|
||||||
result['id'] = id
|
|
||||||
result['bitrate'] = bitrate
|
|
||||||
result['uuid'] = f"{result['type']}_{id}_{bitrate}"
|
|
||||||
result['settings'] = settings or {}
|
|
||||||
totalSize = len(playlistTracksAPI)
|
totalSize = len(playlistTracksAPI)
|
||||||
result['collection'] = []
|
collection = []
|
||||||
for pos, trackAPI in enumerate(playlistTracksAPI, start=1):
|
for pos, trackAPI in enumerate(playlistTracksAPI, start=1):
|
||||||
if 'EXPLICIT_TRACK_CONTENT' in trackAPI and 'EXPLICIT_LYRICS_STATUS' in trackAPI['EXPLICIT_TRACK_CONTENT'] and trackAPI['EXPLICIT_TRACK_CONTENT']['EXPLICIT_LYRICS_STATUS'] in [1,4]:
|
if 'EXPLICIT_TRACK_CONTENT' in trackAPI and 'EXPLICIT_LYRICS_STATUS' in trackAPI['EXPLICIT_TRACK_CONTENT'] and trackAPI['EXPLICIT_TRACK_CONTENT']['EXPLICIT_LYRICS_STATUS'] in [1,4]:
|
||||||
playlistAPI['explicit'] = True
|
playlistAPI['explicit'] = True
|
||||||
|
@ -234,51 +171,70 @@ def generateQueueItem(dz, sp, url, settings, bitrate=None, albumAPI=None, interf
|
||||||
trackAPI['POSITION'] = pos
|
trackAPI['POSITION'] = pos
|
||||||
trackAPI['SIZE'] = totalSize
|
trackAPI['SIZE'] = totalSize
|
||||||
trackAPI['FILENAME_TEMPLATE'] = settings['playlistTracknameTemplate']
|
trackAPI['FILENAME_TEMPLATE'] = settings['playlistTracknameTemplate']
|
||||||
result['collection'].append(trackAPI)
|
collection.append(trackAPI)
|
||||||
if not 'explicit' in playlistAPI:
|
if not 'explicit' in playlistAPI:
|
||||||
playlistAPI['explicit'] = False
|
playlistAPI['explicit'] = False
|
||||||
|
|
||||||
|
return return QICollection(
|
||||||
|
id,
|
||||||
|
bitrate,
|
||||||
|
playlistAPI['title'],
|
||||||
|
playlistAPI['creator']['name'],
|
||||||
|
playlistAPI['picture_small'][:-24] + '/75x75-000000-80-0-0.jpg',
|
||||||
|
totalSize,
|
||||||
|
'playlist',
|
||||||
|
settings,
|
||||||
|
collection,
|
||||||
|
)
|
||||||
|
|
||||||
elif type == "artist":
|
elif type == "artist":
|
||||||
try:
|
try:
|
||||||
artistAPI = dz.get_artist(id)
|
artistAPI = dz.get_artist(id)
|
||||||
except APIError as e:
|
except APIError as e:
|
||||||
e = json.loads(str(e))
|
e = json.loads(str(e))
|
||||||
result['error'] = f"Wrong URL: {e['type']+': ' if 'type' in e else ''}{e['message'] if 'message' in e else ''}"
|
return return queueError(url, f"Wrong URL: {e['type']+': ' if 'type' in e else ''}{e['message'] if 'message' in e else ''}")
|
||||||
return result
|
|
||||||
if interface:
|
if interface:
|
||||||
interface.send("startAddingArtist", {'name': artistAPI['name'], 'id': artistAPI['id']})
|
interface.send("startAddingArtist", {'name': artistAPI['name'], 'id': artistAPI['id']})
|
||||||
|
|
||||||
artistAPITracks = dz.get_artist_albums(id)
|
artistAPITracks = dz.get_artist_albums(id)
|
||||||
albumList = []
|
albumList = []
|
||||||
for album in artistAPITracks['data']:
|
for album in artistAPITracks['data']:
|
||||||
albumList.append(generateQueueItem(dz, sp, album['link'], settings, bitrate))
|
albumList.append(generateQueueItem(dz, sp, album['link'], settings, bitrate))
|
||||||
|
|
||||||
if interface:
|
if interface:
|
||||||
interface.send("finishAddingArtist", {'name': artistAPI['name'], 'id': artistAPI['id']})
|
interface.send("finishAddingArtist", {'name': artistAPI['name'], 'id': artistAPI['id']})
|
||||||
|
|
||||||
return albumList
|
return albumList
|
||||||
|
|
||||||
elif type == "artistdiscography":
|
elif type == "artistdiscography":
|
||||||
try:
|
try:
|
||||||
artistAPI = dz.get_artist(id)
|
artistAPI = dz.get_artist(id)
|
||||||
except APIError as e:
|
except APIError as e:
|
||||||
e = json.loads(str(e))
|
e = json.loads(str(e))
|
||||||
result['error'] = f"Wrong URL: {e['type']+': ' if 'type' in e else ''}{e['message'] if 'message' in e else ''}"
|
return return queueError(url, f"Wrong URL: {e['type']+': ' if 'type' in e else ''}{e['message'] if 'message' in e else ''}")
|
||||||
return result
|
|
||||||
if interface:
|
if interface:
|
||||||
interface.send("startAddingArtist", {'name': artistAPI['name'], 'id': artistAPI['id']})
|
interface.send("startAddingArtist", {'name': artistAPI['name'], 'id': artistAPI['id']})
|
||||||
|
|
||||||
artistDiscographyAPI = dz.get_artist_discography_gw(id, 100)
|
artistDiscographyAPI = dz.get_artist_discography_gw(id, 100)
|
||||||
albumList = []
|
albumList = []
|
||||||
for type in artistDiscographyAPI:
|
for type in artistDiscographyAPI:
|
||||||
if type != 'all':
|
if type != 'all':
|
||||||
for album in artistDiscographyAPI[type]:
|
for album in artistDiscographyAPI[type]:
|
||||||
albumList.append(generateQueueItem(dz, sp, album['link'], settings, bitrate))
|
albumList.append(generateQueueItem(dz, sp, album['link'], settings, bitrate))
|
||||||
|
|
||||||
if interface:
|
if interface:
|
||||||
interface.send("finishAddingArtist", {'name': artistAPI['name'], 'id': artistAPI['id']})
|
interface.send("finishAddingArtist", {'name': artistAPI['name'], 'id': artistAPI['id']})
|
||||||
|
|
||||||
return albumList
|
return albumList
|
||||||
|
|
||||||
elif type == "artisttop":
|
elif type == "artisttop":
|
||||||
try:
|
try:
|
||||||
artistAPI = dz.get_artist(id)
|
artistAPI = dz.get_artist(id)
|
||||||
except APIError as e:
|
except APIError as e:
|
||||||
e = json.loads(str(e))
|
e = json.loads(str(e))
|
||||||
result['error'] = f"Wrong URL: {e['type']+': ' if 'type' in e else ''}{e['message'] if 'message' in e else ''}"
|
return return queueError(url, f"Wrong URL: {e['type']+': ' if 'type' in e else ''}{e['message'] if 'message' in e else ''}")
|
||||||
return result
|
|
||||||
|
|
||||||
playlistAPI = {
|
playlistAPI = {
|
||||||
'id': str(artistAPI['id'])+"_top_track",
|
'id': str(artistAPI['id'])+"_top_track",
|
||||||
|
@ -312,21 +268,8 @@ def generateQueueItem(dz, sp, url, settings, bitrate=None, albumAPI=None, interf
|
||||||
playlistAPI['various_artist'] = dz.get_artist(5080)
|
playlistAPI['various_artist'] = dz.get_artist(5080)
|
||||||
playlistAPI['nb_tracks'] = len(artistTopTracksAPI_gw)
|
playlistAPI['nb_tracks'] = len(artistTopTracksAPI_gw)
|
||||||
|
|
||||||
result['title'] = playlistAPI['title']
|
|
||||||
result['artist'] = playlistAPI['creator']['name']
|
|
||||||
result['cover'] = playlistAPI['picture_small'][:-24] + '/75x75-000000-80-0-0.jpg'
|
|
||||||
result['size'] = playlistAPI['nb_tracks']
|
|
||||||
result['downloaded'] = 0
|
|
||||||
result['failed'] = 0
|
|
||||||
result['errors'] = []
|
|
||||||
result['progress'] = 0
|
|
||||||
result['type'] = 'playlist'
|
|
||||||
result['id'] = id
|
|
||||||
result['bitrate'] = bitrate
|
|
||||||
result['uuid'] = f"{result['type']}_{id}_{bitrate}"
|
|
||||||
result['settings'] = settings or {}
|
|
||||||
totalSize = len(artistTopTracksAPI_gw)
|
totalSize = len(artistTopTracksAPI_gw)
|
||||||
result['collection'] = []
|
collection = []
|
||||||
for pos, trackAPI in enumerate(artistTopTracksAPI_gw, start=1):
|
for pos, trackAPI in enumerate(artistTopTracksAPI_gw, start=1):
|
||||||
if 'EXPLICIT_TRACK_CONTENT' in trackAPI and 'EXPLICIT_LYRICS_STATUS' in trackAPI['EXPLICIT_TRACK_CONTENT'] and trackAPI['EXPLICIT_TRACK_CONTENT']['EXPLICIT_LYRICS_STATUS'] in [1,4]:
|
if 'EXPLICIT_TRACK_CONTENT' in trackAPI and 'EXPLICIT_LYRICS_STATUS' in trackAPI['EXPLICIT_TRACK_CONTENT'] and trackAPI['EXPLICIT_TRACK_CONTENT']['EXPLICIT_LYRICS_STATUS'] in [1,4]:
|
||||||
playlistAPI['explicit'] = True
|
playlistAPI['explicit'] = True
|
||||||
|
@ -334,62 +277,70 @@ def generateQueueItem(dz, sp, url, settings, bitrate=None, albumAPI=None, interf
|
||||||
trackAPI['POSITION'] = pos
|
trackAPI['POSITION'] = pos
|
||||||
trackAPI['SIZE'] = totalSize
|
trackAPI['SIZE'] = totalSize
|
||||||
trackAPI['FILENAME_TEMPLATE'] = settings['playlistTracknameTemplate']
|
trackAPI['FILENAME_TEMPLATE'] = settings['playlistTracknameTemplate']
|
||||||
result['collection'].append(trackAPI)
|
collection.append(trackAPI)
|
||||||
if not 'explicit' in playlistAPI:
|
if not 'explicit' in playlistAPI:
|
||||||
playlistAPI['explicit'] = False
|
playlistAPI['explicit'] = False
|
||||||
|
|
||||||
|
return return QICollection(
|
||||||
|
id,
|
||||||
|
bitrate,
|
||||||
|
playlistAPI['title'],
|
||||||
|
playlistAPI['creator']['name'],
|
||||||
|
playlistAPI['picture_small'][:-24] + '/75x75-000000-80-0-0.jpg',
|
||||||
|
totalSize,
|
||||||
|
'playlist',
|
||||||
|
settings,
|
||||||
|
collection,
|
||||||
|
)
|
||||||
|
|
||||||
elif type == "spotifytrack":
|
elif type == "spotifytrack":
|
||||||
if not sp.spotifyEnabled:
|
if not sp.spotifyEnabled:
|
||||||
logger.warn("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."
|
return queueError(url, "Spotify Features is not setted up correctly.", "spotifyDisabled")
|
||||||
result['errid'] = "spotifyDisabled"
|
|
||||||
return result
|
|
||||||
try:
|
try:
|
||||||
track_id = sp.get_trackid_spotify(dz, id, settings['fallbackSearch'])
|
track_id = sp.get_trackid_spotify(dz, id, settings['fallbackSearch'])
|
||||||
except SpotifyException as e:
|
except SpotifyException as e:
|
||||||
result['error'] = "Wrong URL: "+e.msg[e.msg.find('\n')+2:]
|
return queueError(url, "Wrong URL: "+e.msg[e.msg.find('\n')+2:])
|
||||||
return result
|
|
||||||
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:
|
||||||
logger.warn("Track not found on deezer!")
|
logger.warn("Track not found on deezer!")
|
||||||
result['error'] = "Track not found on deezer!"
|
return queueError(url, "Track not found on deezer!", "trackNotOnDeezer")
|
||||||
result['errid'] = "trackNotOnDeezer"
|
|
||||||
elif type == "spotifyalbum":
|
elif type == "spotifyalbum":
|
||||||
if not sp.spotifyEnabled:
|
if not sp.spotifyEnabled:
|
||||||
logger.warn("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."
|
return queueError(url, "Spotify Features is not setted up correctly.", "spotifyDisabled")
|
||||||
result['errid'] = "spotifyDisabled"
|
|
||||||
return result
|
|
||||||
try:
|
try:
|
||||||
album_id = sp.get_albumid_spotify(dz, id)
|
album_id = sp.get_albumid_spotify(dz, id)
|
||||||
except SpotifyException as e:
|
except SpotifyException as e:
|
||||||
result['error'] = "Wrong URL: "+e.msg[e.msg.find('\n')+2:]
|
return queueError(url, "Wrong URL: "+e.msg[e.msg.find('\n')+2:])
|
||||||
return result
|
|
||||||
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:
|
||||||
logger.warn("Album not found on deezer!")
|
logger.warn("Album not found on deezer!")
|
||||||
result['error'] = "Album not found on deezer!"
|
return queueError(url, "Album not found on deezer!", "albumNotOnDeezer")
|
||||||
result['errid'] = "albumNotOnDeezer"
|
|
||||||
elif type == "spotifyplaylist":
|
elif type == "spotifyplaylist":
|
||||||
if not sp.spotifyEnabled:
|
if not sp.spotifyEnabled:
|
||||||
logger.warn("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."
|
return queueError(url, "Spotify Features is not setted up correctly.", "spotifyDisabled")
|
||||||
result['errid'] = "spotifyDisabled"
|
|
||||||
return result
|
|
||||||
try:
|
try:
|
||||||
playlist = sp.adapt_spotify_playlist(dz, id, settings)
|
playlist = sp.adapt_spotify_playlist(dz, id, settings)
|
||||||
except SpotifyException as e:
|
|
||||||
result['error'] = "Wrong URL: "+e.msg[e.msg.find('\n')+2:]
|
|
||||||
return result
|
|
||||||
playlist['bitrate'] = bitrate
|
playlist['bitrate'] = bitrate
|
||||||
playlist['uuid'] = f"{playlist['type']}_{id}_{bitrate}"
|
playlist['uuid'] = f"{playlist['type']}_{id}_{bitrate}"
|
||||||
result = playlist
|
return playlist
|
||||||
|
except SpotifyException as e:
|
||||||
|
return queueError(url, "Wrong URL: "+e.msg[e.msg.find('\n')+2:])
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logger.warn("URL not supported yet")
|
logger.warn("URL not supported yet")
|
||||||
result['error'] = "URL not supported yet"
|
return queueError(url, "URL not supported yet", "unsupportedURL")
|
||||||
result['errid'] = "unsupportedURL"
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
def addToQueue(dz, sp, url, settings, bitrate=None, interface=None):
|
def addToQueue(dz, sp, url, settings, bitrate=None, interface=None):
|
||||||
|
@ -527,3 +478,14 @@ def removeFinishedDownloads(interface=None):
|
||||||
queueComplete = []
|
queueComplete = []
|
||||||
if interface:
|
if interface:
|
||||||
interface.send("removedFinishedDownloads")
|
interface.send("removedFinishedDownloads")
|
||||||
|
|
||||||
|
class queueError:
|
||||||
|
def __init__(self, link, message, errid=None):
|
||||||
|
self.link = link
|
||||||
|
self.message = message
|
||||||
|
self.errid = errid
|
||||||
|
|
||||||
|
def toList(self):
|
||||||
|
error = {
|
||||||
|
'link'
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue