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

get_images raises ValueError when parsing uri "spotify:directory" #301

Closed kingosticks closed 1 month ago

kingosticks commented 3 years ago

Iris causes this straight away when you go to browse.

HttpServer DEBUG    2021-02-10 00:05:40,784 Received WebSocket message from 127.0.0.1: '{"method":"core.library.get_images","params":{"uris":["file:root","local:directory","orfradio:","soundcloud:directory","spotify:directory","tunein:root"]},"jsonrpc":"2.0","id":13}'
Core-14 ERROR    2021-02-10 00:05:40,789 SpotifyBackend backend caused an exception.
Traceback (most recent call last):
  File "/home/nick/Dev/mopidy-dev/mopidy/mopidy/core/library.py", line 17, in _backend_error_handling
    yield
  File "/home/nick/Dev/mopidy-dev/mopidy/mopidy/core/library.py", line 181, in get_images
    if future.get() is None:
  File "/home/nick/.virtualenvs/mopidy3/lib/python3.8/site-packages/pykka/_threading.py", line 45, in get
    _compat.reraise(*self._data['exc_info'])
  File "/home/nick/.virtualenvs/mopidy3/lib/python3.8/site-packages/pykka/_compat/__init__.py", line 29, in reraise
    raise value
  File "/home/nick/.virtualenvs/mopidy3/lib/python3.8/site-packages/pykka/_actor.py", line 193, in _actor_loop
    response = self._handle_receive(envelope.message)
  File "/home/nick/.virtualenvs/mopidy3/lib/python3.8/site-packages/pykka/_actor.py", line 299, in _handle_receive
    return callee(*message.args, **message.kwargs)
  File "/home/nick/Dev/mopidy-dev/mopidy-spotify/mopidy_spotify/library.py", line 35, in get_images
    return images.get_images(self._backend._web_client, uris)
  File "/home/nick/Dev/mopidy-dev/mopidy-spotify/mopidy_spotify/images.py", line 23, in get_images
    uris = sorted((_parse_uri(u) for u in uris), key=uri_type_getter)
  File "/home/nick/Dev/mopidy-dev/mopidy-spotify/mopidy_spotify/images.py", line 23, in <genexpr>
    uris = sorted((_parse_uri(u) for u in uris), key=uri_type_getter)
  File "/home/nick/Dev/mopidy-dev/mopidy-spotify/mopidy_spotify/images.py", line 45, in _parse_uri
    uri_type, uri_id = parsed_uri.path.split(":")[:2]
ValueError: not enough values to unpack (expected 2, got 1)

And similarly:

HttpServer DEBUG    2021-02-10 00:12:54,304 Received WebSocket message from 127.0.0.1: '{"method":"core.library.get_images","params":{"uris":["spotify:playlists:featured"]},"jsonrpc":"2.0","id":19}'
Core-14 ERROR    2021-02-10 00:12:54,306 SpotifyBackend backend caused an exception.
Traceback (most recent call last):
  File "/home/nick/Dev/mopidy-dev/mopidy/mopidy/core/library.py", line 17, in _backend_error_handling
    yield
  File "/home/nick/Dev/mopidy-dev/mopidy/mopidy/core/library.py", line 181, in get_images
    if future.get() is None:
  File "/home/nick/.virtualenvs/mopidy3/lib/python3.8/site-packages/pykka/_threading.py", line 45, in get
    _compat.reraise(*self._data['exc_info'])
  File "/home/nick/.virtualenvs/mopidy3/lib/python3.8/site-packages/pykka/_compat/__init__.py", line 29, in reraise
    raise value
  File "/home/nick/.virtualenvs/mopidy3/lib/python3.8/site-packages/pykka/_actor.py", line 193, in _actor_loop
    response = self._handle_receive(envelope.message)
  File "/home/nick/.virtualenvs/mopidy3/lib/python3.8/site-packages/pykka/_actor.py", line 299, in _handle_receive
    return callee(*message.args, **message.kwargs)
  File "/home/nick/Dev/mopidy-dev/mopidy-spotify/mopidy_spotify/library.py", line 35, in get_images
    return images.get_images(self._backend._web_client, uris)
  File "/home/nick/Dev/mopidy-dev/mopidy-spotify/mopidy_spotify/images.py", line 23, in get_images
    uris = sorted((_parse_uri(u) for u in uris), key=uri_type_getter)
  File "/home/nick/Dev/mopidy-dev/mopidy-spotify/mopidy_spotify/images.py", line 23, in <genexpr>
    uris = sorted((_parse_uri(u) for u in uris), key=uri_type_getter)
  File "/home/nick/Dev/mopidy-dev/mopidy-spotify/mopidy_spotify/images.py", line 59, in _parse_uri
    raise ValueError(f"Could not parse {repr(uri)} as a Spotify URI")
ValueError: Could not parse 'spotify:playlists:featured' as a Spotify URI
tatealive commented 3 years ago

I am getting the same issue:

mopidy[661]:   File "/usr/lib/python3/dist-packages/mopidy_spotify/library.py", line 35, in get_images
mopidy[661]:     return images.get_images(self._backend._web_client, uris)
mopidy[661]:   File "/usr/lib/python3/dist-packages/mopidy_spotify/images.py", line 23, in get_images
mopidy[661]:     uris = sorted((_parse_uri(u) for u in uris), key=uri_type_getter)
mopidy[661]:   File "/usr/lib/python3/dist-packages/mopidy_spotify/images.py", line 23, in <genexpr>
mopidy[661]:     uris = sorted((_parse_uri(u) for u in uris), key=uri_type_getter)
mopidy[661]:   File "/usr/lib/python3/dist-packages/mopidy_spotify/images.py", line 45, in _parse_uri
mopidy[661]:     uri_type, uri_id = parsed_uri.path.split(":")[:2]
mopidy[661]: ValueError: not enough values to unpack (expected 2, got 1)
kingosticks commented 3 years ago

If someone wants to fix this, they can just handle the exception and return an empty response. We don't need to support returning images for arbitrary browse directories, I think this is a weird thing for a client to request.

djmattyg007 commented 3 years ago

It could be analogous to album art?

kingosticks commented 3 years ago

I'm talking about virtual directories like the ones in the examples I provided above. What would we return for spotify:featured:playlists, for example?

djmattyg007 commented 3 years ago

Right, that doesn’t make sense.

kingosticks commented 1 month ago

Fixed some time ago at https://github.com/mopidy/mopidy-spotify/blob/main/src/mopidy_spotify/images.py#L46-L47