Skip to content

Commit

Permalink
Merge branch 'fdarveau-update-deezer-lists-handling'
Browse files Browse the repository at this point in the history
  • Loading branch information
XDGFX committed Aug 12, 2021
2 parents 4268bab + e91d0d6 commit 9493d83
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions ultrasonics/official_plugins/up_deezer.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"mode": [
"playlists"
],
"version": "0.2",
"version": "0.3",
"settings": [
{
"type": "auth",
Expand Down Expand Up @@ -261,19 +261,15 @@ def list_playlists(self):
"index": 0
}

playlists = self.api(url, params=params)["data"]
playlists_response = self.api(url, params=params)
playlists = playlists_response["data"]

playlist_count = len(playlists)
i = 1
playlists_count = playlists_response["total"]

# Get all playlists from the user
while playlist_count == limit:
params["index"] = limit * i

buffer = self.api(url, params=params)["data"]
playlists.extend(buffer)
playlist_count = len(buffer)
i += 1
# Get all playlists from the playlist
while "next" in playlists_response:
playlists_response = self.api(playlists_response["next"])
playlists.extend(playlists_response["data"])

log.info(f"Found {len(playlists)} playlist(s) on Deezer.")

Expand All @@ -292,19 +288,15 @@ def playlist_tracks(self, playlist_id):
"index": 0
}

tracks = self.api(url, params=params)["data"]
tracks_response = self.api(url, params=params)
tracks = tracks_response["data"]

tracks_count = len(tracks)
i = 1
tracks_count = tracks_response["total"]

# Get all tracks from the playlist
while tracks_count == limit:
params["index"] = limit * i

buffer = self.api(url, params=params)["data"]
tracks.extend(buffer)
tracks_count = len(buffer)
i += 1
while "next" in tracks_response:
tracks_response = self.api(tracks_response["next"])
tracks.extend(tracks_response["data"])

track_list = []

Expand Down Expand Up @@ -507,7 +499,9 @@ def deezer_to_songs_dict(self, track=None, result=None):
remove_ids = [
deezer_id for deezer_id in existing_ids if deezer_id not in new_ids + duplicate_ids]

dz.remove_tracks_from_playlist(playlist_id, remove_ids)
# Skip if no songs are to be removed
if remove_ids:
dz.remove_tracks_from_playlist(playlist_id, remove_ids)

# Add tracks to playlist in batches of 100
url = f"https://api.deezer.com/playlist/{playlist_id}/tracks"
Expand Down

0 comments on commit 9493d83

Please sign in to comment.