Remove duplicate releases when getting artist discography

This commit is contained in:
RemixDev 2020-08-11 22:30:07 +02:00
parent d22f55c279
commit 42842b07b8
3 changed files with 38 additions and 35 deletions

View File

@ -1,3 +1,3 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
__version__ = "1.1.30" __version__ = "1.1.31"

View File

@ -280,6 +280,7 @@ class Deezer:
releases = [] releases = []
RELEASE_TYPE = ["single", "album", "compile", "ep"] RELEASE_TYPE = ["single", "album", "compile", "ep"]
result = {'all': []} result = {'all': []}
IDs = []
while True: while True:
response = self.gw_api_call('album.getDiscography', {'art_id': art_id, "discography_mode":"all", 'nb': nb, 'nb_songs': 0, 'start': start}) 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'] releases += response['results']['data']
@ -287,39 +288,41 @@ class Deezer:
if start > response['results']['total']: if start > response['results']['total']:
break break
for release in releases: for release in releases:
obj = { if release['ALB_ID'] not in IDs:
'id': release['ALB_ID'], IDs.append(release['ALB_ID'])
'title': release['ALB_TITLE'], obj = {
'link': f"https://www.deezer.com/album/{release['ALB_ID']}", 'id': release['ALB_ID'],
'cover': f"https://api.deezer.com/album/{release['ALB_ID']}/image", 'title': release['ALB_TITLE'],
'cover_small': f"https://cdns-images.dzcdn.net/images/cover/{release['ALB_PICTURE']}/56x56-000000-80-0-0.jpg", 'link': f"https://www.deezer.com/album/{release['ALB_ID']}",
'cover_medium': f"https://cdns-images.dzcdn.net/images/cover/{release['ALB_PICTURE']}/250x250-000000-80-0-0.jpg", 'cover': f"https://api.deezer.com/album/{release['ALB_ID']}/image",
'cover_big': f"https://cdns-images.dzcdn.net/images/cover/{release['ALB_PICTURE']}/500x500-000000-80-0-0.jpg", 'cover_small': f"https://cdns-images.dzcdn.net/images/cover/{release['ALB_PICTURE']}/56x56-000000-80-0-0.jpg",
'cover_xl': f"https://cdns-images.dzcdn.net/images/cover/{release['ALB_PICTURE']}/1000x1000-000000-80-0-0.jpg", 'cover_medium': f"https://cdns-images.dzcdn.net/images/cover/{release['ALB_PICTURE']}/250x250-000000-80-0-0.jpg",
'genre_id': release['GENRE_ID'], 'cover_big': f"https://cdns-images.dzcdn.net/images/cover/{release['ALB_PICTURE']}/500x500-000000-80-0-0.jpg",
'fans': release['RANK'], 'cover_xl': f"https://cdns-images.dzcdn.net/images/cover/{release['ALB_PICTURE']}/1000x1000-000000-80-0-0.jpg",
'release_date': release['PHYSICAL_RELEASE_DATE'], 'genre_id': release['GENRE_ID'],
'record_type': RELEASE_TYPE[int(release['TYPE'])], 'fans': release['RANK'],
'tracklist': f"https://api.deezer.com/album/{release['ALB_ID']}/tracks", 'release_date': release['PHYSICAL_RELEASE_DATE'],
'explicit_lyrics': int(release['EXPLICIT_LYRICS']) > 0, 'record_type': RELEASE_TYPE[int(release['TYPE'])],
'type': release['__TYPE__'], 'tracklist': f"https://api.deezer.com/album/{release['ALB_ID']}/tracks",
'nb_song': release['NUMBER_TRACK'], 'explicit_lyrics': int(release['EXPLICIT_LYRICS']) > 0,
'nb_disk': release['NUMBER_DISK'] 'type': release['__TYPE__'],
} 'nb_song': release['NUMBER_TRACK'],
if (release['ART_ID'] == art_id or release['ART_ID'] != art_id and release['ROLE_ID'] == 0) and release['ARTISTS_ALBUMS_IS_OFFICIAL']: 'nb_disk': release['NUMBER_DISK']
if not obj['record_type'] in result: }
result[obj['record_type']] = [] if (release['ART_ID'] == art_id or release['ART_ID'] != art_id and release['ROLE_ID'] == 0) and release['ARTISTS_ALBUMS_IS_OFFICIAL']:
result[obj['record_type']].append(obj) if not obj['record_type'] in result:
result['all'].append(obj) result[obj['record_type']] = []
else: result[obj['record_type']].append(obj)
if release['ROLE_ID'] == 5: result['all'].append(obj)
if not 'featured' in result: else:
result['featured'] = [] if release['ROLE_ID'] == 5:
result['featured'].append(obj) if not 'featured' in result:
elif release['ROLE_ID'] == 0: result['featured'] = []
if not 'more' in result: result['featured'].append(obj)
result['more'] = [] elif release['ROLE_ID'] == 0:
result['more'].append(obj) if not 'more' in result:
result['more'] = []
result['more'].append(obj)
return result return result
def search_main_gw(self, term): def search_main_gw(self, term):

View File

@ -7,7 +7,7 @@ README = (HERE / "README.md").read_text()
setup( setup(
name="deemix", name="deemix",
version="1.1.30", version="1.1.31",
description="A barebone deezer downloader library", description="A barebone deezer downloader library",
long_description=README, long_description=README,
long_description_content_type="text/markdown", long_description_content_type="text/markdown",