Better handling of albums upcs

This commit is contained in:
RemixDev 2021-06-08 11:16:52 +02:00
parent 261b7adb36
commit c47e394039
No known key found for this signature in database
GPG Key ID: B33962B465BDB51C
1 changed files with 18 additions and 5 deletions

View File

@ -49,12 +49,25 @@ def generateTrackItem(dz, link_id, bitrate, trackAPI=None, albumAPI=None):
def generateAlbumItem(dz, link_id, bitrate, rootArtist=None):
# Get essential album info
try:
albumAPI = dz.api.get_album(link_id)
except APIError as e:
raise GenerationError(f"https://deezer.com/album/{link_id}", str(e)) from e
if str(link_id).startswith('upc'):
upcs = [link_id[4:],]
upcs.append(int(upcs[0]))
lastError = None
for upc in upcs:
try:
albumAPI = dz.api.get_album(f"upc:{upc}")
except APIError as e:
lastError = e
albumAPI = None
if not albumAPI:
raise GenerationError(f"https://deezer.com/album/{link_id}", str(lastError)) from lastError
link_id = albumAPI['id']
else:
try:
albumAPI = dz.api.get_album(link_id)
except APIError as e:
raise GenerationError(f"https://deezer.com/album/{link_id}", str(e)) from e
if str(link_id).startswith('upc'): link_id = albumAPI['id']
if not link_id.isdecimal(): raise InvalidID(f"https://deezer.com/album/{link_id}")
# Get extra info about album