Skip to content
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

Mopidy as a streaming target #418

Closed
koying opened this issue Jun 18, 2022 · 10 comments
Closed

Mopidy as a streaming target #418

koying opened this issue Jun 18, 2022 · 10 comments
Labels
bug Something isn't working
Milestone

Comments

@koying
Copy link

koying commented Jun 18, 2022

I know mopidy is not a supported target, but I'd like to understand what could be the issue, here.
To be clear, this is about streaming to mopidy, not supporting the library side.

The key error on mopidy seems to be

ERROR    2022-06-18 14:09:26,433 [1:Core-10] mopidy.core.playback
  StreamBackend backend caused an exception.
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/urllib3/response.py", line 697, in _update_chunk_length
    self.chunk_left = int(line, 16)
ValueError: invalid literal for int() with base 16: b''

Is MASS using a special protocol that has to be understood by mopidy?

Full HA log

2022-06-18 14:09:25 INFO (MainThread) [music_assistant.players.stream] Start Streaming queue track: database://track/1520 (Agnes Obel - The Curse) for queue Mopidy Uranus
2022-06-18 14:09:26 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.9/site-packages/music_assistant/controllers/streams.py", line 167, in serve_queue_stream
    await queue_stream.subscribe(client_id, resp.write)
  File "/usr/local/lib/python3.9/site-packages/music_assistant/controllers/streams.py", line 317, in subscribe
    assert not self.done.is_set(), "Stream task is already finished"
AssertionError: Stream task is already finished
2022-06-18 14:09:26 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.9/site-packages/music_assistant/controllers/streams.py", line 167, in serve_queue_stream
    await queue_stream.subscribe(client_id, resp.write)
  File "/usr/local/lib/python3.9/site-packages/music_assistant/controllers/streams.py", line 317, in subscribe
    assert not self.done.is_set(), "Stream task is already finished"
AssertionError: Stream task is already finished
2022-06-18 14:09:27 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.9/site-packages/music_assistant/controllers/streams.py", line 167, in serve_queue_stream
    await queue_stream.subscribe(client_id, resp.write)
  File "/usr/local/lib/python3.9/site-packages/music_assistant/controllers/streams.py", line 317, in subscribe
    assert not self.done.is_set(), "Stream task is already finished"
AssertionError: Stream task is already finished
2022-06-18 14:09:27 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.9/site-packages/music_assistant/controllers/streams.py", line 167, in serve_queue_stream
    await queue_stream.subscribe(client_id, resp.write)
  File "/usr/local/lib/python3.9/site-packages/music_assistant/controllers/streams.py", line 317, in subscribe
    assert not self.done.is_set(), "Stream task is already finished"
AssertionError: Stream task is already finished
2022-06-18 14:09:27 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.9/site-packages/music_assistant/controllers/streams.py", line 167, in serve_queue_stream
    await queue_stream.subscribe(client_id, resp.write)
  File "/usr/local/lib/python3.9/site-packages/music_assistant/controllers/streams.py", line 317, in subscribe
    assert not self.done.is_set(), "Stream task is already finished"
AssertionError: Stream task is already finished
2022-06-18 14:09:27 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.9/site-packages/music_assistant/controllers/streams.py", line 167, in serve_queue_stream
    await queue_stream.subscribe(client_id, resp.write)
  File "/usr/local/lib/python3.9/site-packages/music_assistant/controllers/streams.py", line 317, in subscribe
    assert not self.done.is_set(), "Stream task is already finished"
AssertionError: Stream task is already finished

Full mopidy log

ERROR    2022-06-18 14:09:26,433 [1:Core-10] mopidy.core.playback
  StreamBackend backend caused an exception.
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/urllib3/response.py", line 697, in _update_chunk_length
    self.chunk_left = int(line, 16)
