diversify icon indicating copy to clipboard operation
diversify copied to clipboard

Change get_user_playlists() so it returns the same data structure for different values of the features param

Open edujtm opened this issue 7 years ago • 4 comments

Currently the get_user_playlists() method has a features parameter that is meant to get audio features instead of its meta data. The user of the API probably will not expect this to happen, so it can lead to poor user experience and bugs.

Current behavior (wrong one):

def get_user_playlists(spfy, userid, features=False, flat=False):

   if features:
      return # List of tuples with (album name, list of songs meta-data)
   else:
      return # List of songs with audio features

In the current behavior, when using features=True, the audio features from the playlists will be merged together. When using features=False, the songs will be separated by playlist. Its better to implement it as a consistent behavior.

Better behavior:

def get_user_playlists(spfy, userid, features=False, flat=False):

   if features:
      return # List of tuples with (album name, list of songs meta-data)
   else:
      return # List of tuples with (album name, list of songs audio features)

edujtm avatar Oct 03 '19 01:10 edujtm

how can I get the album name, list of songs meta-data and list of songs audio features

pieceofeden avatar Oct 03 '19 13:10 pieceofeden

Wait a little bit, I'll do an update of the README with instructions. As I said in #13, I wasn't expecting other people to see the issues.

edujtm avatar Oct 03 '19 14:10 edujtm

I added instructions on the README.md, but here's what you can do after you setup your environment:

import interfacespfy as isp
import pprint

spfy = isp.login_user("your spotify username")

playlists = isp.get_user_playlists(spfy, "other-username")
for name, playlist in playlists:
    print(f'Playlist name: {name}')
    pprint.pprint(playlist)

The get_user_playlists methods get all user public playlists songs (it can be your user or any other). If the user doesn't have public playlists it might return nothing. If you want to get your saved songs, you should use get_favorite_songs() instead.

edujtm avatar Oct 03 '19 17:10 edujtm

Fixed it on commit 029c9389c32100ec81e3be6faa9dd1bc57d8d70f.

edujtm avatar Oct 03 '19 21:10 edujtm