postlund / pyatv

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

Support streaming from online video services, e.g. Youtube #2186

Open postlund opened 9 months ago

postlund commented 9 months ago

What feature would you like?

Add support for streaming directly from online services, like Youtube. This is probably not possible with all services, but some should work.

Describe the solution you'd like

The intention is to use yt-dlp to extract the underlying video URL, then passing that URL on via AirPlay (play_url). It's an easy solution that yields a simple API for most users. Testing it would be something like this:

atvremote -s 10.0.10.81 play_service=https://www.youtube.com/watch?v=dQw4w9WgXcQ

As play_url is used, that feature must be available.

Any other information to share?

TBD

postlund commented 9 months ago

I have started the work in #2187. Some caveats here though:

This Is still an early attempt, but would love some feedback on this!

postlund commented 9 months ago

I can create a variant that installs yt-dlp as an optional dependency:

https://setuptools.pypa.io/en/latest/userguide/dependency_management.html#optional-dependencies

postlund commented 9 months ago

To continue with the other bullets:

postlund commented 9 months ago

Thinking about it once more... most people would like this as a transparent feature, i.e. pass a URL and let pyatv deal with it. That's what I would prefer as well. So merging with play_url sounds reasonable, but also add a flag to disable auto extraction in case it becomes a problem. I will have to check if I can validate if a URL is supported by yt-dlp though.

postlund commented 9 months ago

I can probably check if the URL is supported by yt-dlp like this:

https://github.com/yt-dlp/yt-dlp/issues/8101#issuecomment-1718341135

Just need to await if this is to be considered a stable API.

postlund commented 9 months ago

This: https://github.com/yt-dlp/yt-dlp/issues/8101#issuecomment-1719061307

robloh commented 9 months ago

Would this work playing an MP4/MKV from a NAS with something like Infuse as well? https://firecore.com/infuse

postlund commented 9 months ago

This will not add support for any new formats (MP4 is still your best bet) and will only support services supported by yt-dlp, where Infuse does not seem to be included. So in that particular case: no, it will not. But I imagine you can get the URL to media directly in Infuse somehow? Maybe even transcoded to an appropriate format? Since they have an Apple TV app, you could also opt for using launch_app with deep links instead (see https://pyatv.dev/development/apps/#app-deep-links).