Moved spotify conversion outside creating queue item
This commit is contained in:
parent
3f8d4d5ae9
commit
a991ad04ec
|
@ -947,12 +947,14 @@ def downloadTrackObj_wrap(dz, track, settings, bitrate, queueItem, interface):
|
|||
return result
|
||||
|
||||
|
||||
def download(dz, queueItem, interface=None):
|
||||
def download(dz, sp, queueItem, interface=None):
|
||||
global downloadPercentage, lastPercentage
|
||||
settings = queueItem['settings']
|
||||
bitrate = queueItem['bitrate']
|
||||
downloadPercentage = 0
|
||||
lastPercentage = 0
|
||||
if '_EXTRA' in queueItem:
|
||||
sp.convert_spotify_playlist(dz, queueItem, settings, interface=interface)
|
||||
if 'single' in queueItem:
|
||||
try:
|
||||
result = downloadTrackObj(dz, queueItem['single'], settings, bitrate, queueItem, interface=interface)
|
||||
|
@ -988,6 +990,7 @@ def download(dz, queueItem, interface=None):
|
|||
interface.send("finishDownload", queueItem['uuid'])
|
||||
return {
|
||||
'dz': dz,
|
||||
'sp': sp,
|
||||
'interface': interface,
|
||||
'download_path': download_path
|
||||
}
|
||||
|
|
|
@ -53,10 +53,10 @@ def slimQueueItems(items):
|
|||
|
||||
def slimQueueItem(item):
|
||||
light = item.copy()
|
||||
if 'single' in light:
|
||||
del light['single']
|
||||
if 'collection' in light:
|
||||
del light['collection']
|
||||
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):
|
||||
|
@ -377,18 +377,14 @@ def generateQueueItem(dz, sp, url, settings, bitrate=None, albumAPI=None, interf
|
|||
result['error'] = "Spotify Features is not setted up correctly."
|
||||
result['errid'] = "spotifyDisabled"
|
||||
return result
|
||||
if interface:
|
||||
interface.send("startConvertingSpotifyPlaylist", str(id))
|
||||
try:
|
||||
playlist = sp.convert_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['uuid'] = f"{playlist['type']}_{id}_{bitrate}"
|
||||
result = playlist
|
||||
if interface:
|
||||
interface.send("finishConvertingSpotifyPlaylist", str(id))
|
||||
else:
|
||||
logger.warn("URL not supported yet")
|
||||
result['error'] = "URL not supported yet"
|
||||
|
@ -447,11 +443,11 @@ def addToQueue(dz, sp, url, settings, bitrate=None, interface=None):
|
|||
logger.info(f"[{queueItem['uuid']}] Added to queue.")
|
||||
queue.append(queueItem['uuid'])
|
||||
queueList[queueItem['uuid']] = queueItem
|
||||
nextItem(dz, interface)
|
||||
nextItem(dz, sp, interface)
|
||||
return True
|
||||
|
||||
|
||||
def nextItem(dz, interface=None):
|
||||
def nextItem(dz, sp, interface=None):
|
||||
global currentItem, queueList, queue
|
||||
if currentItem != "":
|
||||
return None
|
||||
|
@ -463,7 +459,7 @@ def nextItem(dz, interface=None):
|
|||
if interface:
|
||||
interface.send("startDownload", currentItem)
|
||||
logger.info(f"[{currentItem}] Started downloading.")
|
||||
result = download(dz, queueList[currentItem], interface)
|
||||
result = download(dz, sp, queueList[currentItem], interface)
|
||||
callbackQueueDone(result)
|
||||
|
||||
|
||||
|
@ -475,7 +471,7 @@ def callbackQueueDone(result):
|
|||
queueComplete.append(currentItem)
|
||||
logger.info(f"[{currentItem}] Finished downloading.")
|
||||
currentItem = ""
|
||||
nextItem(result['dz'], result['interface'])
|
||||
nextItem(result['dz'], result['sp'], result['interface'])
|
||||
|
||||
|
||||
def getQueue():
|
||||
|
|
|
@ -174,7 +174,7 @@ class SpotifyHelper:
|
|||
json.dump(cache, spotifyCache)
|
||||
return dz_album
|
||||
|
||||
def convert_spotify_playlist(self, dz, playlist_id, settings):
|
||||
def adapt_spotify_playlist(self, dz, playlist_id, settings):
|
||||
if not self.spotifyEnabled:
|
||||
raise spotifyFeaturesNotEnabled
|
||||
spotify_playlist = self.sp.playlist(playlist_id)
|
||||
|
@ -199,21 +199,34 @@ class SpotifyHelper:
|
|||
playlistAPI['various_artist'] = dz.get_artist(5080)
|
||||
tracklistTmp = spotify_playlist['tracks']['items']
|
||||
result['collection'] = []
|
||||
tracklist = []
|
||||
result['_EXTRA'] = {}
|
||||
result['_EXTRA']['unconverted'] = []
|
||||
while spotify_playlist['tracks']['next']:
|
||||
spotify_playlist['tracks'] = self.sp.next(spotify_playlist['tracks'])
|
||||
tracklistTmp += spotify_playlist['tracks']['items']
|
||||
for item in tracklistTmp:
|
||||
if item['track']:
|
||||
tracklist.append(item['track'])
|
||||
totalSize = len(tracklist)
|
||||
if item['track']['explicit']:
|
||||
playlistAPI['explicit'] = True
|
||||
result['_EXTRA']['unconverted'].append(item['track'])
|
||||
totalSize = len(result['_EXTRA']['unconverted'])
|
||||
result['size'] = totalSize
|
||||
if not 'explicit' in playlistAPI:
|
||||
playlistAPI['explicit'] = False
|
||||
result['_EXTRA']['playlistAPI'] = playlistAPI
|
||||
return result
|
||||
|
||||
def convert_spotify_playlist(self, dz, item, settings, interface=None):
|
||||
convertPercentage = 0
|
||||
lastPercentage = 0
|
||||
if path.isfile(path.join(self.configFolder, 'spotifyCache.json')):
|
||||
with open(path.join(self.configFolder, 'spotifyCache.json'), 'r') as spotifyCache:
|
||||
cache = json.load(spotifyCache)
|
||||
else:
|
||||
cache = {'tracks': {}, 'albums': {}}
|
||||
for pos, track in enumerate(tracklist, start=1):
|
||||
if interface:
|
||||
interface.send("startConversion", item['uuid'])
|
||||
for pos, track in enumerate(item['_EXTRA']['unconverted'], start=1):
|
||||
if str(track['id']) in cache['tracks']:
|
||||
trackID = cache['tracks'][str(track['id'])]
|
||||
else:
|
||||
|
@ -234,18 +247,24 @@ class SpotifyHelper:
|
|||
}
|
||||
else:
|
||||
deezerTrack = dz.get_track_gw(trackID)
|
||||
if 'EXPLICIT_LYRICS' in deezerTrack and deezerTrack['EXPLICIT_LYRICS'] == "1":
|
||||
playlistAPI['explicit'] = True
|
||||
deezerTrack['_EXTRA_PLAYLIST'] = playlistAPI
|
||||
deezerTrack['_EXTRA_PLAYLIST'] = item['_EXTRA']['playlistAPI']
|
||||
deezerTrack['POSITION'] = pos
|
||||
deezerTrack['SIZE'] = totalSize
|
||||
deezerTrack['SIZE'] = item['size']
|
||||
deezerTrack['FILENAME_TEMPLATE'] = settings['playlistTracknameTemplate']
|
||||
result['collection'].append(deezerTrack)
|
||||
if not 'explicit' in playlistAPI:
|
||||
playlistAPI['explicit'] = False
|
||||
item['collection'].append(deezerTrack)
|
||||
|
||||
convertPercentage = (pos / item['size']) * 100
|
||||
print(convertPercentage)
|
||||
if round(convertPercentage) != lastPercentage and round(convertPercentage) % 2 == 0:
|
||||
lastPercentage = round(convertPercentage)
|
||||
if interface:
|
||||
interface.send("updateQueue", {'uuid': item['uuid'], 'conversion': lastPercentage})
|
||||
|
||||
del item['_EXTRA']
|
||||
with open(path.join(self.configFolder, 'spotifyCache.json'), 'w') as spotifyCache:
|
||||
json.dump(cache, spotifyCache)
|
||||
return result
|
||||
if interface:
|
||||
interface.send("startDownload", item['uuid'])
|
||||
|
||||
def get_user_playlists(self, user):
|
||||
if not self.spotifyEnabled:
|
||||
|
|
Loading…
Reference in New Issue