New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception spotify.SpotifyError: 'Failed to get link from a playlist' when adding new playlist #387

Closed
kingosticks opened this Issue Apr 2, 2013 · 8 comments

Comments

2 participants
@kingosticks
Member

kingosticks commented Apr 2, 2013

When new playlists are created by the pyspotify jukebox client or the Spotify web player (or presumably the Windows client too) an exception is raised from refresh_playlists:

Exception spotify.SpotifyError: 'Failed to get link from a playlist' in <bound method SpotifyContainerManager.container_loaded of <mopidy.backends.spotify.container_manager.SpotifyContainerManager instance at 0x2e2f830>> ignored

The added playlist is then not available within mopidy, at least until SpotifySessionManager.refresh_playlists() fires again (which I do by restarting mopidy or removing a playlist) after which point all playlists are successfully loaded and available within mopidy.

I think the exception is caused by uri = str(Link.from_track(spotify_track, 0)) in spotify/translator.py when the newly added playlist has not yet loaded. The libspotify docs say to wait until the playlist_state_changed callback has fired but it doesn't look like this callback (and a few others) are wired up in pyspotify's SpotifyPlaylistManager. I'm not 100% sure if this is a pyspotify issue or a mopidy issue (or a both a bit of both); the pyspotify jukebox client doesn't have this issue but it doesn't try and access the playlists on container_loaded like mopidy does.

It also might have something to do with sp_playlist_is_in_ram which I was surprised to see isn't used by pyspotify anywhere.

@kingosticks

This comment has been minimized.

Member

kingosticks commented Apr 24, 2013

I was playing around with this last night but I only managed to make matters worse. I was running Mopidy with verbose output and saw numerous ChannelError(x, y, playlist) messages which seem to be originating from libspotify (via pyspotify). Can't find anything to indicate what they mean. I was surprised to see that the container_loaded() callback doesn't seem to always fire after logging in at all, or at least fire before the full refresh_playlists() occurs.

I also noticed that on shutdown, the Spotify thread is killed before SpotifySessionManager.logged_out() can run, so maybe this will cause some issues when syncing the cache and offline playlist support (#424)? Waiting for the session.connected event to be unset (and not using daemon threads?) would seem like a fix but I don't have a clue of the wider implications of this.

Anyway, I then tried returning before uri = str(Link.from_playlist(spotify_playlist)) in translator.to_mopidy_playlist() if the playlist is not loaded; this obviously stops the exception. But I saw that playlist_state_changed() was never called for my newly added playlist (it was for every other playlist) and even after waiting and running refresh_playlists() multiple times, my newly added playlist was never loaded.

@jodal

This comment has been minimized.

Member

jodal commented Apr 28, 2013

AFAIK, Spotify had problems with their playlists service around the time you experienced the ChannelError messages.

I think just adding a try-except around the playlist link creation will fix this. I now see the following series of events when I have 96 playlists and add a new playlist:

DEBUG    2013-04-28 09:56:31,845 [1202:SpotifyThread] mopidy.backends.spotify
  Callback called: playlist added at position 0
DEBUG    2013-04-28 09:56:31,845 [1202:SpotifyThread] mopidy.backends.spotify
  Callback called: playlist container loaded
DEBUG    2013-04-28 09:56:31,846 [1202:SpotifyThread] mopidy.backends.spotify
  Spotify playlist translation error: Failed to get link from a playlist
INFO     2013-04-28 09:56:31,908 [1202:SpotifyThread] mopidy.backends.spotify
  Loaded 96 Spotify playlists
DEBUG    2013-04-28 09:56:31,915 [1202:SpotifyThread] mopidy.backends.spotify
  Watching 96 playlist(s) for changes
DEBUG    2013-04-28 09:56:32,236 [1202:SpotifyThread] mopidy.backends.spotify
  Callback called: 0 track(s) added to position 0 in playlist "Foo 3"
INFO     2013-04-28 09:56:32,286 [1202:SpotifyThread] mopidy.backends.spotify
  Loaded 97 Spotify playlists

With words: 80ms after the container_loaded callback (that used to fail), which now just ignores the new playlist, there is a tracks_added event from libspotify for the playlist, which now is properly loaded, and thus refresh_playlists() succeeds at translating the new Spotify playlist to a Mopidy playlist.

@jodal jodal closed this in 44cf8a0 Apr 28, 2013

jodal added a commit that referenced this issue Apr 28, 2013

@kingosticks

This comment has been minimized.

Member

kingosticks commented Apr 28, 2013

Great, thanks. I'll give this a go when I'm back later. How do you find out when the spotify service is having problems? I was looking on Twitter for an announcement but there wasn't anything.

@kingosticks

This comment has been minimized.

Member

kingosticks commented Apr 28, 2013

Also, do you have an opinion on the session logout callback I mentioned? Or happy to leave that as is?

@jodal

This comment has been minimized.

Member

jodal commented Apr 28, 2013

There was some talk about it on the #spotify IRC channel on freenode.
On Apr 28, 2013 10:19 AM, "Nick Steel" notifications@github.com wrote:

Great, thanks. I'll give this a go when I'm back later. How do you find
out when the spotify service is having problems? I was looking on Twitter
for an announcement but there wasn't anything.


Reply to this email directly or view it on GitHubhttps://github.com//issues/387#issuecomment-17130506
.

@jodal

This comment has been minimized.

Member

jodal commented Apr 28, 2013

Could you open a separate bug for it? I want to have a look at it later.
On Apr 28, 2013 10:21 AM, "Nick Steel" notifications@github.com wrote:

Also, do you have an opinion on the session logout callback I mentioned?
Or happy to leave that as is?


Reply to this email directly or view it on GitHubhttps://github.com//issues/387#issuecomment-17130525
.

@kingosticks

This comment has been minimized.

Member

kingosticks commented Apr 28, 2013

Sure, will do tonight. Thanks again.

@kingosticks

This comment has been minimized.

Member

kingosticks commented Apr 28, 2013

Yep, working fine here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment