Youtube Music - Media Browser

Now with Home Assistant supporting Media Browser/Library content.

It looks like this python project is ripe for the intergration https://github.com/sigma67/ytmusicapi

Best of all for chromecast devices we only need to pass the youtube id for everything to just work.

Please yes!

This would be amazing!

That would be nice.

a real treat indeed

Anyone have so good python skills and time, would love some help on this…

Would be nice

A lot of people waiting for a lot of time.for something like that.

Yes please!

1 Like

We definitely need this with GMusic shutting down

would be great to have this working. Meanwhile are there any workarounds to start playing playlist on google home from home assistant or node red?

Same here!

Everyone, please vote for this!

1 Like

Please yes!

So I’ve started to digg into the given URL on the top. I can login and get the playlists and also narrow it down to the song ID. e.g. O6FrmB81bRU. Pushing that into the browser like https://www.youtube.com/watch?v=O6FrmB81bRU (just an example link) works fine, I get the song, playing on the website, but I can’t pass that link to a chromcast / home / generic device.

Does anyone know how to convert that videoId or even the cypher to a playable link?
JKW

@JKW You can use the media_extractor.play_media to give it the YouTube ID and it will play it for you.

I have a mod for the Cast app to add support for YouTube app and supporting playing video’s like we do via the YouTube controller in pychromecast. it unfortunately will only work with video Chromecast devices. Need to work on building a controller for YouTube Music app but that is a larger challenge.

Additionally If you want to have playlists instead of controlling one song at a time we will need to have the YouTube or YouTube Music App

Hi, media_extractor didn’t work for me … works fine for regular youtube video IDs but did not work for the Youtube Music IDs.

I’ve written a (somewhat) working version with the help of pytube + ytmusicapi. Still a few kinks to work out, but even “auto track advance” is working now … This is based on the great work of @troy https://github.com/tprelog/homeassistant-gmusic_player but replaces gmusic with ytube music

Performance is ok, it takes around 3 sec “to think” between the tracks (actually not to bad, but could be faster). [https://github.com/nficano/pytube/issues/841]

For early adopters / brave alpha testes (feedback always welcome):

Github: https://github.com/KoljaWindeler/ytube_music_player
You need a “credential file” as explained here: https://ytmusicapi.readthedocs.io/en/latest/setup.html#copy-authentication-headers
Ultimatly create a file, looking like this:
https://ytmusicapi.readthedocs.io/en/latest/setup.html#manual-file-creation

I know that this steps is very complicated, I’m considering to create a config flow for this component to ease the file creation. Any other thoughts?

configuration.yaml:

media_player:
  - platform: ytube_music_player
    speakers:
      - jkw_cast2

input_select:
  ytube_music_player_source:
    name: Source
    icon: mdi:music-box-multiple
    options:
    - "Playlist Radio"
    - "Playlist"

  ytube_music_player_playlist:
    name: Playlist
    icon: mdi:playlist-music
    options: ## Should be empty
    - " "

JKW

4 Likes

@JKW, You have saved us all! :tada:

It wasn’t too bad doing this manually (I think it was easier than getting the oauth creds in gmusic_player) but a config flow would be much appreciated for most users.

  1. Please make your repository HACS compatible :slightly_smiling_face:

  2. For the configuration example, I think you forgot the input_select for the speakers. Also over time, I found it is better to include some sort of default value for the input selects helpers. Please consider the following updated example:

media_player:
  - platform: ytube_music_player
    header_path: '/config/headers_auth.json'
    speakers:
      - jkw_cast2

input_select:
  ytube_music_player_source:
    name: Source
    icon: mdi:music-box-multiple
    options:
    - "Playlist Radio"
    - "Playlist"

  ytube_music_player_playlist:
    name: Playlist
    icon: mdi:playlist-music
    options:
    - "loading"

  ytube_music_player_speakers:
    name: Speakers
    icon: mdi:speaker
    options:
    - "loading"
2 Likes

Could you have a look.

  • Should already work with custom repository in HACS
  • Default HACS entry should follow soon, brand and wheel pull_request are submitted
  • config_flow to import the cookie works here, but setting up the player is apparently above my capabilities, although I’ve written two other config_flow without isses

I can’t wrap my head around the async generation of the YouTube object. Anyone willing to work with me on that?

JKW

5 Likes

I was able to get authenticated, I had to read through your const.py to see which headers were needed, then put it in the json format from ytmusicapi link. Copying the whole thing didn’t work.

I am not able to load any playlists, I tried private, unlisted and public but it just shows ‘loading’


{
    "Cookie": "",
    "Accept-Encoding": "gzip, deflate, br",
    "Accept-Language": "en-US,en;q=0.5",
    "Authorization": "",
    "Host": "music.youtube.com",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:82.0) Gecko/20100101 Firefox/82.0",
    "X-Goog-AuthUser": "null",
    "X-Goog-Visitor-Id": "",
    "x-origin": "https://music.youtube.com",
    "X-YouTube-Client-Name": "",
    "X-YouTube-Identity-Token": "",
    "X-YouTube-Page-CL": ""
}