[GH-ISSUE #98] Efficient API refactor as a Python package #87

Closed
opened 2026-02-27 04:57:27 +03:00 by kerem · 2 comments
Owner

Originally created by @KyrillosL on GitHub (Oct 12, 2025).
Original GitHub issue: https://github.com/Googolplexed0/zotify/issues/98

Hello,

I'm working on an application that synchronizes two accounts (source -> target). I came across this project and saw your work about the efficient API calls.

  1. Coud your work benefit my application? I'm currently using the Spotipy package, and my current code is bellow.
  2. If yes, it could be interesting to split your code into a generic and efficient Spotify data fetcher API that is then extended to a specific purpose. We would have to remove the download method from your API Code, and Zotify would just import the generic API and extend it with a download feature. In my case, it wouldn't be a download feature, but a sync feature.
def get_all_playlists(api, account):
    client = api.get_client(account)
    playlists = []
    limit = 50
    offset = 0
    while True:
        page = client.current_user_playlists(limit=limit, offset=offset)
        items = page.get('items', [])
        playlists.extend({"id": p["id"], "name": p["name"]} for p in items)
        if len(items) < limit:
            break
        offset += limit
    return playlists

def get_playlist_tracks(api, account, playlist_id):
    client = api.get_client(account)
    tracks = []
    limit = 100
    offset = 0
    while True:
        page = client.playlist_items(playlist_id, limit=limit, offset=offset)
        items = page.get('items', [])
        for it in items:
            t = it.get('track')
            if t and t.get('id'):
                tracks.append(t['id'])
        if len(items) < limit:
            break
        offset += limit
    return tracks
Originally created by @KyrillosL on GitHub (Oct 12, 2025). Original GitHub issue: https://github.com/Googolplexed0/zotify/issues/98 Hello, I'm working on an application that synchronizes two accounts (source -> target). I came across this project and saw your work about the efficient API calls. 1. Coud your work benefit my application? I'm currently using the Spotipy package, and my current code is bellow. 2. If yes, it could be interesting to split your code into a generic and efficient Spotify data fetcher API that is then extended to a specific purpose. We would have to remove the `download` method from your API Code, and Zotify would just import the generic API and extend it with a download feature. In my case, it wouldn't be a download feature, but a sync feature. ``` def get_all_playlists(api, account): client = api.get_client(account) playlists = [] limit = 50 offset = 0 while True: page = client.current_user_playlists(limit=limit, offset=offset) items = page.get('items', []) playlists.extend({"id": p["id"], "name": p["name"]} for p in items) if len(items) < limit: break offset += limit return playlists def get_playlist_tracks(api, account, playlist_id): client = api.get_client(account) tracks = [] limit = 100 offset = 0 while True: page = client.playlist_items(playlist_id, limit=limit, offset=offset) items = page.get('items', []) for it in items: t = it.get('track') if t and t.get('id'): tracks.append(t['id']) if len(items) < limit: break offset += limit return tracks ```
kerem closed this issue 2026-02-27 04:57:28 +03:00
Author
Owner

@Googolplexed0 commented on GitHub (Oct 12, 2025):

  1. Could your work benefit my application?

Directly benefit? I doubt it. This repository has a lot of extra boilerplate code that isn't necessary for what you are trying to do. You are free to fork this and adapt it into whatever you would like but it would probably not be a very efficient use of your time.

The library you are currently using should have all the tools you need to create/edit playlists using the contents of an existing playlist. I've done similar tasks using that exact library. Your current approach is on the right track.

<!-- gh-comment-id:3395458682 --> @Googolplexed0 commented on GitHub (Oct 12, 2025): > 1. Could your work benefit my application? Directly benefit? I doubt it. This repository has a lot of extra boilerplate code that isn't necessary for what you are trying to do. You are free to fork this and adapt it into whatever you would like but it would probably not be a very efficient use of your time. The library you are currently using should have all the tools you need to create/edit playlists using the contents of an existing playlist. I've done similar tasks using that exact library. Your current approach is on the right track.
Author
Owner

@KyrillosL commented on GitHub (Oct 12, 2025):

Thanks for your answer, Googolplexed0.
I'm curious why you didn't use the Spotipy package and you reimplemented a lot of stuff related to API calls (such as the invoke_url_nextable) if they are already implemented and efficient?

<!-- gh-comment-id:3395463444 --> @KyrillosL commented on GitHub (Oct 12, 2025): Thanks for your answer, Googolplexed0. I'm curious why you didn't use the Spotipy package and you reimplemented a lot of stuff related to API calls (such as the `invoke_url_nextable`) if they are already implemented and efficient?
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/zotify#87
No description provided.