From c47e394039ea6a756bdac0bd9651319e97a6e02b Mon Sep 17 00:00:00 2001 From: RemixDev Date: Tue, 8 Jun 2021 11:16:52 +0200 Subject: [PATCH] Better handling of albums upcs --- deemix/itemgen.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/deemix/itemgen.py b/deemix/itemgen.py index 36821db..fd5f6b8 100644 --- a/deemix/itemgen.py +++ b/deemix/itemgen.py @@ -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