Fixed conversion for some spotify urls
You need to remove spotifyCache.json in the config folder to use this
This commit is contained in:
parent
39be6077d3
commit
1599223384
|
@ -21,7 +21,7 @@ class QueueManager:
|
||||||
self.currentItem = ""
|
self.currentItem = ""
|
||||||
self.sp = spotifyHelper
|
self.sp = spotifyHelper
|
||||||
|
|
||||||
def generateQueueItem(self, dz, url, settings, bitrate=None, albumAPI=None, interface=None):
|
def generateQueueItem(self, dz, url, settings, bitrate=None, albumAPI=None, trackAPI=None, interface=None):
|
||||||
forcedBitrate = getBitrateInt(bitrate)
|
forcedBitrate = getBitrateInt(bitrate)
|
||||||
bitrate = forcedBitrate if forcedBitrate else settings['maxBitrate']
|
bitrate = forcedBitrate if forcedBitrate else settings['maxBitrate']
|
||||||
if 'deezer.page.link' in url:
|
if 'deezer.page.link' in url:
|
||||||
|
@ -37,16 +37,16 @@ class QueueManager:
|
||||||
elif type == "track":
|
elif type == "track":
|
||||||
if id.startswith("isrc"):
|
if id.startswith("isrc"):
|
||||||
try:
|
try:
|
||||||
trackAPI = dz.get_track(id)
|
isrcTest = dz.get_track(id)
|
||||||
if 'id' in trackAPI and 'title' in trackAPI:
|
if 'id' in isrcTest and 'title' in isrcTest:
|
||||||
id = trackAPI['id']
|
id = isrcTest['id']
|
||||||
else:
|
else:
|
||||||
return QueueError(url, "Track ISRC is not available on deezer", "ISRCnotOnDeezer")
|
return QueueError(url, "Track ISRC is not available on deezer", "ISRCnotOnDeezer")
|
||||||
except APIError as e:
|
except APIError as e:
|
||||||
e = json.loads(str(e))
|
e = json.loads(str(e))
|
||||||
return QueueError(url, 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 ''}")
|
||||||
try:
|
try:
|
||||||
trackAPI = dz.get_track_gw(id)
|
trackAPI_gw = dz.get_track_gw(id)
|
||||||
except APIError as e:
|
except APIError as e:
|
||||||
e = json.loads(str(e))
|
e = json.loads(str(e))
|
||||||
message = "Wrong URL"
|
message = "Wrong URL"
|
||||||
|
@ -54,25 +54,27 @@ class QueueManager:
|
||||||
message += f": {e['DATA_ERROR']}"
|
message += f": {e['DATA_ERROR']}"
|
||||||
return QueueError(url, message)
|
return QueueError(url, message)
|
||||||
if albumAPI:
|
if albumAPI:
|
||||||
trackAPI['_EXTRA_ALBUM'] = albumAPI
|
trackAPI_gw['_EXTRA_ALBUM'] = albumAPI
|
||||||
|
if trackAPI:
|
||||||
|
trackAPI_gw['_EXTRA_TRACK'] = trackAPI
|
||||||
if settings['createSingleFolder']:
|
if settings['createSingleFolder']:
|
||||||
trackAPI['FILENAME_TEMPLATE'] = settings['albumTracknameTemplate']
|
trackAPI_gw['FILENAME_TEMPLATE'] = settings['albumTracknameTemplate']
|
||||||
else:
|
else:
|
||||||
trackAPI['FILENAME_TEMPLATE'] = settings['tracknameTemplate']
|
trackAPI_gw['FILENAME_TEMPLATE'] = settings['tracknameTemplate']
|
||||||
trackAPI['SINGLE_TRACK'] = True
|
trackAPI_gw['SINGLE_TRACK'] = True
|
||||||
|
|
||||||
title = trackAPI['SNG_TITLE']
|
title = trackAPI_gw['SNG_TITLE']
|
||||||
if 'VERSION' in trackAPI and trackAPI['VERSION']:
|
if 'VERSION' in trackAPI_gw and trackAPI_gw['VERSION']:
|
||||||
title += " " + trackAPI['VERSION']
|
title += " " + trackAPI_gw['VERSION']
|
||||||
return QISingle(
|
return QISingle(
|
||||||
id,
|
id,
|
||||||
bitrate,
|
bitrate,
|
||||||
title,
|
title,
|
||||||
trackAPI['ART_NAME'],
|
trackAPI_gw['ART_NAME'],
|
||||||
f"https://e-cdns-images.dzcdn.net/images/cover/{trackAPI['ALB_PICTURE']}/75x75-000000-80-0-0.jpg",
|
f"https://e-cdns-images.dzcdn.net/images/cover/{trackAPI_gw['ALB_PICTURE']}/75x75-000000-80-0-0.jpg",
|
||||||
'track',
|
'track',
|
||||||
settings,
|
settings,
|
||||||
trackAPI,
|
trackAPI_gw,
|
||||||
)
|
)
|
||||||
|
|
||||||
elif type == "album":
|
elif type == "album":
|
||||||
|
@ -88,7 +90,7 @@ class QueueManager:
|
||||||
albumAPI['copyright'] = albumAPI_gw['COPYRIGHT']
|
albumAPI['copyright'] = albumAPI_gw['COPYRIGHT']
|
||||||
if albumAPI['nb_tracks'] == 1:
|
if albumAPI['nb_tracks'] == 1:
|
||||||
return self.generateQueueItem(dz, f"https://www.deezer.com/track/{albumAPI['tracks']['data'][0]['id']}",
|
return self.generateQueueItem(dz, f"https://www.deezer.com/track/{albumAPI['tracks']['data'][0]['id']}",
|
||||||
settings, bitrate, albumAPI)
|
settings, bitrate, albumAPI=albumAPI, interface=interface)
|
||||||
tracksArray = dz.get_album_tracks_gw(id)
|
tracksArray = dz.get_album_tracks_gw(id)
|
||||||
if albumAPI['nb_tracks'] == 255:
|
if albumAPI['nb_tracks'] == 255:
|
||||||
albumAPI['nb_tracks'] = len(tracksArray)
|
albumAPI['nb_tracks'] = len(tracksArray)
|
||||||
|
@ -177,7 +179,7 @@ class QueueManager:
|
||||||
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(self.generateQueueItem(dz, album['link'], settings, bitrate))
|
albumList.append(self.generateQueueItem(dz, album['link'], settings, bitrate, interface=interface))
|
||||||
|
|
||||||
if interface:
|
if interface:
|
||||||
interface.send("finishAddingArtist", {'name': artistAPI['name'], 'id': artistAPI['id']})
|
interface.send("finishAddingArtist", {'name': artistAPI['name'], 'id': artistAPI['id']})
|
||||||
|
@ -199,7 +201,7 @@ class QueueManager:
|
||||||
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(self.generateQueueItem(dz, album['link'], settings, bitrate))
|
albumList.append(self.generateQueueItem(dz, album['link'], settings, bitrate, interface=interface))
|
||||||
|
|
||||||
if interface:
|
if interface:
|
||||||
interface.send("finishAddingArtist", {'name': artistAPI['name'], 'id': artistAPI['id']})
|
interface.send("finishAddingArtist", {'name': artistAPI['name'], 'id': artistAPI['id']})
|
||||||
|
@ -276,14 +278,14 @@ class QueueManager:
|
||||||
return QueueError(url, "Spotify Features is not setted up correctly.", "spotifyDisabled")
|
return QueueError(url, "Spotify Features is not setted up correctly.", "spotifyDisabled")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
track_id = self.sp.get_trackid_spotify(dz, id, settings['fallbackSearch'])
|
(track_id, trackAPI, _) = self.sp.get_trackid_spotify(dz, id, settings['fallbackSearch'])
|
||||||
except SpotifyException as e:
|
except SpotifyException as e:
|
||||||
return QueueError(url, "Wrong URL: "+e.msg[e.msg.find('\n')+2:])
|
return QueueError(url, "Wrong URL: "+e.msg[e.msg.find('\n')+2:])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return QueueError(url, "Something went wrong: "+str(e))
|
return QueueError(url, "Something went wrong: "+str(e))
|
||||||
|
|
||||||
if track_id != "0":
|
if track_id != "0":
|
||||||
return self.generateQueueItem(dz, f'https://www.deezer.com/track/{track_id}', settings, bitrate)
|
return self.generateQueueItem(dz, f'https://www.deezer.com/track/{track_id}', settings, bitrate, trackAPI=trackAPI, interface=interface)
|
||||||
else:
|
else:
|
||||||
logger.warn("Track not found on deezer!")
|
logger.warn("Track not found on deezer!")
|
||||||
return QueueError(url, "Track not found on deezer!", "trackNotOnDeezer")
|
return QueueError(url, "Track not found on deezer!", "trackNotOnDeezer")
|
||||||
|
@ -301,7 +303,7 @@ class QueueManager:
|
||||||
return QueueError(url, "Something went wrong: "+str(e))
|
return QueueError(url, "Something went wrong: "+str(e))
|
||||||
|
|
||||||
if album_id != "0":
|
if album_id != "0":
|
||||||
return self.generateQueueItem(dz, f'https://www.deezer.com/album/{album_id}', settings, bitrate)
|
return self.generateQueueItem(dz, f'https://www.deezer.com/album/{album_id}', settings, bitrate, interface=interface)
|
||||||
else:
|
else:
|
||||||
logger.warn("Album not found on deezer!")
|
logger.warn("Album not found on deezer!")
|
||||||
return QueueError(url, "Album not found on deezer!", "albumNotOnDeezer")
|
return QueueError(url, "Album not found on deezer!", "albumNotOnDeezer")
|
||||||
|
|
|
@ -132,27 +132,31 @@ class SpotifyHelper:
|
||||||
else:
|
else:
|
||||||
cache = {'tracks': {}, 'albums': {}}
|
cache = {'tracks': {}, 'albums': {}}
|
||||||
if str(track_id) in cache['tracks']:
|
if str(track_id) in cache['tracks']:
|
||||||
return cache['tracks'][str(track_id)]
|
dz_track = dz.get_track_by_ISRC(cache['tracks'][str(track_id)]['isrc'])
|
||||||
|
return (cache['tracks'][str(track_id)]['id'], dz_track, cache['tracks'][str(track_id)]['isrc'])
|
||||||
singleTrack = True
|
singleTrack = True
|
||||||
spotify_track = self.sp.track(track_id)
|
spotify_track = self.sp.track(track_id)
|
||||||
else:
|
else:
|
||||||
spotify_track = spotifyTrack
|
spotify_track = spotifyTrack
|
||||||
dz_track = "0"
|
dz_id = "0"
|
||||||
|
dz_track = None
|
||||||
|
isrc = None
|
||||||
if 'external_ids' in spotify_track and 'isrc' in spotify_track['external_ids']:
|
if 'external_ids' in spotify_track and 'isrc' in spotify_track['external_ids']:
|
||||||
try:
|
try:
|
||||||
dz_track = dz.get_track_by_ISRC(spotify_track['external_ids']['isrc'])
|
dz_track = dz.get_track_by_ISRC(spotify_track['external_ids']['isrc'])
|
||||||
dz_track = dz_track['id'] if 'id' in dz_track and 'title' in dz_track else "0"
|
dz_id = dz_track['id'] if 'id' in dz_track and 'title' in dz_track else "0"
|
||||||
|
isrc = spotify_track['external_ids']['isrc']
|
||||||
except:
|
except:
|
||||||
dz_track = dz.get_track_from_metadata(spotify_track['artists'][0]['name'], spotify_track['name'],
|
dz_id = dz.get_track_from_metadata(spotify_track['artists'][0]['name'], spotify_track['name'],
|
||||||
spotify_track['album']['name']) if fallbackSearch else "0"
|
spotify_track['album']['name']) if fallbackSearch else "0"
|
||||||
elif fallbackSearch:
|
elif fallbackSearch:
|
||||||
dz_track = dz.get_track_from_metadata(spotify_track['artists'][0]['name'], spotify_track['name'],
|
dz_id = dz.get_track_from_metadata(spotify_track['artists'][0]['name'], spotify_track['name'],
|
||||||
spotify_track['album']['name'])
|
spotify_track['album']['name'])
|
||||||
if singleTrack:
|
if singleTrack:
|
||||||
cache['tracks'][str(track_id)] = dz_track
|
cache['tracks'][str(track_id)] = {'id': dz_id, 'isrc': isrc}
|
||||||
with open(path.join(self.configFolder, 'spotifyCache.json'), 'w') as spotifyCache:
|
with open(path.join(self.configFolder, 'spotifyCache.json'), 'w') as spotifyCache:
|
||||||
json.dump(cache, spotifyCache)
|
json.dump(cache, spotifyCache)
|
||||||
return dz_track
|
return (dz_id, dz_track, isrc)
|
||||||
|
|
||||||
# Returns deezer album_id from spotify album_id
|
# Returns deezer album_id from spotify album_id
|
||||||
def get_albumid_spotify(self, dz, album_id):
|
def get_albumid_spotify(self, dz, album_id):
|
||||||
|
@ -164,20 +168,22 @@ class SpotifyHelper:
|
||||||
else:
|
else:
|
||||||
cache = {'tracks': {}, 'albums': {}}
|
cache = {'tracks': {}, 'albums': {}}
|
||||||
if str(album_id) in cache['albums']:
|
if str(album_id) in cache['albums']:
|
||||||
return cache['albums'][str(album_id)]
|
return cache['albums'][str(album_id)]['id']
|
||||||
spotify_album = self.sp.album(album_id)
|
spotify_album = self.sp.album(album_id)
|
||||||
dz_album = "0"
|
dz_album = "0"
|
||||||
|
upc = None
|
||||||
if 'external_ids' in spotify_album and 'upc' in spotify_album['external_ids']:
|
if 'external_ids' in spotify_album and 'upc' in spotify_album['external_ids']:
|
||||||
try:
|
try:
|
||||||
dz_album = dz.get_album_by_UPC(spotify_album['external_ids']['upc'])
|
dz_album = dz.get_album_by_UPC(spotify_album['external_ids']['upc'])
|
||||||
dz_album = dz_album['id'] if 'id' in dz_album else "0"
|
dz_album = dz_album['id'] if 'id' in dz_album else "0"
|
||||||
|
upc = spotify_album['external_ids']['upc']
|
||||||
except:
|
except:
|
||||||
try:
|
try:
|
||||||
dz_album = dz.get_album_by_UPC(int(spotify_album['external_ids']['upc']))
|
dz_album = dz.get_album_by_UPC(int(spotify_album['external_ids']['upc']))
|
||||||
dz_album = dz_album['id'] if 'id' in dz_album else "0"
|
dz_album = dz_album['id'] if 'id' in dz_album else "0"
|
||||||
except:
|
except:
|
||||||
dz_album = "0"
|
dz_album = "0"
|
||||||
cache['albums'][str(album_id)] = dz_album
|
cache['albums'][str(album_id)] = {'id': dz_album, 'upc': upc}
|
||||||
with open(path.join(self.configFolder, 'spotifyCache.json'), 'w') as spotifyCache:
|
with open(path.join(self.configFolder, 'spotifyCache.json'), 'w') as spotifyCache:
|
||||||
json.dump(cache, spotifyCache)
|
json.dump(cache, spotifyCache)
|
||||||
return dz_album
|
return dz_album
|
||||||
|
@ -240,10 +246,14 @@ class SpotifyHelper:
|
||||||
if queueItem.cancel:
|
if queueItem.cancel:
|
||||||
return
|
return
|
||||||
if str(track['id']) in cache['tracks']:
|
if str(track['id']) in cache['tracks']:
|
||||||
trackID = cache['tracks'][str(track['id'])]
|
trackID = cache['tracks'][str(track['id'])]['id']
|
||||||
|
trackAPI = dz.get_track_by_ISRC(cache['tracks'][str(track['id'])]['isrc'])
|
||||||
else:
|
else:
|
||||||
trackID = self.get_trackid_spotify(dz, "0", queueItem.settings['fallbackSearch'], track)
|
(trackID, trackAPI, isrc) = self.get_trackid_spotify(dz, "0", queueItem.settings['fallbackSearch'], track)
|
||||||
cache['tracks'][str(track['id'])] = trackID
|
cache['tracks'][str(track['id'])] = {
|
||||||
|
'id': trackID,
|
||||||
|
'isrc': isrc
|
||||||
|
}
|
||||||
if str(trackID) == "0":
|
if str(trackID) == "0":
|
||||||
deezerTrack = {
|
deezerTrack = {
|
||||||
'SNG_ID': "0",
|
'SNG_ID': "0",
|
||||||
|
@ -260,6 +270,8 @@ class SpotifyHelper:
|
||||||
else:
|
else:
|
||||||
deezerTrack = dz.get_track_gw(trackID)
|
deezerTrack = dz.get_track_gw(trackID)
|
||||||
deezerTrack['_EXTRA_PLAYLIST'] = queueItem.extra['playlistAPI']
|
deezerTrack['_EXTRA_PLAYLIST'] = queueItem.extra['playlistAPI']
|
||||||
|
if trackAPI:
|
||||||
|
deezerTrack['_EXTRA_TRACK'] = trackAPI
|
||||||
deezerTrack['POSITION'] = pos
|
deezerTrack['POSITION'] = pos
|
||||||
deezerTrack['SIZE'] = queueItem.size
|
deezerTrack['SIZE'] = queueItem.size
|
||||||
deezerTrack['FILENAME_TEMPLATE'] = queueItem.settings['playlistTracknameTemplate']
|
deezerTrack['FILENAME_TEMPLATE'] = queueItem.settings['playlistTracknameTemplate']
|
||||||
|
|
Loading…
Reference in New Issue