postlund / pyatv

A client library for Apple TV and AirPlay devices
https://pyatv.dev
MIT License
886 stars 100 forks source link

Apple TV 15.4 can’t play youtube video #1702

Open rimonhanna opened 2 years ago

rimonhanna commented 2 years ago

Describe the bug

I tried playing youtube videos by giving the addon the video or playlist url as contentId and content type music (I tried all content types actually) but that didn’t work and i got the first error mentioned below, i also tried setting the apple TV as a destination speaker from the youtube addon and i also got the second error

Error log

Logger: homeassistant.components.websocket_api.http.connection
Source: custom_components/apple_tv/media_player.py:292 
Integration: Home Assistant WebSocket API (documentation, issues) 
First occurred: 09:43:13 (2 occurrences) 
Last logged: 09:43:23

[547337612496] Error handling message: Unknown error (unknown_error)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 27, in _handle_async_response
    await func(hass, connection, msg)
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 630, in handle_execute_script
    await script_obj.async_run(msg.get("variables"), context=context)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1275, in async_run
    await asyncio.shield(run.async_run())
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 359, in async_run
    await self._async_step(log_exceptions=False)
  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 "/config/custom_components/apple_tv/media_player.py", line 292, in async_play_media
    await self.atv.stream.stream_file(media_id)
  File "/usr/local/lib/python3.9/site-packages/pyatv/core/facade.py", line 382, in stream_file
    await self.relay("stream_file")(file, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/pyatv/protocols/raop/__init__.py", line 371, in stream_file
    audio_file = await open_source(
  File "/usr/local/lib/python3.9/site-packages/pyatv/protocols/raop/audio_source.py", line 483, in open_source
    return await InternetSource.open(source, sample_rate, channels, sample_size)
  File "/usr/local/lib/python3.9/site-packages/pyatv/protocols/raop/audio_source.py", line 362, in open
    stream_generator = await loop.run_in_executor(
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.9/site-packages/miniaudio.py", line 1216, in stream_any
    raise DecodeError("failed to init decoder", result)
miniaudio.DecodeError: ('failed to init decoder', -17)
This error originated from a custom integration.

Logger: homeassistant.core
Source: custom_components/apple_tv/media_player.py:292 
Integration: Apple TV 
First occurred: 08:55:53 (9 occurrences) 
Last logged: 09:37:35

Error executing service: <ServiceCall media_player.play_media (c:f4131e3ed5dfbee686430ecd29c91c10): entity_id=['media_player.living_room_apple_tv'], extra=metadata=metadataType=3, title=The Very Thought Of You, artist=Nat King Cole, images=[{'url': 'https://lh3.googleusercontent.com/mi-haESDF_9Tp7Rcj5Cv0FhfhrAeBiG-La1G19RUl0lUtsqX9dzsm_4sVLrNq-HOU7o7KG2OnHalgPi3=w120-h120-l90-rj'}], media_type=music, media_id=https://rr1---sn-5hnedn7e.googlevideo.com/videoplayback?expire=1649510307&ei=QjNRYq3vPILA8gPZ1IfgAg&ip=80.56.156.81&id=o-AAplnAa1oThbEoUlfq9lI8BuxFuMjz327rEh0cVtERIn&itag=141&source=youtube&requiressl=yes&mh=ZI&mm=31%2C29&mn=sn-5hnedn7e%2Csn-5hne6ns6&ms=au%2Crdu&mv=m&mvi=1&pl=17&ctier=A&pfa=5&gcr=nl&initcwndbps=2095000&hightc=yes&spc=4ocVC8qX9N_NAEN8YGgaaeZNpyXO0j5LTXiken67dw&vprv=1&mime=audio%2Fmp4&ns=j_LefCJstm0VcXOnzV7T1jgG&gir=yes&clen=7364004&dur=228.693&lmt=1581788650843563&mt=1649488395&fvip=2&keepalive=yes&fexp=24001373%2C24007246&c=WEB_REMIX&txp=5531432&n=_cAnkYMyUZxYjmRCUI&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cctier%2Cpfa%2Cgcr%2Chightc%2Cspc%2Cvprv%2Cmime%2Cns%2Cgir%2Cclen%2Cdur%2Clmt&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRgIhAIh0SZHL3NztlHPXJEJo209zt7QVuJm5mWwr0theCzHNAiEA01H7wTH641Vr5I__TLPHYbxakFjkowaHPRp4BjAQnfA%3D&sig=AOq0QJ8wRQIgGyNha4c8pNI0vYdD3gMmChPXOtAaqT7AS3g-Cru3sc4CIQC5_lbFgVbDIOTH1Oau_60NQNCoBBD9PWt5kXwM-5Yvog==>
Error executing service: <ServiceCall media_player.play_media (c:857d6e41530b4700ec67b06f1b09f788): entity_id=['media_player.living_room_apple_tv'], extra=metadata=metadataType=3, title=Autumn Leaves, artist=New York Jazz Lounge, images=[{'url': 'https://lh3.googleusercontent.com/YvXUtDfSzt_iTqXvBPVaNXA0wkF8LDuRA_kdjU7XxGVR8F6fQOGWCcn3iP-wBR1s9ksvmcuKYE97WjlT=w120-h120-l90-rj'}], media_type=music, media_id=https://rr4---sn-5hne6nzk.googlevideo.com/videoplayback?expire=1649510770&ei=ETVRYr6KOdiF6dsPlYOD-AU&ip=80.56.156.81&id=o-AHt1H16WVyHUiAKhlXTxa4u6ZwunG0pQcQhceyPsDeD9&itag=141&source=youtube&requiressl=yes&mh=1m&mm=31%2C26&mn=sn-5hne6nzk%2Csn-4g5e6nz7&ms=au%2Conr&mv=m&mvi=4&pl=17&ctier=A&pfa=5&gcr=nl&initcwndbps=2068750&hightc=yes&spc=4ocVCx75ib8mZ1Bdnrs0aqQfRHZtk09Oqs9xDSdNWQ&vprv=1&mime=audio%2Fmp4&ns=foBh-9Tp731IOeYS28wDvnMG&gir=yes&clen=11665397&dur=362.371&lmt=1600393227662820&mt=1649488885&fvip=4&keepalive=yes&fexp=24001373%2C24007246&c=WEB_REMIX&txp=1311222&n=d3qwiZ0SjPhXpHnStR&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cctier%2Cpfa%2Cgcr%2Chightc%2Cspc%2Cvprv%2Cmime%2Cns%2Cgir%2Cclen%2Cdur%2Clmt&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRQIgNB2Jj5Kw2RfP4x-QFIoAK4KUOkJ2lWkLDJOEwG-ak0wCIQD0suvEWjFkE1DPcPzzaiZKfH-l2uzc6n4yHYLsr-4zJg%3D%3D&sig=AOq0QJ8wRAIgKn9E_XcfljSjNaBJbhYOA4PkKQ2m_LV5fzcDPqXlQBkCIA7GU1X4j_T-DN3gshU9oO_ehjzounzLEkGy2R2WxMfI>
Error executing service: <ServiceCall media_player.play_media (c:3e9a127027e1efeeeaad09036b22528c): entity_id=['media_player.living_room_apple_tv'], extra=metadata=metadataType=3, title=My Kind of Girl, artist=Michael Bublé, images=[{'url': 'https://lh3.googleusercontent.com/6a5_8QvukBYccS9qRyV6S9hu9DWkbY27fUROA3zzrfSGrq48vd9o2PStocePXaVmCdWMDQY5i4_tBH8b=w120-h120-l90-rj'}], media_type=music, media_id=https://rr1---sn-5hneknes.googlevideo.com/videoplayback?expire=1649511042&ei=IjZRYsuNFrymx_AP27y1sA0&ip=80.56.156.81&id=o-AJ4oVR0HO9VJ1TDWAYOCc9BhvrtBnLTmFVPLCioxgN2Y&itag=141&source=youtube&requiressl=yes&mh=Ox&mm=31%2C29&mn=sn-5hneknes%2Csn-5hne6nz6&ms=au%2Crdu&mv=m&mvi=1&pl=17&ctier=A&pfa=5&gcr=nl&initcwndbps=2138750&hightc=yes&spc=4ocVC0C2vbNYlm9kHYD26C4pCjqAW5Kwgreova4kEg&vprv=1&mime=audio%2Fmp4&ns=IwHxlLOuBcQkB5I03GbAoRMG&gir=yes&clen=7934590&dur=246.439&lmt=1565291756460608&mt=1649489129&fvip=1&keepalive=yes&fexp=24001373%2C24007246&c=WEB_REMIX&txp=5431432&n=3P_692RyaAU0D2i5gj&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cctier%2Cpfa%2Cgcr%2Chightc%2Cspc%2Cvprv%2Cmime%2Cns%2Cgir%2Cclen%2Cdur%2Clmt&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRgIhAK0tAqdI7nHXwF5c1TMP-iH78FojzbeC5VyYHKMJx4BuAiEA-htHjuIzNiY20Sh6u_KFkhdUcJIww1A4YhyNENO998o%3D&sig=AOq0QJ8wRQIgbEJMs9jORRZ5sS-wWNeYEKwsnMwrqH0cV0gxsa_OvMICIQDeYFCUs_uuv9PSaOH6X-4vBf7VdDOIRs00K4Aixy4RwA==>
Error executing service: <ServiceCall media_player.play_media (c:bff6ceca4021d98407e3d2de18a639c5): entity_id=['media_player.living_room'], extra=metadata=metadataType=3, title=My Kind of Girl, artist=Michael Bublé, images=[{'url': 'https://lh3.googleusercontent.com/6a5_8QvukBYccS9qRyV6S9hu9DWkbY27fUROA3zzrfSGrq48vd9o2PStocePXaVmCdWMDQY5i4_tBH8b=w120-h120-l90-rj'}], media_type=music, media_id=https://rr1---sn-5hne6nz6.googlevideo.com/videoplayback?expire=1649511090&ei=UjZRYtK5J6-px_APl9iIiAE&ip=80.56.156.81&id=o-ABMcCbh-zdFVYnVk9Sx53bMUEJzCKaYChrAQa0siSK81&itag=141&source=youtube&requiressl=yes&mh=Ox&mm=31%2C26&mn=sn-5hne6nz6%2Csn-4g5ednsz&ms=au%2Conr&mv=m&mvi=1&pl=17&ctier=A&pfa=5&gcr=nl&initcwndbps=2328750&hightc=yes&spc=4ocVC7Cd7hfv1aA5AMeZGXzcI1i9LAqz4-ZPnrZ4Hw&vprv=1&mime=audio%2Fmp4&ns=DzuU16hXRX_bonjyneNU1pYG&gir=yes&clen=7934590&dur=246.439&lmt=1565291756460608&mt=1649489129&fvip=5&keepalive=yes&fexp=24001373%2C24007246&c=WEB_REMIX&txp=5431432&n=-neLSowSbV60Fzhqvv&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cctier%2Cpfa%2Cgcr%2Chightc%2Cspc%2Cvprv%2Cmime%2Cns%2Cgir%2Cclen%2Cdur%2Clmt&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRgIhALBodPQ8tZRTsTZ7YgszZ_b9fJvQMBiydscvzYZINxU3AiEAjbggGmCMiZ_v8deQfKSvqSaxe68oKO4sI4zrOmCgsbs%3D&sig=AOq0QJ8wRgIhAOnDWeffiJ4P-40PAY_lDGwNoM_W7uKOfudkVwhGuOJMAiEAwhnjMdq5iNpkeNJwZZXe2RIOBzknXoXawwhhcy_BDIw=>
Error executing service: <ServiceCall media_player.play_media (c:df3643761b3e5df4d1c0c7a0c5f5ff0d): entity_id=['media_player.living_room_apple_tv'], extra=metadata=metadataType=3, title=Dancing In The Dark, artist=Diana Krall, images=[{'url': 'https://lh3.googleusercontent.com/5AjdKXSDO4l7yHDo0L5Y-AUX1X4ZA-EqKxKIKMnF25C_VO9PpW13Rtv7DIBJJt5Xd2VQvlm7J9MCFyLD=w120-h120-s-l90-rj'}], media_type=music, media_id=https://rr1---sn-5hnekn7l.googlevideo.com/videoplayback?expire=1649511230&ei=3jZRYo26GvaXx_AP7aymiA8&ip=80.56.156.81&id=o-AMTcE-l1IayC_MuXB5nCoNsyWogdog6eXu-rQms3Okll&itag=141&source=youtube&requiressl=yes&mh=4a&mm=31%2C29&mn=sn-5hnekn7l%2Csn-5hne6nsk&ms=au%2Crdu&mv=m&mvi=1&pl=17&ctier=A&pfa=5&gcr=nl&initcwndbps=2088750&hightc=yes&spc=4ocVC4Jal0E3tupsAw8EdQWDUUAY3roEtX4-rriLxg&vprv=1&mime=audio%2Fmp4&ns=BI9V70_ppr96cwnptsVztC8G&gir=yes&clen=11217900&dur=348.439&lmt=1588437839170673&mt=1649489364&fvip=1&keepalive=yes&fexp=24001373%2C24007246&c=WEB_REMIX&txp=5431432&n=j2VxTj2SWFmlmH1bWQ&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cctier%2Cpfa%2Cgcr%2Chightc%2Cspc%2Cvprv%2Cmime%2Cns%2Cgir%2Cclen%2Cdur%2Clmt&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRAIgXgcCdlv5BvFPDyyxD1dYVVzWiAkFsapuzrOgZI077jQCIHQJt_vzqwZCVcGaszp_04iV1fHqSxVQB-7WjRh-sP-r&sig=AOq0QJ8wRQIgR5_o2iSjnzV2yXfmkS1BUaY-tF2FV_P4bss_3tYela0CIQDd2H93L-NtC39EnmMoIvbQBFAb4D5ahliSHmcdIfRJsg==>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/core.py", line 1652, in catch_exceptions
    await coro_or_task
  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 "/config/custom_components/apple_tv/media_player.py", line 292, in async_play_media
    await self.atv.stream.stream_file(media_id)
  File "/usr/local/lib/python3.9/site-packages/pyatv/core/facade.py", line 382, in stream_file
    await self.relay("stream_file")(file, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/pyatv/protocols/raop/__init__.py", line 371, in stream_file
    audio_file = await open_source(
  File "/usr/local/lib/python3.9/site-packages/pyatv/protocols/raop/audio_source.py", line 483, in open_source
    return await InternetSource.open(source, sample_rate, channels, sample_size)
  File "/usr/local/lib/python3.9/site-packages/pyatv/protocols/raop/audio_source.py", line 362, in open
    stream_generator = await loop.run_in_executor(
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.9/site-packages/miniaudio.py", line 1216, in stream_any
    raise DecodeError("failed to init decoder", result)
miniaudio.DecodeError: ('failed to init decoder', -17)

How to reproduce the bug?

Go to developer tools select media player: play media set the device to an apple tv set content id to a youtube video or playlist url set content type to music or anything really

What is expected behavior?

video or playlist plays on ATV

Operating System

tvOS 15.4.1

Python

3.9

pyatv

3.0.1

Device

Apple TV 4k 2021

Additional context

.

postlund commented 2 years ago

pyatv only supports audio files and that's not gonna change any time soon I'm afraid. Some kind of work-around would be to extract the audio stream with ffmpeg and use that as a source.

postlund commented 1 year ago

Once I restore support for play_url, this could potentially work assuming a third party library is used to extract the underlying video URL. Might be worth looking in to.