core: Media Extractor fails on YouTube links
The problem
In a nutshell, Media Extractor is raising an error when it is fed a YouTube link. This is most likely related to a warning raised yt-dlp that seems to be resolved with the latest 2024.7.9 version. HA is currently using (defining) 2024.07.01 as the version required.
What version of Home Assistant Core has the issue?
core-2024.7.2
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
No response
Anything in the logs that might be useful for us?
From the Logs:
[youtube] oav5D6X0Ecs: nsig extraction failed: Some formats may be missing n = VFfWJyJN9QPW58hrb ; player = https://www.youtube.com/s/player/b22ef6e7/player_ias.vflset/en_US/base.js
[youtube] oav5D6X0Ecs: nsig extraction failed: Some formats may be missing n = XDpRT24b54AU2WZ0E ; player = https://www.youtube.com/s/player/b22ef6e7/player_ias.vflset/en_US/base.js
[youtube] pjVMnq-v4xs: nsig extraction failed: Some formats may be missing n = ZCR-3GwwmEpHNStD0 ; player = https://www.youtube.com/s/player/b22ef6e7/player_ias.vflset/en_US/base.js
[youtube] pjVMnq-v4xs: nsig extraction failed: Some formats may be missing n = rQP2yYXlgGFgj_luy ; player = https://www.youtube.com/s/player/b22ef6e7/player_ias.vflset/en_US/base.js
Followed by:
Logger: homeassistant.helpers.script.websocket_api_script
Source: helpers/script.py:527
First occurred: 14:46:23 (2 occurrences)
Last logged: 14:47:58
websocket_api script: Error executing script. Unexpected error for call_service at pos 1: list index out of range
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 527, in _async_step
await getattr(self, handler)()
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 764, in _async_call_service_step
response_data = await self._async_run_long_action(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 727, in _async_run_long_action
return await long_task
^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2731, in async_call
response_data = await coro
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2774, in _execute_service
return await target(service_call)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/media_extractor/__init__.py", line 123, in extract_media_url
url = get_best_stream_youtube(selected_media["formats"])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/media_extractor/__init__.py", line 315, in get_best_stream_youtube
return get_best_stream(
^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/media_extractor/__init__.py", line 306, in get_best_stream
return cast(str, formats[len(formats) - 1]["url"])
~~~~~~~^^^^^^^^^^^^^^^^^^
IndexError: list index out of range
### Additional information
Likely just needs a bump to the newest version.
I used an older version of yt-dlp (binary) and see the warning in its output but the download still worked.
I updated yt-dlp to the latest version 2024.7.9 and ran the same command again but didn't receive a warning so I _assume_ this issue was fixed in yt-dlp.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 1
- Comments: 44 (7 by maintainers)
I think this error has returned. I am running 2025.4.3 and media extractor is throwing this error again:-
Given I’m stopped from playing anything from YouTube while the integration gets a version bump, I decided to modify my own
manifest.jsonto get it working for me.I know it won’t survive an update and is frowned upon but I assume the next version released will see the bump to yt-dlp anyway.
For anyone interested and skilled enough in doing this that’s using Home Assistant OS version. Here’s what I did.
Protection modeis off and create a username and password in theConfigurationsection. Start the add-on.manifest.jsonfile out to console - allowing you to see which version of yt-dlp is being used by Home Assistant.docker exec -it homeassistant cat /usr/src/homeassistant/homeassistant/components/media_extractor/manifest.jsonmanifest.jsonto use the latest version of yt-dlp.docker exec -it homeassistant sed -i 's/\["yt-dlp==[0-9]\{4\}\.[0-9]\{2\}\.[0-9]\{2\}"\]/\["yt-dlp==2024.07.25"\]/' /usr/src/homeassistant/homeassistant/components/media_extractor/manifest.jsondocker exec -it homeassistant cat /usr/src/homeassistant/homeassistant/components/media_extractor/manifest.jsonBe aware that the above will not survive a version upgrade to Home Assistant but, as I said, I expect this will be resolved in the next release anyway (didn’t get it with 2024.7.4 from today so I needed to do this from my point of view).
I know this is frowned on etc. but for anyone stuck and needing a workaround now without waiting for the next version, this should get
media_extractor.play_mediaworking again with YouTube links.I am repeating myself…
I’m using a VM in Proxmox using this script https://tteck.github.io/Proxmox/#home-assistant-os-vm
Is there any option to modify this file with “File editor” addon or similar?
Bumped that version for the beta