core: Media Extractor integration doesn't play YouTube links

The problem

A previous issue I raised was fixed by @joostlek and that merged change has resolved the issue for Soundcloud links, however, YouTube links are still affected in 2023.8.0b4.

Using this service call:

service: media_extractor.play_media
data:
  entity_id: media_player.office_home
  media_content_id: https://www.youtube.com/watch?v=Nv6F1VVh5D0
  media_content_type: VIDEO

or this

service: media_extractor.play_media
data:
  entity_id: media_player.office_home
  media_content_id: https://www.youtube.com/watch?v=Nv6F1VVh5D0
  media_content_type: video/youtube

Results in the attempt to play the resource failing due to a stall (seemingly in yt-dlp) downloading m3u8 information…

2023-08-01 16:25:48.940 DEBUG (SyncWorker_2) [homeassistant.components.media_extractor] [youtube] Extracting URL: https://www.youtube.com/watch?v=Nv6F1VVh5D0
2023-08-01 16:25:48.940 DEBUG (SyncWorker_2) [homeassistant.components.media_extractor] [youtube] Nv6F1VVh5D0: Downloading webpage
2023-08-01 16:25:49.545 DEBUG (SyncWorker_2) [homeassistant.components.media_extractor] [youtube] Nv6F1VVh5D0: Downloading ios player API JSON
2023-08-01 16:25:49.671 DEBUG (SyncWorker_2) [homeassistant.components.media_extractor] [youtube] Nv6F1VVh5D0: Downloading android player API JSON
2023-08-01 16:25:49.765 DEBUG (SyncWorker_2) [homeassistant.components.media_extractor] [youtube] Nv6F1VVh5D0: Downloading m3u8 information
2023-08-01 16:28:27.131 DEBUG (SyncWorker_4) [homeassistant.components.media_extractor] [youtube] Extracting URL: https://www.youtube.com/watch?v=Nv6F1VVh5D0
2023-08-01 16:28:27.131 DEBUG (SyncWorker_4) [homeassistant.components.media_extractor] [youtube] Nv6F1VVh5D0: Downloading webpage
2023-08-01 16:28:27.658 DEBUG (SyncWorker_4) [homeassistant.components.media_extractor] [youtube] Nv6F1VVh5D0: Downloading ios player API JSON
2023-08-01 16:28:27.796 DEBUG (SyncWorker_4) [homeassistant.components.media_extractor] [youtube] Nv6F1VVh5D0: Downloading android player API JSON
2023-08-01 16:28:27.885 DEBUG (SyncWorker_4) [homeassistant.components.media_extractor] [youtube] Nv6F1VVh5D0: Downloading m3u8 information

I have manually used the yt-dlp binary and provided the same link and that works as expected. I have tried altering my configuration.yaml file to specify a default, as well as leaving it without any specifics around the default_query section but get the same result. In the example below, I have commented out the default_query I tried.

media_extractor:
  #default_query: bestaudio[ext=m4a]/bestaudio[ext=mp3]/bestaudio

What version of Home Assistant Core has the issue?

2023.8.0b4

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

media_extractor

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

service: media_extractor.play_media
data:
  entity_id: media_player.office_home
  media_content_id: https://www.youtube.com/watch?v=Nv6F1VVh5D0
  media_content_type: video/youtube

Anything in the logs that might be useful for us?

2023-08-01 16:25:48.940 DEBUG (SyncWorker_2) [homeassistant.components.media_extractor] [youtube] Extracting URL: https://www.youtube.com/watch?v=Nv6F1VVh5D0
2023-08-01 16:25:48.940 DEBUG (SyncWorker_2) [homeassistant.components.media_extractor] [youtube] Nv6F1VVh5D0: Downloading webpage
2023-08-01 16:25:49.545 DEBUG (SyncWorker_2) [homeassistant.components.media_extractor] [youtube] Nv6F1VVh5D0: Downloading ios player API JSON
2023-08-01 16:25:49.671 DEBUG (SyncWorker_2) [homeassistant.components.media_extractor] [youtube] Nv6F1VVh5D0: Downloading android player API JSON
2023-08-01 16:25:49.765 DEBUG (SyncWorker_2) [homeassistant.components.media_extractor] [youtube] Nv6F1VVh5D0: Downloading m3u8 information
2023-08-01 16:28:27.131 DEBUG (SyncWorker_4) [homeassistant.components.media_extractor] [youtube] Extracting URL: https://www.youtube.com/watch?v=Nv6F1VVh5D0
2023-08-01 16:28:27.131 DEBUG (SyncWorker_4) [homeassistant.components.media_extractor] [youtube] Nv6F1VVh5D0: Downloading webpage
2023-08-01 16:28:27.658 DEBUG (SyncWorker_4) [homeassistant.components.media_extractor] [youtube] Nv6F1VVh5D0: Downloading ios player API JSON
2023-08-01 16:28:27.796 DEBUG (SyncWorker_4) [homeassistant.components.media_extractor] [youtube] Nv6F1VVh5D0: Downloading android player API JSON
2023-08-01 16:28:27.885 DEBUG (SyncWorker_4) [homeassistant.components.media_extractor] [youtube] Nv6F1VVh5D0: Downloading m3u8 information

Additional information

Previous issue link: https://github.com/home-assistant/core/issues/97389

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 25 (12 by maintainers)

Most upvoted comments

Also, when you now debug media_extractor you can view what link it’s sending. Also I am working on a separate service (since we now have service responses) to return the media info in a service call. This way you can do whatever you want with it, download it, stream it, whatever

Adding unit tests to Media extractor is something on my to do list, as its hard to debug every time. I needed some more information but I got that, so I will work on it soon

Thanks for the workaround suggestion. That service works great where there’s a device that can start apps/show video, like a Chromecast with Google TV, Nest Hub or an nVidia SHIELD but unfortunately the devices I want to target are typically audio only devices like Google Chromecast Audio (discontinued by Google), a Nest Audio or a Google Home (just an audio device) and unfortunately that service call does nothing when I target them - basically no different to when I click the cast icon within the YouTube app, I can’t target any of the audio only devices I have. What is interesting though is that I can still target my audio only devices if I press the Cast icon within the YouTube Music app.

My use case for Media Extractor is to just play the audio from YouTube videos (like Above and Beyond Group Therapy) to my Google Chromecast Audio devices which I have plugged in to Receivers and soundbars around my home. The devices are great for just audio listening. Since most of my audio systems do have HDMI inputs, I could technically replace all the Google Chromecast Audio devices with Chromecast with Google TV, but since Media Extractor/youtube_dl did that job wonderfully up until a few months ago, that wasn’t necessary and they still work perfectly when I’m listening to podcasts with direct URLs.