mopidy / mopidy-spotify

Mopidy extension for playing music from Spotify
https://mopidy.com/ext/spotify/
Apache License 2.0
933 stars 109 forks source link

Playlist no longer working #215

Closed TCke83 closed 4 years ago

TCke83 commented 5 years ago

Since a few day's i'm unable to load contents of playlist using mopidy with the mopidy-spotify plugin. It shows following error in the logs:

Mar  3 18:19:41 mopidy rc.local[1021]: ERROR    SpotifyBackend backend caused an exception.
Mar  3 18:19:41 mopidy rc.local[1021]: Traceback (most recent call last):
Mar  3 18:19:41 mopidy rc.local[1021]:   File "/usr/lib/python2.7/dist-packages/mopidy/core/playlists.py", line 18, in _backend_error_handling
Mar  3 18:19:41 mopidy rc.local[1021]:     yield
Mar  3 18:19:41 mopidy rc.local[1021]:   File "/usr/lib/python2.7/dist-packages/mopidy/core/playlists.py", line 248, in lookup
Mar  3 18:19:41 mopidy rc.local[1021]:     playlist = backend.playlists.lookup(uri).get()
Mar  3 18:19:41 mopidy rc.local[1021]:   File "/usr/lib/python2.7/dist-packages/pykka/threading.py", line 52, in get
Mar  3 18:19:41 mopidy rc.local[1021]:     compat.reraise(*self._data['exc_info'])
Mar  3 18:19:41 mopidy rc.local[1021]:   File "/usr/lib/python2.7/dist-packages/pykka/compat.py", line 12, in reraise
Mar  3 18:19:41 mopidy rc.local[1021]:     exec('raise tp, value, tb')
Mar  3 18:19:41 mopidy rc.local[1021]:   File "/usr/lib/python2.7/dist-packages/pykka/actor.py", line 201, in _actor_loop
Mar  3 18:19:41 mopidy rc.local[1021]:     response = self._handle_receive(message)
Mar  3 18:19:41 mopidy rc.local[1021]:   File "/usr/lib/python2.7/dist-packages/pykka/actor.py", line 295, in _handle_receive
Mar  3 18:19:41 mopidy rc.local[1021]:     return callee(*message['args'], **message['kwargs'])
Mar  3 18:19:41 mopidy rc.local[1021]:   File "/usr/local/lib/python2.7/dist-packages/Mopidy_Spotify-3.1.0-py2.7.egg/mopidy_spotify/playlists.py", line 124, in lookup
Mar  3 18:19:41 mopidy rc.local[1021]:     return self._get_playlist(uri)
Mar  3 18:19:41 mopidy rc.local[1021]:   File "/usr/local/lib/python2.7/dist-packages/Mopidy_Spotify-3.1.0-py2.7.egg/mopidy_spotify/playlists.py", line 137, in _get_playlist
Mar  3 18:19:41 mopidy rc.local[1021]:     link = translator.parse_uri(uri)
Mar  3 18:19:41 mopidy rc.local[1021]:   File "/usr/local/lib/python2.7/dist-packages/Mopidy_Spotify-3.1.0-py2.7.egg/mopidy_spotify/translator.py", line 355, in parse_uri
Mar  3 18:19:41 mopidy rc.local[1021]:     raise ValueError('Could not parse %r as a Spotify URI' % uri)
**Mar  3 18:19:41 mopidy rc.local[1021]: ValueError: Could not parse 'spotify:playlist:63Phh7U3VFWdZYvjQt8zyv' as a Spotify URI**

I've found a similar thread but there is stated the spotify playlist URI is incorrect without a username, but the playlists urls are the ones i use also in my spotify app (url is retrieved when logged in to spotify). Anyone any suggestions how to solve this issues, both mopidy & mopidy-spotify are the most recent stable versions.

Any suggestions how to fix this?

Thans in advance.

Regards,

Tom

L422Y commented 5 years ago

running into this as well as of yesterday. it looks as though the username has been removed from the URIs. I added a line in translator.py ~line 355 forcing a username and it's working for now at least.

  elif len(parts) == 2 and parts[0] in ('playlist'):
        return _result(uri, parts[0],  parts[1], "username")
Stybyk commented 5 years ago

Hi, can you specify with translator.py file did you modified? mopidy-spotify/mopidy_spotify/translator.py here is only 263 lines

Files found via: sudo find / -name "translator.py" are not so long with 355 lines

If you really solved the issue. Is possible to add it to pip install release?

L422Y commented 5 years ago

@Stybyk ah, i'm using an older version. 3.1.0 /usr/local/lib/python2.7/dist-packages/Mopidy_Spotify-3.1.0-py2.7.egg/mopidy_spotify/translator.py

