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

Add support for custom stream queries for media_extractor #8538

Merged
merged 4 commits into from
Jul 19, 2017
Merged

Add support for custom stream queries for media_extractor #8538

merged 4 commits into from
Jul 19, 2017

Conversation

minchik
Copy link
Contributor

@minchik minchik commented Jul 18, 2017

Description:

This PR adds support for custom stream queries per device and media type to media_extractor.

Example entry for configuration.yaml (if applicable):

media_extractor:
  default_query: worst
  customize:
    media_player.kd55x8507c:
      video: bestvideo 
      music: bestaudio
      playlist: worstaudio[ext=mp4]

Default query if no settings provided is best.
User can override default value or set custom query per device and media type.

Examples:

  • bestvideo - best video only stream
  • best - best video + audio stream
  • bestaudio[ext=m4a] - best audio stream with m4a extension
  • worst - worst video + audio stream
  • bestaudio[ext=m4a]/bestaudio[ext=ogg]/bestaudio - best m4a audio, otherwise best ogg audio and only then any audio

More about format queries https://github.com/rg3/youtube-dl/blob/master/README.md#format-selection

BUT:

My settings:

media_extractor:
  default_query: best
  customize:
    media_player.kd55x8507c:
      video/videoonly: bestvideo
      video/best: best
      audio/best: bestaudio[ext=m4a]

My chromecast device (Sony Bravia with Android TV) does not support these media content types https://home-assistant.io/components/media_player/#service-media_playerplay_media
It supports media_content_type attributes like:

  • video/blablabla
  • audio/blablabla

My service call data is:

{"entity_id": "media_player.kd55x8507c", "media_content_id": "https://www.youtube.com/watch?v=VZMfhtKa-wo", "media_content_type": "audio/best"}

Checklist:

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • New dependencies have been added to the REQUIREMENTS variable ([example][ex-requir]).
  • New dependencies are only imported inside functions that use them ([example][ex-import]).
  • New dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

If the code does not interact with devices:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • Tests have been added to verify that the new code works.

@lwis
Copy link
Member

lwis commented Jul 18, 2017

Could you add a config schema for this component please?

Apart from that, this looks good. Will test later.

@lwis
Copy link
Member

lwis commented Jul 18, 2017

Still getting soco.exceptions.SoCoUPnPException: UPnP Error 714 received: Illegal MIME-Type for Sonos, sadly. Potentially more hackery required, but as this stands it looks good 👍

@minchik
Copy link
Contributor Author

minchik commented Jul 18, 2017

Is it possible to send any stream to Sonos from HA using media_player.play_media service?

@lwis
Copy link
Member

lwis commented Jul 18, 2017

I've done it before with a stream of PC audio, so it is possible, just not easy.

@minchik
Copy link
Contributor Author

minchik commented Jul 18, 2017

Could you provide service data?

@lwis
Copy link
Member

lwis commented Jul 18, 2017

Same as your example.

@minchik
Copy link
Contributor Author

minchik commented Jul 18, 2017

But what was the value of "media_content_type" with working example?

@lwis
Copy link
Member

lwis commented Jul 18, 2017

Ah, I mean the stream was setup outside of hass.

@minchik
Copy link
Contributor Author

minchik commented Jul 18, 2017

Looks like sonos support only MP3, AAC and WMA for that kind of streaming. And unfortunately youtube does not support these formats.( https://sonos.custhelp.com/app/answers/detail/a_id/80/~/supported-audio-formats

@lwis
Copy link
Member

lwis commented Jul 18, 2017

Gotcha, it's a shame we can't add support for transcoding without serving the stream through hass.

@minchik
Copy link
Contributor Author

minchik commented Jul 18, 2017

Can you check your sonos devices with this url - https://soundcloud.com/bruttoband/brutto-11 and audio/mp3: bestaudio[ext=mp3]

@minchik
Copy link
Contributor Author

minchik commented Jul 18, 2017

Can anyone rerun this build as it failed because of ConnectionResetError

@lwis
Copy link
Member

lwis commented Jul 19, 2017

@minchik restarted the build for you.

{"entity_id": "media_player.sonos_bedroom", "media_content_id": "https://soundcloud.com/bruttoband/brutto-11", "media_content_type": "audio/mp3"} worked for me.

@minchik
Copy link
Contributor Author

minchik commented Jul 19, 2017

As expected it depends on whether the owner of the media contains supported streams for your device

@lwis lwis merged commit 6bc0729 into home-assistant:dev Jul 19, 2017
@lwis
Copy link
Member

lwis commented Jul 19, 2017

Thanks! 🐊

@lwis
Copy link
Member

lwis commented Jul 19, 2017

@minchik can you update the docs for this please? Provide a link to https://github.com/rg3/youtube-dl#format-selection

@minchik
Copy link
Contributor Author

minchik commented Jul 19, 2017

ok

@minchik
Copy link
Contributor Author

minchik commented Jul 19, 2017

@balloob balloob mentioned this pull request Jul 29, 2017
dethpickle pushed a commit to dethpickle/home-assistant that referenced this pull request Aug 18, 2017
…ractor (home-assistant#8538)

* Add support for different stream formats

* Encapsulate logic inside MediaExtractor class

* Add CONFIG_SCHEMA

* Fix for cases when youtube-dl returns content of playlist as list
@home-assistant home-assistant locked and limited conversation to collaborators Oct 20, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants