zmb3 / spotify

A Go wrapper for the Spotify Web API
Apache License 2.0
1.33k stars 284 forks source link

`AddTracksToPlaylist` could not accept adding episodes of podcasts #180

Open kerkerj opened 2 years ago

kerkerj commented 2 years ago

In AddTracksToPlaylist method, the arguments are provided in form of ID strings, instead of providing URI.

The src code:

func (c *Client) AddTracksToPlaylist(ctx context.Context, playlistID ID, trackIDs ...ID) (snapshotID string, err error) {
    uris := make([]string, len(trackIDs))
    for i, id := range trackIDs {
        uris[i] = fmt.Sprintf("spotify:track:%s", id)
    }
    m := make(map[string]interface{})
    m["uris"] = uris

uris[i] = fmt.Sprintf("spotify:track:%s", id) ☝️ This limits from adding episodes of podcasts to the playlist, because the URI of episodes is like spotify:episode:XXXXXXXX

After checking the playlist section of Spotify API doc

How about adding a new API AddItemsToPlaylist with the same approach of AddTracksToPlaylist, the only difference is that AddItemsToPlaylist accepts URI instead of ID to gain more flexibility without breaking the AddTracksToPlaylist API behavior?

example:

func (c *Client) AddItemsToPlaylist(ctx context.Context, playlistID ID, position int, items ...URI) (snapshotID string, err error) { /* To be implemented */}

// accepts:
// {"uris": ["spotify:track:4iV5W9uYEdYUVa79Axb7Rh","spotify:track:1301WleyT98MSxVHPZCA6M","spotify:episode:1311WleyT98MSxVHPZCA6M"], "position": 3}

I can help with adding this btw :)

p.s. Adding this new API with accepting position argument might resolve this issue as well: https://github.com/zmb3/spotify/issues/174

strideynet commented 2 years ago

I like this, happy to accept a PR implementing this.