jbh-cloud / spotify_sync

A schedulable, configurable CLI downloader for Spotify accounts
MIT License
176 stars 7 forks source link

'spotify_sync stats playlists' returns error if user has no playlists #5

Closed larsjohannessen closed 2 years ago

larsjohannessen commented 2 years ago

First off, really handy tool - thanks for releasing it.

I've successfully integrated my Spotify account based on the instructions in these docs. (Thank you for writing clear and easy-to-follow docs.)

I also have the following set in my config.json (based on what I read in these docs):

    "spotify": {
        "client_id": "[REDACTED]",
        "client_secret": "[REDACTED]",
        "username": "[REDACTED]",
        "scope": "user-library-read, playlist-read-private",
        "redirect_uri_port": "9090",
        "playlists": {
            "enabled": true,
            "owner_only": false,
            "excluded": []
        }
    },

I would love to be able to extract a playlist from my Spotify account. When I run spotify_sync run sync-spotify --config ~/Music/config.json, nothing much happens:

[lars@familyroompc Music]$ spotify_sync run sync-spotify --config ~/Music/config.json 
[2022-08-20 22:07:20,945] INFO      SpotifySync      : Loading config from file /home/lars/Music/config.json
[2022-08-20 22:07:20,946] INFO      SpotifySync      : Script started with sync-spotify command
[2022-08-20 22:07:20,947] INFO      SpotifyService   : Fetching liked songs
[2022-08-20 22:07:21,221] INFO      SpotifyService   : Added 0 new liked song(s) from Spotify (cached:0)
[2022-08-20 22:07:21,222] INFO      SpotifySync      : Script finished

When I try to view all playlists associated with my account via spotify_sync stats playlists --config ~/Music/config.json, I get the following stack trace:

[lars@familyroompc Music]$ spotify_sync stats playlists --config ~/Music/config.json 
Traceback (most recent call last):
  File "/home/lars/.local/bin/spotify_sync", line 8, in <module>
    sys.exit(cli())
  File "/home/lars/.local/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/lars/.local/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/lars/.local/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/lars/.local/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/lars/.local/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/lars/.local/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/lars/.local/lib/python3.10/site-packages/spotify_sync/__main__.py", line 183, in playlist_stats
    app.playlist_stats()
  File "/home/lars/.local/lib/python3.10/site-packages/spotify_sync/cli.py", line 144, in playlist_stats
    spotify_svc.display_playlist_stats()
  File "/home/lars/.local/lib/python3.10/site-packages/spotify_sync/spotify_.py", line 54, in display_playlist_stats
    header = stats[0].keys()
IndexError: list index out of range

I get the same behavior if I run spotify_sync stats playlists --profile myFirstProfile

Any idea what I could be doing wrong?

I'm not sure what else you might find important, so I'll try to give you as many details as I can think of:

  1. I have a single playlist that a friend sent me a link to.
  2. I clicked the green heart on it, which added it to my Spotify Library.
  3. When I click the playlist to open it up on the Spotify Web UI, I see that Spotify calls it a "Collaborative Playlist" towards the top of the screen.
  4. The playlist has ~600 songs on it.
  5. My account is a free account.

Some additional system info below:

[lars@familyroompc Music]$ python --version
Python 3.10.4
[lars@familyroompc Music]$ uname -a
Linux familyroompc 5.17.5-300.fc36.x86_64 #1 SMP PREEMPT Thu Apr 28 15:51:30 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
[lars@familyroompc Music]$ cat /etc/fedora-release 
Fedora release 36 (Thirty Six)
jbh-cloud commented 2 years ago

hey @larsjohannessen thanks for providing so much information and context!

Collaborative playlists is something I have overlooked by the sound of it. In theory the existing code will allow you to download it if your Spotify OAuth token allows access to read them (doesn't currently). I also need to stop the stats code blowing up if the app cant find any.

Give this a go:

You should find a hidden file '.spotify-oauth-cache-USERNAME', remove this ls -la ~/.local/share/spotify_sync/USERNAME

Update your Spotify scope in your config to: user-library-read, playlist-read-private, playlist-read-collaborative

Re-cache your Spotify OAuth access token spotify_sync utils authorize-spotify ...

Re-run auto-mode, it should start the download.

I'll update the app soon to have additional options to include/exclude collaborative playlists

jbh-cloud commented 2 years ago

Created new issue for #7 collaborative playlist support