From 9206745295ad38da99dbcec39e0a161d7cf23a92 Mon Sep 17 00:00:00 2001 From: NeatoMonster <54335735+NeatoMonster@users.noreply.github.com> Date: Mon, 2 Oct 2023 16:35:48 -0700 Subject: [PATCH 1/2] Refactor (fix) Compilations & Featured In Previous behavior was very broken. --- deemon/core/api.py | 122 +++++++++++++++++++++++++-------------------- 1 file changed, 69 insertions(+), 53 deletions(-) diff --git a/deemon/core/api.py b/deemon/core/api.py index 295381e..42e250b 100644 --- a/deemon/core/api.py +++ b/deemon/core/api.py @@ -201,60 +201,76 @@ def get_artist_albums(self, query: dict, limit: int = -1): return query api_result = [] for r in result: - # Remove ID check to get compilations - if (r['ART_ID'] == str(query['artist_id']) and r['ARTISTS_ALBUMS_IS_OFFICIAL']) or (r['ART_ID'] == str(query['artist_id']) and config.allow_unofficial()) or config.allow_compilations(): - # TYPE 0 - single, TYPE 1 - album, TYPE 2 - compilation, TYPE 3 - ep - if r['TYPE'] == '0': - r['TYPE'] = "single" - elif r['TYPE'] == '1' and r['ART_ID'] != str(query['artist_id']): - if not config.allow_featured_in(): - logger.debug(f"Featured In for {query['artist_name']} detected but are disabled in config") - continue - else: - logger.debug(f"Featured In detected for artist {query['artist_name']}: {r['ALB_TITLE']}") - r['TYPE'] = "album" - # TODO set unique r['TYPE'] for FEATURED IN - elif r['TYPE'] == '2': - if not config.allow_compilations(): - logger.debug(f"Compilation for {query['artist_name']} detected but are disabled in config") - continue - else: - logger.debug(f"Compilation detected for artist {query['artist_name']}: {r['ALB_TITLE']}") - r['TYPE'] = "album" - # TODO set unique r['TYPE'] for COMPILATIONS - elif r['TYPE'] == '3': - r['TYPE'] = "ep" - else: - r['TYPE'] = "album" + if not config.allow_unofficial() and not r['ARTISTS_ALBUMS_IS_OFFICIAL']: + logger.debug(f"Unofficial for {query['artist_name']} detected but are disabled in config") + continue + if not config.allow_compilations() and (r['SUBTYPES']['isCompilation'] or r['TYPE'] == '2'): + logger.debug(f"Compilation for {query['artist_name']} detected but are disabled in config") + continue + if not config.allow_featured_in() and not (r['SUBTYPES']['isCompilation'] or r['TYPE'] == '2') and r['ART_ID'] != str(query['artist_id']): + logger.debug(f"Featured In for {query['artist_name']} detected but are disabled in config") + continue + # TYPE 0 - single, TYPE 1 - album, TYPE 2 - compilation, TYPE 3 - ep + if r['TYPE'] == '0': + r['TYPE'] = "single" + if r['SUBTYPES']['isCompilation']: + logger.debug(f"Compilation detected for artist {query['artist_name']}: {r['ALB_TITLE']}") + # TODO set unique r['TYPE'] for COMPILATIONS + elif r['ART_ID'] != str(query['artist_id']): + logger.debug(f"Featured In detected for artist {query['artist_name']}: {r['ALB_TITLE']}") + # TODO set unique r['TYPE'] for FEATURED IN + elif r['TYPE'] == '1': + r['TYPE'] = "album" + if r['SUBTYPES']['isCompilation']: + logger.debug(f"Compilation detected for artist {query['artist_name']}: {r['ALB_TITLE']}") + # TODO set unique r['TYPE'] for COMPILATIONS + elif r['ART_ID'] != str(query['artist_id']): + logger.debug(f"Featured In detected for artist {query['artist_name']}: {r['ALB_TITLE']}") + # TODO set unique r['TYPE'] for FEATURED IN + elif r['TYPE'] == '2': + r['TYPE'] = "album" + logger.debug(f"Compilation detected for artist {query['artist_name']}: {r['ALB_TITLE']}") + # TODO set unique r['TYPE'] for COMPILATIONS + elif r['TYPE'] == '3': + r['TYPE'] = "ep" + if r['SUBTYPES']['isCompilation']: + logger.debug(f"Compilation detected for artist {query['artist_name']}: {r['ALB_TITLE']}") + # TODO set unique r['TYPE'] for COMPILATIONS + elif r['ART_ID'] != str(query['artist_id']): + logger.debug(f"Featured In detected for artist {query['artist_name']}: {r['ALB_TITLE']}") + # TODO set unique r['TYPE'] for FEATURED IN + else: + logger.debug(f"Unable to process {query['artist_name']}: {r['ALB_TITLE']} ({r['ALB_ID']}), skipping") + continue - if r['ORIGINAL_RELEASE_DATE'] != "0000-00-00": - release_date = r['ORIGINAL_RELEASE_DATE'] - elif r['PHYSICAL_RELEASE_DATE'] != "0000-00-00": - release_date = r['PHYSICAL_RELEASE_DATE'] - elif r['DIGITAL_RELEASE_DATE'] != "0000-00-00": - release_date = r['DIGITAL_RELEASE_DATE'] - else: - # In the event of an unknown release date, set it to today's date - # See album ID: 417403 - logger.warning(f" [!] Found release without release date, assuming today: " - f"{query['artist_name']} - {r['ALB_TITLE']}") - release_date = datetime.strftime(datetime.today(), "%Y-%m-%d") - - cover_art = f"https://e-cdns-images.dzcdn.net/images/cover/{r['ALB_PICTURE']}/500x500-00000-80-0-0.jpg" - album_url = f"https://www.deezer.com/album/{r['ALB_ID']}" - - api_result.append( - { - 'id': int(r['ALB_ID']), - 'title': r['ALB_TITLE'], - 'release_date': release_date, - 'explicit_lyrics': r['EXPLICIT_ALBUM_CONTENT']['EXPLICIT_LYRICS_STATUS'], - 'record_type': r['TYPE'], - 'cover_big': cover_art, - 'link': album_url, - 'nb_tracks': r['NUMBER_TRACK'], - } - ) + if r['ORIGINAL_RELEASE_DATE'] != "0000-00-00": + release_date = r['ORIGINAL_RELEASE_DATE'] + elif r['PHYSICAL_RELEASE_DATE'] != "0000-00-00": + release_date = r['PHYSICAL_RELEASE_DATE'] + elif r['DIGITAL_RELEASE_DATE'] != "0000-00-00": + release_date = r['DIGITAL_RELEASE_DATE'] + else: + # In the event of an unknown release date, set it to today's date + # See album ID: 417403 + logger.warning(f" [!] Found release without release date, assuming today: " + f"{query['artist_name']} - {r['ALB_TITLE']}") + release_date = datetime.strftime(datetime.today(), "%Y-%m-%d") + + cover_art = f"https://e-cdns-images.dzcdn.net/images/cover/{r['ALB_PICTURE']}/500x500-00000-80-0-0.jpg" + album_url = f"https://www.deezer.com/album/{r['ALB_ID']}" + + api_result.append( + { + 'id': int(r['ALB_ID']), + 'title': r['ALB_TITLE'], + 'release_date': release_date, + 'explicit_lyrics': r['EXPLICIT_ALBUM_CONTENT']['EXPLICIT_LYRICS_STATUS'], + 'record_type': r['TYPE'], + 'cover_big': cover_art, + 'link': album_url, + 'nb_tracks': r['NUMBER_TRACK'], + } + ) else: api_result = self.api.get_artist_albums(artist_id=query['artist_id'], limit=limit)['data'] From 5cd12da7becae218229648bd487ed8d092aebb65 Mon Sep 17 00:00:00 2001 From: NeatoMonster <54335735+NeatoMonster@users.noreply.github.com> Date: Mon, 2 Oct 2023 17:38:23 -0700 Subject: [PATCH 2/2] Update Compilations Behavior Stay more in-line with previous behavior and documentation. --- deemon/core/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deemon/core/api.py b/deemon/core/api.py index 42e250b..6127b93 100644 --- a/deemon/core/api.py +++ b/deemon/core/api.py @@ -204,7 +204,7 @@ def get_artist_albums(self, query: dict, limit: int = -1): if not config.allow_unofficial() and not r['ARTISTS_ALBUMS_IS_OFFICIAL']: logger.debug(f"Unofficial for {query['artist_name']} detected but are disabled in config") continue - if not config.allow_compilations() and (r['SUBTYPES']['isCompilation'] or r['TYPE'] == '2'): + if not config.allow_compilations() and (r['SUBTYPES']['isCompilation'] or r['TYPE'] == '2') and r['ART_ID'] != str(query['artist_id']): logger.debug(f"Compilation for {query['artist_name']} detected but are disabled in config") continue if not config.allow_featured_in() and not (r['SUBTYPES']['isCompilation'] or r['TYPE'] == '2') and r['ART_ID'] != str(query['artist_id']):