def parse_uri(uri):
    parsed_uri = urlparse.urlparse(uri)

    schemes = ('http', 'https')
    netlocs = ('open.spotify.com', 'play.spotify.com')

    if parsed_uri.scheme == 'spotify':
        parts = parsed_uri.path.split(':')
    elif parsed_uri.scheme in schemes and parsed_uri.netloc in netlocs:
        parts = parsed_uri.path[1:].split('/')
    else:
        parts = []

    # Strip out empty parts to ensure we are strict about URI parsing.
    parts = [p for p in parts if p.strip()]

    if len(parts) == 2 and parts[0] in ('track', 'album', 'artist'):
        return _result(uri, parts[0],  parts[1], None)
    elif len(parts) == 2 and parts[0] in ('playlist'):
        return _result(uri, parts[0],  parts[1], "***USERNAME***")
    elif len(parts) == 3 and parts[0] == 'user' and parts[2] == 'starred':
        if parsed_uri.scheme == 'spotify':
            return _result(uri, 'starred',  None, parts[1])
    elif len(parts) == 3 and parts[0] == 'playlist':
        return _result(uri, 'playlist',  parts[2], parts[1])
    elif len(parts) == 4 and parts[0] == 'user' and parts[2] == 'playlist':
        return _result(uri, 'playlist',  parts[3], parts[1])

    raise ValueError('Could not parse %r as a Spotify URI' % uri)
TCke83 commented 5 years ago

@Stybyk ah, i'm using an older version. 3.1.0 /usr/local/lib/python2.7/dist-packages/Mopidy_Spotify-3.1.0-py2.7.egg/mopidy_spotify/translator.py

def parse_uri(uri):
    parsed_uri = urlparse.urlparse(uri)

    schemes = ('http', 'https')
    netlocs = ('open.spotify.com', 'play.spotify.com')

    if parsed_uri.scheme == 'spotify':
        parts = parsed_uri.path.split(':')
    elif parsed_uri.scheme in schemes and parsed_uri.netloc in netlocs:
        parts = parsed_uri.path[1:].split('/')
    else:
        parts = []

    # Strip out empty parts to ensure we are strict about URI parsing.
    parts = [p for p in parts if p.strip()]

    if len(parts) == 2 and parts[0] in ('track', 'album', 'artist'):
        return _result(uri, parts[0],  parts[1], None)
    elif len(parts) == 2 and parts[0] in ('playlist'):
        return _result(uri, parts[0],  parts[1], "***USERNAME***")
    elif len(parts) == 3 and parts[0] == 'user' and parts[2] == 'starred':
        if parsed_uri.scheme == 'spotify':
            return _result(uri, 'starred',  None, parts[1])
    elif len(parts) == 3 and parts[0] == 'playlist':
        return _result(uri, 'playlist',  parts[2], parts[1])
    elif len(parts) == 4 and parts[0] == 'user' and parts[2] == 'playlist':
        return _result(uri, 'playlist',  parts[3], parts[1])

    raise ValueError('Could not parse %r as a Spotify URI' % uri)

If I add those two lines it failes when i try to load the playlist, so this doesn't really look like a fix

L422Y commented 5 years ago

did you replace ***USERNAME*** with your spotify username? it's just a bandaid, that's what helped for me.

TCke83 commented 5 years ago

did you replace ***USERNAME*** with your spotify username? it's just a bandaid, that's what helped for me.

Yes i did, i've printed the link return value for the translator call:

Link(uri='spotify:playlist:1MpVIj7sqfgmd078BreKKP', type=u'playlist', id=u'1MpVIj7sqfgmd078BreKKP', owner=u'tcke83')

Shouldn't the username be present in de uri also?

L422Y commented 5 years ago

That's what we are compensating for – the API seems to not be including it any longer. If you're returning from the call successfully, you're having a different issue. Mine was explicitly the lack of the username in the URI

TCke83 commented 5 years ago

Failed to lookup "spotify:playlist:2UNm9TY5FiohSFenZHXFyu": Failed to get link from Spotify URI: u'spotify:playlist:2UNm9TY5FiohSFenZHXFyu'

is the error that i get when i select the playlist for playback, the username is not in the uri (as you can see in the Link from previous comment)

L422Y commented 5 years ago

That is a different error than Mar 3 18:19:41 mopidy rc.local[1021]: ValueError: Could not parse 'spotify:playlist:63Phh7U3VFWdZYvjQt8zyv' as a Spotify URI so you've progressed past the initial error you posted. It's likely the other playlist issue from a while back, I also had that but applied a fix from another thread.

Worth looking here: https://github.com/mopidy/mopidy-spotify/issues/182