From 42842b07b8fe70c89a7ea93dab2e7b363f9d6ad4 Mon Sep 17 00:00:00 2001 From: RemixDev Date: Tue, 11 Aug 2020 22:30:07 +0200 Subject: [PATCH] Remove duplicate releases when getting artist discography --- deemix/__init__.py | 2 +- deemix/api/deezer.py | 69 +++++++++++++++++++++++--------------------- setup.py | 2 +- 3 files changed, 38 insertions(+), 35 deletions(-) diff --git a/deemix/__init__.py b/deemix/__init__.py index 42e1e43..bfa5d4c 100644 --- a/deemix/__init__.py +++ b/deemix/__init__.py @@ -1,3 +1,3 @@ #!/usr/bin/env python3 -__version__ = "1.1.30" +__version__ = "1.1.31" diff --git a/deemix/api/deezer.py b/deemix/api/deezer.py index 85a4732..e8c25aa 100755 --- a/deemix/api/deezer.py +++ b/deemix/api/deezer.py @@ -280,6 +280,7 @@ class Deezer: releases = [] RELEASE_TYPE = ["single", "album", "compile", "ep"] result = {'all': []} + IDs = [] while True: response = self.gw_api_call('album.getDiscography', {'art_id': art_id, "discography_mode":"all", 'nb': nb, 'nb_songs': 0, 'start': start}) releases += response['results']['data'] @@ -287,39 +288,41 @@ class Deezer: if start > response['results']['total']: break for release in releases: - obj = { - 'id': release['ALB_ID'], - 'title': release['ALB_TITLE'], - 'link': f"https://www.deezer.com/album/{release['ALB_ID']}", - 'cover': f"https://api.deezer.com/album/{release['ALB_ID']}/image", - 'cover_small': f"https://cdns-images.dzcdn.net/images/cover/{release['ALB_PICTURE']}/56x56-000000-80-0-0.jpg", - 'cover_medium': f"https://cdns-images.dzcdn.net/images/cover/{release['ALB_PICTURE']}/250x250-000000-80-0-0.jpg", - 'cover_big': f"https://cdns-images.dzcdn.net/images/cover/{release['ALB_PICTURE']}/500x500-000000-80-0-0.jpg", - 'cover_xl': f"https://cdns-images.dzcdn.net/images/cover/{release['ALB_PICTURE']}/1000x1000-000000-80-0-0.jpg", - 'genre_id': release['GENRE_ID'], - 'fans': release['RANK'], - 'release_date': release['PHYSICAL_RELEASE_DATE'], - 'record_type': RELEASE_TYPE[int(release['TYPE'])], - 'tracklist': f"https://api.deezer.com/album/{release['ALB_ID']}/tracks", - 'explicit_lyrics': int(release['EXPLICIT_LYRICS']) > 0, - 'type': release['__TYPE__'], - 'nb_song': release['NUMBER_TRACK'], - 'nb_disk': release['NUMBER_DISK'] - } - if (release['ART_ID'] == art_id or release['ART_ID'] != art_id and release['ROLE_ID'] == 0) and release['ARTISTS_ALBUMS_IS_OFFICIAL']: - if not obj['record_type'] in result: - result[obj['record_type']] = [] - result[obj['record_type']].append(obj) - result['all'].append(obj) - else: - if release['ROLE_ID'] == 5: - if not 'featured' in result: - result['featured'] = [] - result['featured'].append(obj) - elif release['ROLE_ID'] == 0: - if not 'more' in result: - result['more'] = [] - result['more'].append(obj) + if release['ALB_ID'] not in IDs: + IDs.append(release['ALB_ID']) + obj = { + 'id': release['ALB_ID'], + 'title': release['ALB_TITLE'], + 'link': f"https://www.deezer.com/album/{release['ALB_ID']}", + 'cover': f"https://api.deezer.com/album/{release['ALB_ID']}/image", + 'cover_small': f"https://cdns-images.dzcdn.net/images/cover/{release['ALB_PICTURE']}/56x56-000000-80-0-0.jpg", + 'cover_medium': f"https://cdns-images.dzcdn.net/images/cover/{release['ALB_PICTURE']}/250x250-000000-80-0-0.jpg", + 'cover_big': f"https://cdns-images.dzcdn.net/images/cover/{release['ALB_PICTURE']}/500x500-000000-80-0-0.jpg", + 'cover_xl': f"https://cdns-images.dzcdn.net/images/cover/{release['ALB_PICTURE']}/1000x1000-000000-80-0-0.jpg", + 'genre_id': release['GENRE_ID'], + 'fans': release['RANK'], + 'release_date': release['PHYSICAL_RELEASE_DATE'], + 'record_type': RELEASE_TYPE[int(release['TYPE'])], + 'tracklist': f"https://api.deezer.com/album/{release['ALB_ID']}/tracks", + 'explicit_lyrics': int(release['EXPLICIT_LYRICS']) > 0, + 'type': release['__TYPE__'], + 'nb_song': release['NUMBER_TRACK'], + 'nb_disk': release['NUMBER_DISK'] + } + if (release['ART_ID'] == art_id or release['ART_ID'] != art_id and release['ROLE_ID'] == 0) and release['ARTISTS_ALBUMS_IS_OFFICIAL']: + if not obj['record_type'] in result: + result[obj['record_type']] = [] + result[obj['record_type']].append(obj) + result['all'].append(obj) + else: + if release['ROLE_ID'] == 5: + if not 'featured' in result: + result['featured'] = [] + result['featured'].append(obj) + elif release['ROLE_ID'] == 0: + if not 'more' in result: + result['more'] = [] + result['more'].append(obj) return result def search_main_gw(self, term): diff --git a/setup.py b/setup.py index b4146c5..5ccb94b 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ README = (HERE / "README.md").read_text() setup( name="deemix", - version="1.1.30", + version="1.1.31", description="A barebone deezer downloader library", long_description=README, long_description_content_type="text/markdown",