ValueError: invalid literal for int() with base 16: b''

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/urllib3/response.py", line 438, in _error_catcher
    yield
  File "/usr/local/lib/python3.8/dist-packages/urllib3/response.py", line 764, in read_chunked
    self._update_chunk_length()
  File "/usr/local/lib/python3.8/dist-packages/urllib3/response.py", line 701, in _update_chunk_length
    raise InvalidChunkLength(self, line)
urllib3.exceptions.InvalidChunkLength: InvalidChunkLength(got length b'', 0 bytes read)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/requests/models.py", line 750, in generate
    for chunk in self.raw.stream(chunk_size, decode_content=True):
  File "/usr/local/lib/python3.8/dist-packages/urllib3/response.py", line 572, in stream
    for line in self.read_chunked(amt, decode_content=decode_content):
  File "/usr/local/lib/python3.8/dist-packages/urllib3/response.py", line 793, in read_chunked
    self._original_response.close()
  File "/usr/lib/python3.8/contextlib.py", line 131, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/local/lib/python3.8/dist-packages/urllib3/response.py", line 455, in _error_catcher
    raise ProtocolError("Connection broken: %r" % e, e)
urllib3.exceptions.ProtocolError: ("Connection broken: InvalidChunkLength(got length b'', 0 bytes read)", InvalidChunkLength(got length b'', 0 bytes read))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/mopidy/core/playback.py", line 350, in _change
    if not backend.playback.change_track(pending_tl_track.track).get():
  File "/usr/lib/python3/dist-packages/pykka/_threading.py", line 45, in get
    _compat.reraise(*self._data['exc_info'])
  File "/usr/lib/python3/dist-packages/pykka/_compat/__init__.py", line 29, in reraise
    raise value
  File "/usr/lib/python3/dist-packages/pykka/_actor.py", line 193, in _actor_loop
    response = self._handle_receive(envelope.message)
  File "/usr/lib/python3/dist-packages/pykka/_actor.py", line 299, in _handle_receive
    return callee(*message.args, **message.kwargs)
  File "/usr/lib/python3/dist-packages/mopidy/backend.py", line 313, in change_track
    uri = self.translate_uri(track.uri)
  File "/usr/lib/python3/dist-packages/mopidy/stream/actor.py", line 93, in translate_uri
    unwrapped_uri, _ = _unwrap_stream(
  File "/usr/lib/python3/dist-packages/mopidy/stream/actor.py", line 163, in _unwrap_stream
    content = http.download(
  File "/usr/lib/python3/dist-packages/mopidy/internal/http.py", line 42, in download
    for chunk in response.iter_content(chunk_size):
  File "/usr/lib/python3/dist-packages/requests/models.py", line 753, in generate
    raise ChunkedEncodingError(e)
requests.exceptions.ChunkedEncodingError: ("Connection broken: InvalidChunkLength(got length b'', 0 bytes read)", InvalidChunkLength(got length b'', 0 bytes read))
WARNING  2022-06-18 14:09:26,454 [1:Core-10] mopidy.core.tracklist
  Track is not playable: http://192.168.3.252:8095/374d38f3a092465897d9da4b945b6ca1.flac
ERROR    2022-06-18 14:09:27,422 [1:Core-10] mopidy.core.library
  StreamBackend backend caused an exception.
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/urllib3/response.py", line 697, in _update_chunk_length
    self.chunk_left = int(line, 16)
ValueError: invalid literal for int() with base 16: b''

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/urllib3/response.py", line 438, in _error_catcher
    yield
  File "/usr/local/lib/python3.8/dist-packages/urllib3/response.py", line 764, in read_chunked
    self._update_chunk_length()
  File "/usr/local/lib/python3.8/dist-packages/urllib3/response.py", line 701, in _update_chunk_length
    raise InvalidChunkLength(self, line)
urllib3.exceptions.InvalidChunkLength: InvalidChunkLength(got length b'', 0 bytes read)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/requests/models.py", line 750, in generate
    for chunk in self.raw.stream(chunk_size, decode_content=True):
  File "/usr/local/lib/python3.8/dist-packages/urllib3/response.py", line 572, in stream
    for line in self.read_chunked(amt, decode_content=decode_content):
  File "/usr/local/lib/python3.8/dist-packages/urllib3/response.py", line 793, in read_chunked
    self._original_response.close()
  File "/usr/lib/python3.8/contextlib.py", line 131, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/local/lib/python3.8/dist-packages/urllib3/response.py", line 455, in _error_catcher
    raise ProtocolError("Connection broken: %r" % e, e)
urllib3.exceptions.ProtocolError: ("Connection broken: InvalidChunkLength(got length b'', 0 bytes read)", InvalidChunkLength(got length b'', 0 bytes read))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/mopidy/core/library.py", line 17, in _backend_error_handling
    yield
  File "/usr/lib/python3/dist-packages/mopidy/core/library.py", line 217, in lookup
    result = future.get()
  File "/usr/lib/python3/dist-packages/pykka/_threading.py", line 45, in get
    _compat.reraise(*self._data['exc_info'])
  File "/usr/lib/python3/dist-packages/pykka/_compat/__init__.py", line 29, in reraise
    raise value
  File "/usr/lib/python3/dist-packages/pykka/_actor.py", line 193, in _actor_loop
    response = self._handle_receive(envelope.message)
  File "/usr/lib/python3/dist-packages/pykka/_actor.py", line 299, in _handle_receive
    return callee(*message.args, **message.kwargs)
  File "/usr/lib/python3/dist-packages/mopidy/stream/actor.py", line 66, in lookup
    _, scan_result = _unwrap_stream(
  File "/usr/lib/python3/dist-packages/mopidy/stream/actor.py", line 163, in _unwrap_stream
    content = http.download(
  File "/usr/lib/python3/dist-packages/mopidy/internal/http.py", line 42, in download
    for chunk in response.iter_content(chunk_size):
  File "/usr/lib/python3/dist-packages/requests/models.py", line 753, in generate
    raise ChunkedEncodingError(e)
requests.exceptions.ChunkedEncodingError: ("Connection broken: InvalidChunkLength(got length b'', 0 bytes read)", InvalidChunkLength(got length b'', 0 bytes read))
ERROR    2022-06-18 14:09:27,554 [1:Core-10] mopidy.core.library
  StreamBackend backend caused an exception.
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/urllib3/response.py", line 697, in _update_chunk_length
    self.chunk_left = int(line, 16)
ValueError: invalid literal for int() with base 16: b''

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/urllib3/response.py", line 438, in _error_catcher
    yield
  File "/usr/local/lib/python3.8/dist-packages/urllib3/response.py", line 764, in read_chunked
    self._update_chunk_length()
  File "/usr/local/lib/python3.8/dist-packages/urllib3/response.py", line 701, in _update_chunk_length
    raise InvalidChunkLength(self, line)
urllib3.exceptions.InvalidChunkLength: InvalidChunkLength(got length b'', 0 bytes read)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/requests/models.py", line 750, in generate
    for chunk in self.raw.stream(chunk_size, decode_content=True):
  File "/usr/local/lib/python3.8/dist-packages/urllib3/response.py", line 572, in stream
    for line in self.read_chunked(amt, decode_content=decode_content):
  File "/usr/local/lib/python3.8/dist-packages/urllib3/response.py", line 793, in read_chunked
    self._original_response.close()
  File "/usr/lib/python3.8/contextlib.py", line 131, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/local/lib/python3.8/dist-packages/urllib3/response.py", line 455, in _error_catcher
    raise ProtocolError("Connection broken: %r" % e, e)
urllib3.exceptions.ProtocolError: ("Connection broken: InvalidChunkLength(got length b'', 0 bytes read)", InvalidChunkLength(got length b'', 0 bytes read))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/mopidy/core/library.py", line 17, in _backend_error_handling
    yield
  File "/usr/lib/python3/dist-packages/mopidy/core/library.py", line 217, in lookup
    result = future.get()
  File "/usr/lib/python3/dist-packages/pykka/_threading.py", line 45, in get
    _compat.reraise(*self._data['exc_info'])
  File "/usr/lib/python3/dist-packages/pykka/_compat/__init__.py", line 29, in reraise
    raise value
  File "/usr/lib/python3/dist-packages/pykka/_actor.py", line 193, in _actor_loop
    response = self._handle_receive(envelope.message)
  File "/usr/lib/python3/dist-packages/pykka/_actor.py", line 299, in _handle_receive
    return callee(*message.args, **message.kwargs)
  File "/usr/lib/python3/dist-packages/mopidy/stream/actor.py", line 66, in lookup
    _, scan_result = _unwrap_stream(
  File "/usr/lib/python3/dist-packages/mopidy/stream/actor.py", line 163, in _unwrap_stream
    content = http.download(
  File "/usr/lib/python3/dist-packages/mopidy/internal/http.py", line 42, in download
    for chunk in response.iter_content(chunk_size):
  File "/usr/lib/python3/dist-packages/requests/models.py", line 753, in generate
    raise ChunkedEncodingError(e)
requests.exceptions.ChunkedEncodingError: ("Connection broken: InvalidChunkLength(got length b'', 0 bytes read)", InvalidChunkLength(got length b'', 0 bytes read))
@marcelveldt
Copy link
Member

I think this is the same issue as the one with OSMC... I didn't account for the player doing a HEAD request before the GET.
Just fixed that today so please test again in next patch release it might be fixed.

@erkr erkr added the bug Something isn't working label Jun 18, 2022
@koying
Copy link
Author

koying commented Jun 18, 2022

Yeah, I saw the OSMC issue but was not sure it was actually the same issue. Will test the forthcoming point release.

@marcelveldt marcelveldt added this to the 2022.6.2 milestone Jun 18, 2022
@koying
Copy link
Author

koying commented Jun 18, 2022

Unfortunately, 2022.6.2 doesn't fix it. Same errors.

@marcelveldt
Copy link
Member

OK, too bad. In that case it needs more work to investigate. Perhaps it connects once to determine the stream details and connects again after that. The stream backend in MA sees that as a disconnected client and closes the stream task. I saw the same with DLNA clients but once I send some special headers they did no longer connect twice.

@marcelveldt
Copy link
Member

marcelveldt commented Jun 18, 2022

https://github.com/music-assistant/music-assistant-lib/blob/master/music_assistant/controllers/streams.py#L318

It hits that line so the client must have been connecting twice somehow

@parameter-pollution
Copy link

I just got it to work. There is a way to tell mopidy to not do stream metadata lookups!

https://docs.mopidy.com/en/latest/ext/stream/#confval-stream-metadata_blacklist

Here an example from my mopidy.conf :

[stream]
enabled = true
protocols =
    http
    https
    mms
    rtmp
    rtmps
    rtsp
timeout = 5000
metadata_blacklist = http://HA_IP_HERE:8095/*

@koying
Copy link
Author

koying commented Jun 18, 2022

Exactly just came to the same conclusion :)

I used

metadata_blacklist = http://*:8095/*

@koying koying closed this as completed Jun 18, 2022
@marcelveldt
Copy link
Member

I think it would be nice to provide this info in a small article in the FAQ section:

https://github.com/music-assistant/hass-music-assistant/discussions/categories/q-a-faq

@koying
Copy link
Author

koying commented Jun 18, 2022

Done: #439

@Sjorsa
Copy link

Sjorsa commented Dec 4, 2024

I have added the metadate_blacklist, but where do I add my Mopidy player to MA? I don't see it as one of the player providers.

Edit:
2 minutes after making this comment I figured out I needed to add it via HA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants