2020-09-18 11:43:54 +00:00
|
|
|
import eventlet
|
2020-04-16 08:37:02 +00:00
|
|
|
import json
|
2020-09-27 21:44:37 +00:00
|
|
|
from pathlib import Path
|
2020-04-16 08:37:02 +00:00
|
|
|
|
2020-09-18 11:43:54 +00:00
|
|
|
eventlet.import_patched('requests.adapters')
|
|
|
|
|
|
|
|
spotipy = eventlet.import_patched('spotipy')
|
|
|
|
SpotifyClientCredentials = spotipy.oauth2.SpotifyClientCredentials
|
2020-05-26 10:16:07 +00:00
|
|
|
from deemix.utils.localpaths import getConfigFolder
|
2020-09-12 11:08:28 +00:00
|
|
|
from deemix.app.queueitem import QIConvertable
|
2020-04-17 10:31:47 +00:00
|
|
|
|
2020-08-15 13:49:45 +00:00
|
|
|
emptyPlaylist = {
|
|
|
|
'collaborative': False,
|
|
|
|
'description': "",
|
|
|
|
'external_urls': {'spotify': None},
|
|
|
|
'followers': {'total': 0, 'href': None},
|
|
|
|
'id': None,
|
|
|
|
'images': [],
|
|
|
|
'name': "Something went wrong",
|
|
|
|
'owner': {
|
|
|
|
'display_name': "Error",
|
|
|
|
'id': None
|
|
|
|
},
|
|
|
|
'public': True,
|
|
|
|
'tracks' : [],
|
|
|
|
'type': 'playlist',
|
|
|
|
'uri': None
|
|
|
|
}
|
2020-04-17 10:31:47 +00:00
|
|
|
|
2020-04-16 08:37:02 +00:00
|
|
|
class SpotifyHelper:
|
2020-05-26 10:16:07 +00:00
|
|
|
def __init__(self, configFolder=None):
|
2020-04-17 10:31:47 +00:00
|
|
|
self.credentials = {}
|
|
|
|
self.spotifyEnabled = False
|
|
|
|
self.sp = None
|
2020-08-15 13:49:45 +00:00
|
|
|
self.configFolder = configFolder
|
2020-04-17 10:31:47 +00:00
|
|
|
|
2020-10-04 09:56:32 +00:00
|
|
|
# Make sure config folder exists
|
2020-08-15 13:49:45 +00:00
|
|
|
if not self.configFolder:
|
|
|
|
self.configFolder = getConfigFolder()
|
2020-09-27 21:44:37 +00:00
|
|
|
self.configFolder = Path(self.configFolder)
|
|
|
|
if not self.configFolder.is_dir():
|
|
|
|
self.configFolder.mkdir()
|
2020-08-15 13:49:45 +00:00
|
|
|
|
|
|
|
# Make sure authCredentials exsits
|
2020-09-27 21:44:37 +00:00
|
|
|
if not (self.configFolder / 'authCredentials.json').is_file():
|
|
|
|
with open(self.configFolder / 'authCredentials.json', 'w') as f:
|
2020-04-17 10:31:47 +00:00
|
|
|
json.dump({'clientId': "", 'clientSecret': ""}, f, indent=2)
|
2020-08-15 13:49:45 +00:00
|
|
|
|
|
|
|
# Load spotify id and secret and check if they are usable
|
2020-09-27 21:44:37 +00:00
|
|
|
with open(self.configFolder / 'authCredentials.json', 'r') as credentialsFile:
|
2020-04-17 10:31:47 +00:00
|
|
|
self.credentials = json.load(credentialsFile)
|
|
|
|
self.checkCredentials()
|
2020-09-20 16:32:39 +00:00
|
|
|
self.checkValidCache()
|
|
|
|
|
|
|
|
def checkValidCache(self):
|
2020-09-27 21:44:37 +00:00
|
|
|
if (self.configFolder / 'spotifyCache.json').is_file():
|
|
|
|
with open(self.configFolder / 'spotifyCache.json', 'r') as spotifyCache:
|
2020-09-20 16:32:39 +00:00
|
|
|
try:
|
|
|
|
cache = json.load(spotifyCache)
|
|
|
|
except Exception as e:
|
|
|
|
print(str(e))
|
2020-09-27 21:44:37 +00:00
|
|
|
(self.configFolder / 'spotifyCache.json').unlink()
|
2020-09-20 16:32:39 +00:00
|
|
|
return
|
|
|
|
# Remove old versions of cache
|
|
|
|
if len(cache['tracks'].values()) and isinstance(list(cache['tracks'].values())[0], int) or \
|
|
|
|
len(cache['albums'].values()) and isinstance(list(cache['albums'].values())[0], int):
|
2020-09-27 21:44:37 +00:00
|
|
|
(self.configFolder / 'spotifyCache.json').unlink()
|
2020-04-16 08:37:02 +00:00
|
|
|
|
2020-04-17 10:31:47 +00:00
|
|
|
def checkCredentials(self):
|
|
|
|
if self.credentials['clientId'] == "" or self.credentials['clientSecret'] == "":
|
|
|
|
spotifyEnabled = False
|
|
|
|
else:
|
|
|
|
try:
|
2020-08-15 13:49:45 +00:00
|
|
|
client_credentials_manager = SpotifyClientCredentials(client_id=self.credentials['clientId'],
|
|
|
|
client_secret=self.credentials['clientSecret'])
|
|
|
|
self.sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
|
2020-04-17 10:31:47 +00:00
|
|
|
self.sp.user_playlists('spotify')
|
|
|
|
self.spotifyEnabled = True
|
|
|
|
except Exception as e:
|
|
|
|
self.spotifyEnabled = False
|
|
|
|
return self.spotifyEnabled
|
2020-04-16 08:37:02 +00:00
|
|
|
|
2020-04-17 10:31:47 +00:00
|
|
|
def getCredentials(self):
|
|
|
|
return self.credentials
|
2020-04-16 08:37:02 +00:00
|
|
|
|
2020-04-17 10:31:47 +00:00
|
|
|
def setCredentials(self, spotifyCredentials):
|
2020-08-15 13:49:45 +00:00
|
|
|
# Remove extra spaces, just to be sure
|
2020-07-31 12:09:14 +00:00
|
|
|
spotifyCredentials['clientId'] = spotifyCredentials['clientId'].strip()
|
|
|
|
spotifyCredentials['clientSecret'] = spotifyCredentials['clientSecret'].strip()
|
2020-08-15 13:49:45 +00:00
|
|
|
|
|
|
|
# Save them to disk
|
2020-09-27 21:44:37 +00:00
|
|
|
with open(self.configFolder / 'authCredentials.json', 'w') as f:
|
2020-04-17 10:31:47 +00:00
|
|
|
json.dump(spotifyCredentials, f, indent=2)
|
2020-08-15 13:49:45 +00:00
|
|
|
|
|
|
|
# Check if they are usable
|
2020-04-17 10:31:47 +00:00
|
|
|
self.credentials = spotifyCredentials
|
|
|
|
self.checkCredentials()
|
2020-04-16 08:37:02 +00:00
|
|
|
|
2020-08-15 13:49:45 +00:00
|
|
|
# Converts spotify API playlist structure to deezer's playlist structure
|
2020-04-17 10:31:47 +00:00
|
|
|
def _convert_playlist_structure(self, spotify_obj):
|
|
|
|
if len(spotify_obj['images']):
|
|
|
|
url = spotify_obj['images'][0]['url']
|
|
|
|
else:
|
2020-05-05 13:08:04 +00:00
|
|
|
url = False
|
2020-04-17 10:31:47 +00:00
|
|
|
deezer_obj = {
|
|
|
|
'checksum': spotify_obj['snapshot_id'],
|
|
|
|
'collaborative': spotify_obj['collaborative'],
|
2020-06-22 21:24:42 +00:00
|
|
|
'creation_date': "XXXX-00-00",
|
2020-05-05 13:08:04 +00:00
|
|
|
'creator': {
|
|
|
|
'id': spotify_obj['owner']['id'],
|
|
|
|
'name': spotify_obj['owner']['display_name'],
|
|
|
|
'tracklist': spotify_obj['owner']['href'],
|
|
|
|
'type': "user"
|
|
|
|
},
|
2020-04-17 10:31:47 +00:00
|
|
|
'description': spotify_obj['description'],
|
|
|
|
'duration': 0,
|
2020-05-05 13:08:04 +00:00
|
|
|
'fans': spotify_obj['followers']['total'] if 'followers' in spotify_obj else 0,
|
2020-04-17 10:31:47 +00:00
|
|
|
'id': spotify_obj['id'],
|
|
|
|
'is_loved_track': False,
|
|
|
|
'link': spotify_obj['external_urls']['spotify'],
|
|
|
|
'nb_tracks': spotify_obj['tracks']['total'],
|
|
|
|
'picture': url,
|
|
|
|
'picture_small': url,
|
2020-05-05 13:08:04 +00:00
|
|
|
'picture_medium': url,
|
|
|
|
'picture_big': url,
|
2020-04-17 10:31:47 +00:00
|
|
|
'picture_xl': url,
|
|
|
|
'public': spotify_obj['public'],
|
|
|
|
'share': spotify_obj['external_urls']['spotify'],
|
|
|
|
'title': spotify_obj['name'],
|
|
|
|
'tracklist': spotify_obj['tracks']['href'],
|
|
|
|
'type': "playlist"
|
|
|
|
}
|
2020-05-05 13:08:04 +00:00
|
|
|
if not url:
|
|
|
|
deezer_obj['picture_small'] = "https://e-cdns-images.dzcdn.net/images/cover/d41d8cd98f00b204e9800998ecf8427e/56x56-000000-80-0-0.jpg"
|
|
|
|
deezer_obj['picture_medium'] = "https://e-cdns-images.dzcdn.net/images/cover/d41d8cd98f00b204e9800998ecf8427e/250x250-000000-80-0-0.jpg"
|
|
|
|
deezer_obj['picture_big'] = "https://e-cdns-images.dzcdn.net/images/cover/d41d8cd98f00b204e9800998ecf8427e/500x500-000000-80-0-0.jpg"
|
|
|
|
deezer_obj['picture_xl'] = "https://e-cdns-images.dzcdn.net/images/cover/d41d8cd98f00b204e9800998ecf8427e/1000x1000-000000-80-0-0.jpg"
|
2020-04-17 10:31:47 +00:00
|
|
|
return deezer_obj
|
2020-04-16 08:37:02 +00:00
|
|
|
|
2020-08-15 13:49:45 +00:00
|
|
|
# Returns deezer song_id from spotify track_id or track dict
|
2020-04-17 10:31:47 +00:00
|
|
|
def get_trackid_spotify(self, dz, track_id, fallbackSearch, spotifyTrack=None):
|
|
|
|
if not self.spotifyEnabled:
|
|
|
|
raise spotifyFeaturesNotEnabled
|
2020-06-11 12:30:35 +00:00
|
|
|
singleTrack = False
|
2020-04-17 10:31:47 +00:00
|
|
|
if not spotifyTrack:
|
2020-09-27 21:44:37 +00:00
|
|
|
if (self.configFolder / 'spotifyCache.json').is_file():
|
|
|
|
with open(self.configFolder / 'spotifyCache.json', 'r') as spotifyCache:
|
2020-06-11 12:30:35 +00:00
|
|
|
cache = json.load(spotifyCache)
|
|
|
|
else:
|
|
|
|
cache = {'tracks': {}, 'albums': {}}
|
|
|
|
if str(track_id) in cache['tracks']:
|
2020-09-25 16:10:47 +00:00
|
|
|
dz_track = None
|
2020-09-18 13:06:31 +00:00
|
|
|
if cache['tracks'][str(track_id)]['isrc']:
|
|
|
|
dz_track = dz.get_track_by_ISRC(cache['tracks'][str(track_id)]['isrc'])
|
2020-09-25 16:10:47 +00:00
|
|
|
dz_id = dz_track['id'] if 'id' in dz_track and 'title' in dz_track else "0"
|
|
|
|
cache['tracks'][str(track_id)]['id'] = dz_id
|
2020-09-15 17:41:11 +00:00
|
|
|
return (cache['tracks'][str(track_id)]['id'], dz_track, cache['tracks'][str(track_id)]['isrc'])
|
2020-06-11 12:30:35 +00:00
|
|
|
singleTrack = True
|
2020-04-17 10:31:47 +00:00
|
|
|
spotify_track = self.sp.track(track_id)
|
|
|
|
else:
|
|
|
|
spotify_track = spotifyTrack
|
2020-09-15 17:41:11 +00:00
|
|
|
dz_id = "0"
|
|
|
|
dz_track = None
|
|
|
|
isrc = None
|
2020-04-17 10:31:47 +00:00
|
|
|
if 'external_ids' in spotify_track and 'isrc' in spotify_track['external_ids']:
|
|
|
|
try:
|
|
|
|
dz_track = dz.get_track_by_ISRC(spotify_track['external_ids']['isrc'])
|
2020-09-15 17:41:11 +00:00
|
|
|
dz_id = dz_track['id'] if 'id' in dz_track and 'title' in dz_track else "0"
|
|
|
|
isrc = spotify_track['external_ids']['isrc']
|
2020-04-17 10:31:47 +00:00
|
|
|
except:
|
2020-09-15 17:41:11 +00:00
|
|
|
dz_id = dz.get_track_from_metadata(spotify_track['artists'][0]['name'], spotify_track['name'],
|
2020-08-18 13:13:32 +00:00
|
|
|
spotify_track['album']['name']) if fallbackSearch else "0"
|
2020-04-17 10:31:47 +00:00
|
|
|
elif fallbackSearch:
|
2020-09-15 17:41:11 +00:00
|
|
|
dz_id = dz.get_track_from_metadata(spotify_track['artists'][0]['name'], spotify_track['name'],
|
2020-04-17 10:31:47 +00:00
|
|
|
spotify_track['album']['name'])
|
2020-06-11 12:30:35 +00:00
|
|
|
if singleTrack:
|
2020-09-15 17:41:11 +00:00
|
|
|
cache['tracks'][str(track_id)] = {'id': dz_id, 'isrc': isrc}
|
2020-09-27 21:44:37 +00:00
|
|
|
with open(self.configFolder / 'spotifyCache.json', 'w') as spotifyCache:
|
2020-06-11 12:30:35 +00:00
|
|
|
json.dump(cache, spotifyCache)
|
2020-09-15 17:41:11 +00:00
|
|
|
return (dz_id, dz_track, isrc)
|
2020-04-16 08:37:02 +00:00
|
|
|
|
2020-08-15 13:49:45 +00:00
|
|
|
# Returns deezer album_id from spotify album_id
|
2020-04-17 10:31:47 +00:00
|
|
|
def get_albumid_spotify(self, dz, album_id):
|
|
|
|
if not self.spotifyEnabled:
|
|
|
|
raise spotifyFeaturesNotEnabled
|
2020-09-27 21:44:37 +00:00
|
|
|
if (self.configFolder / 'spotifyCache.json').is_file():
|
|
|
|
with open(self.configFolder / 'spotifyCache.json', 'r') as spotifyCache:
|
2020-06-11 12:30:35 +00:00
|
|
|
cache = json.load(spotifyCache)
|
|
|
|
else:
|
|
|
|
cache = {'tracks': {}, 'albums': {}}
|
|
|
|
if str(album_id) in cache['albums']:
|
2020-09-15 17:41:11 +00:00
|
|
|
return cache['albums'][str(album_id)]['id']
|
2020-04-17 10:31:47 +00:00
|
|
|
spotify_album = self.sp.album(album_id)
|
2020-08-18 13:13:32 +00:00
|
|
|
dz_album = "0"
|
2020-09-15 17:41:11 +00:00
|
|
|
upc = None
|
2020-04-17 10:31:47 +00:00
|
|
|
if 'external_ids' in spotify_album and 'upc' in spotify_album['external_ids']:
|
|
|
|
try:
|
|
|
|
dz_album = dz.get_album_by_UPC(spotify_album['external_ids']['upc'])
|
2020-08-18 13:13:32 +00:00
|
|
|
dz_album = dz_album['id'] if 'id' in dz_album else "0"
|
2020-09-15 17:41:11 +00:00
|
|
|
upc = spotify_album['external_ids']['upc']
|
2020-04-17 10:31:47 +00:00
|
|
|
except:
|
|
|
|
try:
|
|
|
|
dz_album = dz.get_album_by_UPC(int(spotify_album['external_ids']['upc']))
|
2020-08-18 13:13:32 +00:00
|
|
|
dz_album = dz_album['id'] if 'id' in dz_album else "0"
|
2020-04-17 10:31:47 +00:00
|
|
|
except:
|
2020-08-18 13:13:32 +00:00
|
|
|
dz_album = "0"
|
2020-09-15 17:41:11 +00:00
|
|
|
cache['albums'][str(album_id)] = {'id': dz_album, 'upc': upc}
|
2020-09-27 21:44:37 +00:00
|
|
|
with open(self.configFolder / 'spotifyCache.json', 'w') as spotifyCache:
|
2020-06-11 12:30:35 +00:00
|
|
|
json.dump(cache, spotifyCache)
|
2020-04-17 10:31:47 +00:00
|
|
|
return dz_album
|
2020-04-16 08:37:02 +00:00
|
|
|
|
2020-08-15 13:49:45 +00:00
|
|
|
|
2020-08-16 10:29:51 +00:00
|
|
|
def generate_playlist_queueitem(self, dz, playlist_id, bitrate, settings):
|
2020-04-17 10:31:47 +00:00
|
|
|
if not self.spotifyEnabled:
|
|
|
|
raise spotifyFeaturesNotEnabled
|
|
|
|
spotify_playlist = self.sp.playlist(playlist_id)
|
2020-08-15 13:49:45 +00:00
|
|
|
|
2020-04-17 10:31:47 +00:00
|
|
|
if len(spotify_playlist['images']):
|
2020-08-15 13:49:45 +00:00
|
|
|
cover = spotify_playlist['images'][0]['url']
|
2020-04-17 10:31:47 +00:00
|
|
|
else:
|
2020-08-15 13:49:45 +00:00
|
|
|
cover = "https://e-cdns-images.dzcdn.net/images/cover/d41d8cd98f00b204e9800998ecf8427e/75x75-000000-80-0-0.jpg"
|
|
|
|
|
2020-04-17 10:31:47 +00:00
|
|
|
playlistAPI = self._convert_playlist_structure(spotify_playlist)
|
|
|
|
playlistAPI['various_artist'] = dz.get_artist(5080)
|
2020-08-15 13:49:45 +00:00
|
|
|
|
|
|
|
extra = {}
|
|
|
|
extra['unconverted'] = []
|
|
|
|
|
2020-07-30 16:46:34 +00:00
|
|
|
tracklistTmp = spotify_playlist['tracks']['items']
|
2020-04-17 10:31:47 +00:00
|
|
|
while spotify_playlist['tracks']['next']:
|
|
|
|
spotify_playlist['tracks'] = self.sp.next(spotify_playlist['tracks'])
|
2020-07-30 16:46:34 +00:00
|
|
|
tracklistTmp += spotify_playlist['tracks']['items']
|
|
|
|
for item in tracklistTmp:
|
|
|
|
if item['track']:
|
2020-08-14 17:50:37 +00:00
|
|
|
if item['track']['explicit']:
|
|
|
|
playlistAPI['explicit'] = True
|
2020-08-15 13:49:45 +00:00
|
|
|
extra['unconverted'].append(item['track'])
|
|
|
|
|
|
|
|
totalSize = len(extra['unconverted'])
|
2020-08-14 17:50:37 +00:00
|
|
|
if not 'explicit' in playlistAPI:
|
|
|
|
playlistAPI['explicit'] = False
|
2020-08-15 13:49:45 +00:00
|
|
|
extra['playlistAPI'] = playlistAPI
|
2020-08-15 21:03:05 +00:00
|
|
|
return QIConvertable(
|
2020-08-15 13:49:45 +00:00
|
|
|
playlist_id,
|
2020-08-16 10:29:51 +00:00
|
|
|
bitrate,
|
2020-08-15 13:49:45 +00:00
|
|
|
spotify_playlist['name'],
|
|
|
|
spotify_playlist['owner']['display_name'],
|
|
|
|
cover,
|
2020-09-28 18:31:48 +00:00
|
|
|
playlistAPI['explicit'],
|
2020-08-15 13:49:45 +00:00
|
|
|
totalSize,
|
|
|
|
'spotify_playlist',
|
|
|
|
settings,
|
|
|
|
extra,
|
|
|
|
)
|
2020-08-14 17:50:37 +00:00
|
|
|
|
2020-08-15 21:03:05 +00:00
|
|
|
def convert_spotify_playlist(self, dz, queueItem, interface=None):
|
2020-08-14 17:50:37 +00:00
|
|
|
convertPercentage = 0
|
|
|
|
lastPercentage = 0
|
2020-09-27 21:44:37 +00:00
|
|
|
if (self.configFolder / 'spotifyCache.json').is_file():
|
|
|
|
with open(self.configFolder / 'spotifyCache.json', 'r') as spotifyCache:
|
2020-06-11 12:30:35 +00:00
|
|
|
cache = json.load(spotifyCache)
|
|
|
|
else:
|
|
|
|
cache = {'tracks': {}, 'albums': {}}
|
2020-08-14 17:50:37 +00:00
|
|
|
if interface:
|
2020-08-15 21:03:05 +00:00
|
|
|
interface.send("startConversion", queueItem.uuid)
|
2020-08-15 13:49:45 +00:00
|
|
|
collection = []
|
2020-08-15 21:03:05 +00:00
|
|
|
for pos, track in enumerate(queueItem.extra['unconverted'], start=1):
|
2020-08-19 15:16:39 +00:00
|
|
|
if queueItem.cancel:
|
|
|
|
return
|
2020-07-30 16:46:34 +00:00
|
|
|
if str(track['id']) in cache['tracks']:
|
2020-09-15 17:41:11 +00:00
|
|
|
trackID = cache['tracks'][str(track['id'])]['id']
|
2020-09-18 13:06:31 +00:00
|
|
|
trackAPI = None
|
|
|
|
if cache['tracks'][str(track['id'])]['isrc']:
|
|
|
|
trackAPI = dz.get_track_by_ISRC(cache['tracks'][str(track['id'])]['isrc'])
|
2020-06-11 12:30:35 +00:00
|
|
|
else:
|
2020-09-15 17:41:11 +00:00
|
|
|
(trackID, trackAPI, isrc) = self.get_trackid_spotify(dz, "0", queueItem.settings['fallbackSearch'], track)
|
|
|
|
cache['tracks'][str(track['id'])] = {
|
|
|
|
'id': trackID,
|
|
|
|
'isrc': isrc
|
|
|
|
}
|
2020-08-24 16:58:42 +00:00
|
|
|
if str(trackID) == "0":
|
2020-04-17 10:31:47 +00:00
|
|
|
deezerTrack = {
|
2020-08-18 13:13:32 +00:00
|
|
|
'SNG_ID': "0",
|
2020-07-30 16:46:34 +00:00
|
|
|
'SNG_TITLE': track['name'],
|
2020-04-17 10:31:47 +00:00
|
|
|
'DURATION': 0,
|
|
|
|
'MD5_ORIGIN': 0,
|
|
|
|
'MEDIA_VERSION': 0,
|
|
|
|
'FILESIZE': 0,
|
2020-07-30 16:46:34 +00:00
|
|
|
'ALB_TITLE': track['album']['name'],
|
2020-04-17 10:31:47 +00:00
|
|
|
'ALB_PICTURE': "",
|
|
|
|
'ART_ID': 0,
|
2020-07-30 16:46:34 +00:00
|
|
|
'ART_NAME': track['artists'][0]['name']
|
2020-04-17 10:31:47 +00:00
|
|
|
}
|
|
|
|
else:
|
|
|
|
deezerTrack = dz.get_track_gw(trackID)
|
2020-08-15 21:03:05 +00:00
|
|
|
deezerTrack['_EXTRA_PLAYLIST'] = queueItem.extra['playlistAPI']
|
2020-09-15 17:41:11 +00:00
|
|
|
if trackAPI:
|
|
|
|
deezerTrack['_EXTRA_TRACK'] = trackAPI
|
2020-04-17 10:31:47 +00:00
|
|
|
deezerTrack['POSITION'] = pos
|
2020-08-15 21:03:05 +00:00
|
|
|
deezerTrack['SIZE'] = queueItem.size
|
|
|
|
deezerTrack['FILENAME_TEMPLATE'] = queueItem.settings['playlistTracknameTemplate']
|
2020-08-15 13:49:45 +00:00
|
|
|
collection.append(deezerTrack)
|
2020-08-14 17:50:37 +00:00
|
|
|
|
2020-08-15 21:03:05 +00:00
|
|
|
convertPercentage = (pos / queueItem.size) * 100
|
2020-08-16 10:29:51 +00:00
|
|
|
if round(convertPercentage) != lastPercentage and round(convertPercentage) % 5 == 0:
|
2020-08-14 17:50:37 +00:00
|
|
|
lastPercentage = round(convertPercentage)
|
|
|
|
if interface:
|
2020-08-15 21:03:05 +00:00
|
|
|
interface.send("updateQueue", {'uuid': queueItem.uuid, 'conversion': lastPercentage})
|
|
|
|
|
|
|
|
queueItem.extra = None
|
|
|
|
queueItem.collection = collection
|
2020-08-14 17:50:37 +00:00
|
|
|
|
2020-09-27 21:44:37 +00:00
|
|
|
with open(self.configFolder / 'spotifyCache.json', 'w') as spotifyCache:
|
2020-06-11 12:30:35 +00:00
|
|
|
json.dump(cache, spotifyCache)
|
2020-04-16 08:37:02 +00:00
|
|
|
|
2020-05-05 13:08:04 +00:00
|
|
|
def get_user_playlists(self, user):
|
|
|
|
if not self.spotifyEnabled:
|
|
|
|
raise spotifyFeaturesNotEnabled
|
|
|
|
result = []
|
|
|
|
playlists = self.sp.user_playlists(user)
|
|
|
|
while playlists:
|
|
|
|
for playlist in playlists['items']:
|
|
|
|
result.append(self._convert_playlist_structure(playlist))
|
|
|
|
if playlists['next']:
|
|
|
|
playlists = self.sp.next(playlists)
|
|
|
|
else:
|
|
|
|
playlists = None
|
|
|
|
return result
|
|
|
|
|
|
|
|
def get_playlist_tracklist(self, id):
|
|
|
|
if not self.spotifyEnabled:
|
|
|
|
raise spotifyFeaturesNotEnabled
|
|
|
|
playlist = self.sp.playlist(id)
|
|
|
|
tracklist = playlist['tracks']['items']
|
|
|
|
while playlist['tracks']['next']:
|
|
|
|
playlist['tracks'] = self.sp.next(playlist['tracks'])
|
|
|
|
tracklist += playlist['tracks']['items']
|
|
|
|
playlist['tracks'] = tracklist
|
|
|
|
return playlist
|
|
|
|
|
2020-04-16 08:37:02 +00:00
|
|
|
|
|
|
|
class spotifyFeaturesNotEnabled(Exception):
|
2020-04-17 10:31:47 +00:00
|
|
|
pass
|