home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.69k stars 30.44k forks source link

Invalid Media ID on MPD #69601

Closed brunoccr closed 2 years ago

brunoccr commented 2 years ago

The problem

On pass music name as media_id occurr error

What version of Home Assistant Core has the issue?

core-2022.4.0

What was the last working version of Home Assistant Core?

core-2022.3.8

What type of installation are you running?

Home Assistant OS

Integration causing the issue

No response

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

service: media_player.play_media
data:
  media_content_type: music
  media_content_id: 'music_name.mp3'
target:
  entity_id: media_player.device_mpd

Anything in the logs that might be useful for us?

2022-04-07 12:01:11 ERROR (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Error executing script. Unexpected error for call_service at pos 1: URL is relative, but does not start with a /
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 379, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 582, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1634, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1671, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
    await service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 677, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 955, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 714, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/mpd/media_player.py", line 479, in async_play_media
    media_id = async_process_play_media_url(self.hass, media_id)
  File "/usr/src/homeassistant/homeassistant/components/media_player/browse_media.py", line 40, in async_process_play_media_url
    raise ValueError("URL is relative, but does not start with a /")
ValueError: URL is relative, but does not start with a /

Additional information

image

I believe this line is incorrect.

probot-home-assistant[bot] commented 2 years ago

mpd documentation mpd source (message by IssueLinks)

probot-home-assistant[bot] commented 2 years ago

Hey there @fabaff, mind taking a look at this issue as it has been labeled with an integration (mpd) you are listed as a code owner for? Thanks! (message by CodeOwnersMention)

RichJeanes commented 2 years ago

I am also having this issue when calling the media_player.play_media service on an MPD device via Node-RED with a file URI: image Error output: image

jaminh commented 2 years ago

This issue appears to be affecting me as well.

2022-04-07 18:46:20 ERROR (MainThread) [homeassistant.components.automation.wind_down_music] Wind Down Music: Error executing script. Unexpected error for call_service at pos 1: URL is relative, but does not start with a /
Traceback (most recent call last):
  File "/srv/homeassistant/lib64/python3.9/site-packages/homeassistant/helpers/script.py", line 379, in _async_step
    await getattr(self, handler)()
  File "/srv/homeassistant/lib64/python3.9/site-packages/homeassistant/helpers/script.py", line 582, in _async_call_service_step
    await service_task
  File "/srv/homeassistant/lib64/python3.9/site-packages/homeassistant/core.py", line 1634, in async_call
    task.result()
  File "/srv/homeassistant/lib64/python3.9/site-packages/homeassistant/core.py", line 1671, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/srv/homeassistant/lib64/python3.9/site-packages/homeassistant/helpers/entity_component.py", line 204, in handle_service
    await service.entity_service_call(
  File "/srv/homeassistant/lib64/python3.9/site-packages/homeassistant/helpers/service.py", line 677, in entity_service_call
    future.result()  # pop exception if have
  File "/srv/homeassistant/lib64/python3.9/site-packages/homeassistant/helpers/entity.py", line 955, in async_request_call
    await coro
  File "/srv/homeassistant/lib64/python3.9/site-packages/homeassistant/helpers/service.py", line 714, in _handle_entity_call
    await result
  File "/srv/homeassistant/lib64/python3.9/site-packages/homeassistant/components/mpd/media_player.py", line 479, in async_play_media
    media_id = async_process_play_media_url(self.hass, media_id)
  File "/srv/homeassistant/lib64/python3.9/site-packages/homeassistant/components/media_player/browse_media.py", line 40, in async_process_play_media_url
    raise ValueError("URL is relative, but does not start with a /")

Relevant automation:

  - alias: Wind Down Music
    initial_state: True
    trigger:
      platform: event
      event_type: MY_WIND_DOWN
    action:
      - service: media_player.play_media
        data:
          entity_id: media_player.mainmusic
          media_content_type: music
          media_content_id: >
            {{ [
              "local:track:Mixes/Sleep/Classical%20music%20for%20babies%20-%20Toddler%20bedtime.mp3",
              "local:track:Mixes/Sleep/Relaxing%20Music%20For%20Children%20-%20Be%20Calm%20and%20Focused%20%28cute%20animals%29.mp3"
            ] | random }}
GarckaMan commented 2 years ago

Same issue for me: URL is relative, but does not start with a /

I was sending my MPD instance the command play_media for a spotify with the format spotify:playlist:XXXXXXXXX

jaminh commented 2 years ago

I think part of the issue is when calling the play_media service with a "local" url there isn't a way to specify whether it means local to your HA instance or local to the media player. I got around the issue by modifying the condition here https://github.com/home-assistant/core/blob/689b347904857c77c1346f3f1e971f2dc31d49ca/homeassistant/components/media_player/browse_media.py#L35. Basically I just check if the url has a "scheme" and pass through the media ID if it does. I have a feeling that probably won't work for everyone, especially if you use a "file://" url for referring to files on your HA instance. This might be an issue that is specific to MPD since mopidy seems to use some kind of weird URLs for media IDs, so maybe it would make more sense to put change the logic in just the MPD component?

MatthewFlamm commented 2 years ago

67565 caused this.

I am using mopidy with MPD. Adding a preceding / allows to service call to execute, but then it does not successfully play the request.