Fixed issues with spotify playlist and the queue manager

This commit is contained in:
RemixDev 2020-08-16 12:29:51 +02:00
parent d4bcc728f4
commit e8357cf5e1
5 changed files with 13 additions and 16 deletions

View File

@ -1,3 +1,3 @@
#!/usr/bin/env python3
__version__ = "1.1.31"
__version__ = "1.2.0"

View File

@ -92,7 +92,7 @@ class DownloadJob:
self.dz = dz
self.sp = sp
self.interface = interface
if isinstance(queueItem, QIConvertable):
if isinstance(queueItem, QIConvertable) and queueItem.extra:
self.sp.convert_spotify_playlist(self.dz, queueItem, interface=self.interface)
self.queueItem = queueItem
self.settings = queueItem.settings
@ -609,7 +609,7 @@ class DownloadJob:
if 'error' in result:
self.completeTrackPercentage()
self.queueItem.failed += 1
self.queueItem.errors.append(result['error']['message'])
self.queueItem.errors.append(result['error'])
if self.interface:
error = result['error']
self.interface.send("updateQueue", {

View File

@ -3,11 +3,12 @@ from deemix.app.downloadjob import DownloadJob
from deemix.utils.misc import getIDFromLink, getTypeFromLink, getBitrateInt
from deemix.api.deezer import APIError
from spotipy.exceptions import SpotifyException
from deemix.app.queueitem import QISingle, QICollection
from deemix.app.queueitem import QISingle, QICollection, QIConvertable
import logging
import os.path as path
import json
from os import remove
from time import sleep
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger('deemix')
@ -304,9 +305,7 @@ class QueueManager:
return QueueError(url, "Spotify Features is not setted up correctly.", "spotifyDisabled")
try:
playlist = sp.generate_playlist_queueitem(dz, id, settings)
playlist.bitrate = bitrate
return playlist
return sp.generate_playlist_queueitem(dz, id, bitrate, settings)
except SpotifyException as e:
return QueueError(url, "Wrong URL: "+e.msg[e.msg.find('\n')+2:])
@ -423,7 +422,6 @@ class QueueManager:
queueList[uuid] = self.queueList[uuid].getResettedItem()
else:
queueList[uuid] = self.queueList[uuid].toDict()
print(self.queueList[uuid].progress)
return queueList
def slimQueueList(self):
@ -432,14 +430,14 @@ class QueueManager:
queueList[uuid] = self.queueList[uuid].getSlimmedItem()
return queueList
def loadQueue(self, dz, sp, configFolder, settings, interface=None):
def loadQueue(self, configFolder, settings, interface=None):
if path.isfile(path.join(configFolder, 'queue.json')) and not len(self.queue):
if interface:
interface.send('restoringQueue')
with open(path.join(configFolder, 'queue.json'), 'r') as f:
qd = json.load(f)
remove(path.join(configFolder, 'queue.json'))
self.restoreQueue(qd['queue'], qd['queueComplete'], qd['queueList'], settings, dz, sp, interface)
self.restoreQueue(qd['queue'], qd['queueComplete'], qd['queueList'], settings)
if interface:
interface.send('init_downloadQueue', {
'queue': self.queue,
@ -447,9 +445,8 @@ class QueueManager:
'queueList': self.slimQueueList(),
'restored': True
})
self.nextItem(dz, sp, interface)
def restoreQueue(self, queue, queueComplete, queueList, settings, dz, sp, interface=None):
def restoreQueue(self, queue, queueComplete, queueList, settings):
self.queue = queue
self.queueComplete = queueComplete
self.queueList = {}

View File

@ -183,7 +183,7 @@ class SpotifyHelper:
return dz_album
def generate_playlist_queueitem(self, dz, playlist_id, settings):
def generate_playlist_queueitem(self, dz, playlist_id, bitrate, settings):
if not self.spotifyEnabled:
raise spotifyFeaturesNotEnabled
spotify_playlist = self.sp.playlist(playlist_id)
@ -215,7 +215,7 @@ class SpotifyHelper:
extra['playlistAPI'] = playlistAPI
return QIConvertable(
playlist_id,
0,
bitrate,
spotify_playlist['name'],
spotify_playlist['owner']['display_name'],
cover,
@ -264,7 +264,7 @@ class SpotifyHelper:
collection.append(deezerTrack)
convertPercentage = (pos / queueItem.size) * 100
if round(convertPercentage) != lastPercentage and round(convertPercentage) % 2 == 0:
if round(convertPercentage) != lastPercentage and round(convertPercentage) % 5 == 0:
lastPercentage = round(convertPercentage)
if interface:
interface.send("updateQueue", {'uuid': queueItem.uuid, 'conversion': lastPercentage})

View File

@ -7,7 +7,7 @@ README = (HERE / "README.md").read_text()
setup(
name="deemix",
version="1.1.31",
version="1.2.0",
description="A barebone deezer downloader library",
long_description=README,
long_description_content_type="text/markdown",