Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
postlund opened this issue Sep 13, 2023 · 9 comments
Open

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

postlund opened this issue Sep 13, 2023 · 9 comments
Labels
airplay AirPlay related issue feature
Milestone

Comments

@postlund
Copy link
Owner

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 postlund added feature airplay AirPlay related issue labels Sep 13, 2023
postlund added a commit that referenced this issue Sep 13, 2023
@postlund postlund added this to the 0.15.0 milestone Sep 13, 2023
@postlund
Copy link
Owner Author

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

  • I have not decided if I want pyatv to depend on yt-dlp, so it is not a dependency for now and must be installed manually (an exception is raised otherwise)
  • pyatv will use video with best bitrate: it is not possible to request a certain quality/resolution (will be resolved later)
  • Video services requiring authentication are not supported (yet)
  • API is not final, might change or merge with play_url
  • Would like to turn it into a feature, so the features API reports if it is supported or not
  • Maybe other things...

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

postlund added a commit that referenced this issue Sep 13, 2023
@postlund
Copy link
Owner Author

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
Copy link
Owner Author

To continue with the other bullets:

  • I will have to study yt-dlp a bit to see what filtering to support, e.g. resolution, video vs audio only, formats. Should also investigate if I can send additional metadata via AirPlay in this mode as I get a lot of that.
  • Usernames and passwords can be saved as settings, preferably in a section separated from the protocols to allow for easier sharing amongst protocols (if/when needed).
  • If I can somehow detect if a URL is supported by yt-dlp, then I can merge it with play_url. Not sure if that is easy to do. Otherwise it's probably simpler to keep this as a separate method. Drawback is however...
  • Adding it as a method not implemented by protocols, would not make it into a feature, so I cannot easily report availability for it. Merging functionality with play_url solves this. A workaround would be to add functionality to bind feature availability to another feature, i.e. treat it as a feature but let the facade report the same availability as another feature, thus bypassing protocols in this case. I also have the case of yt-dlp not being installed... I can also just treat it as a feature, just implement it in AirPlay and add all the checks I want. Simplest as only AirPlay supports play_url anyways, so should maybe not overthink this too much.

@postlund
Copy link
Owner Author

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
Copy link
Owner Author

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

yt-dlp/yt-dlp#8101 (comment)

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

@postlund
Copy link
Owner Author

This: yt-dlp/yt-dlp#8101 (comment)

@robloh
Copy link

robloh commented Sep 26, 2023

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

@postlund
Copy link
Owner Author

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).

@cylon147
Copy link

I'm trying to use this with Home assistance. to Launch a movie title from Netflix but it's only launching the Netflix not redirecting to the title page of the movie.

{ "id": 60, "type": "call_service", "domain": "media_player", "service": "play_media", "target": { "entity_id": "media_player.home_cinema" }, "service_data": { "media_content_id": "https://www.netflix.com/in/title/80234304", "media_content_type": "app" } }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
airplay AirPlay related issue feature
Projects
None yet
Development

No branches or pull requests

3 participants