Youtube Music - Media Browser

@popboxgun Did you use config_flow integration or manual way.

It doesnā€™t show up in integration for me, so I manually created the header_auth.json

Iā€™m guessing you might not be logged in correctly. Are there any errors in the Home Assistant logs? I was unsuccessful with various attempts myself, until I used the simplified example from the ymusicapi docs to create my header_auth.json from.

{
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0",
    "Accept": "*/*",
    "Accept-Language": "en-US,en;q=0.5",
    "Content-Type": "application/json",
    "X-Goog-AuthUser": "0",
    "x-origin": "https://music.youtube.com",
    "Cookie" : "PASTE_COOKIE"
}

With this example, I only needed to PASTE_COOKIE where indicated.

** Update **

I went into incognito and signed in, used your headers_auth.json and everything loaded up, thanks!


I had tried that one but wasnā€™t getting anywhere. I did notice that my cookie starts with VISITOR_INFO1_LIVE while the screenshots on the github docs start with CONSENT. Iā€™ll work with authentication some more.

Yes, I did get an error

  File "/config/custom_components/ytube_music_player/media_player.py", line 298, in _update_sources
    self._update_playlists()
  File "/config/custom_components/ytube_music_player/media_player.py", line 309, in _update_playlists
    self._playlists = self._api.get_library_playlists()
  File "/usr/local/lib/python3.8/site-packages/ytmusicapi/mixins/library.py", line 29, in get_library_playlists
    results = find_object_by_key(nav(response, SINGLE_COLUMN_TAB + SECTION_LIST),
  File "/usr/local/lib/python3.8/site-packages/ytmusicapi/parsers/utils.py", line 148, in nav
    raise err
  File "/usr/local/lib/python3.8/site-packages/ytmusicapi/parsers/utils.py", line 142, in nav
    root = root[k]
KeyError: 'contents'
1 Like

Hi, so to understand it correctly:

  1. the integration didnā€™t show up for you (did you refresh your browser after installation and restart?)
  2. since you didnā€™t see the integration youā€™ve tried it directly yourself ā€¦ which didnā€™t work ouf for whatever reason
  3. later the integration showed up and you were able to use the integration to create the auth-file
  4. now everything is good?

So ultimately nothing to change in the code?

I see it in integrations now, truthfully I probably installed the component and didnā€™t see that you could do it via integrations until I was already playing around with headers_auth.json. At that point it was getting errors loading the media_player because I did not format it correctly. Iā€™ll tear it down this morning and test again, but Iā€™d assume it is my fault.

Thanks for your work on this, playing the music worked great this morning!

1 Like

I am trying to enter the cookie info, but it keeps saying: something with your cookie wasnā€™t right.

I first tried the method outlined on github, but I donā€™t have anything past ā€˜user-agentā€™, I donā€™t see any x-google items. (using Chrome)

I then tried the smaller bit of code, and pasted the ā€œPaste_Cookieā€ but still get the error.

My cookie starts with GPS=1; YSU=yTā€¦ etc. should I be coping a subset of this info?

have you tried to grab it from an incognito session?
maybe on a windows pc?

Iā€™m getting the same error when I try to setup using the config flow. However, the cookie is working fine if I setup the component manually.

Pretty sure you need to copy the whole cookie, not just a part of it. I have no idea what it means but my cookie begins with VISITOR_INFO1_LIVE, matching what @popboxgun has reported earlier. I checked the entire string, my cookie does not have any parts being with GPS=... or YSU=...

EDIT ā€“ Looking through the code, I donā€™t see anything that is creating (saving to disk) the header_auth.json file itself. I want to help with this but my Python skills are extremely sub-par. I think I would just be making more work for you @JKW. ( like a young child ā€œhelpingā€ in the kitchen :rofl: ) ā€“ Anyways, Iā€™m wondering if itā€™s possible to just create/store the header_auth.json inside the .storage folder that is already located in the HA config directory. In the config flow, only the cookie would need to be entered.

@JKW yes, I did use Incognito on a Windows PC.

I manually set up the .json file, as suggested, and the player works for me now.

FWIW, I did keep the GPS info in my cookie (sample below), and I am in MX, so perhaps some user may need it, depending on location.

image

playing around with the add in, seems to be working well for the most part. However, Iā€™m not getting the full list of my playlist, Iā€™m only getting 18 (including ā€˜your likesā€™).

anyone else have this issue, and/or know how to refresh it?

1 Like

hi could you update and try again?
thx, jkw

I canā€™t get it to work.
Copying the grabbed text where it is requested: Something is wrong with your cookie.
Creating a file as described: The file seem to be ignored.
Now Iā€™m off. No idea what to do.
Is there anything I have to check or to do?
How shoult the headers_auth.json look like?
Is the location ā€œ/config/ā€ right or is "/config/custom_components/yTube_media_player " meant?
so much questions :slight_smile:

Iā€™m working on an improved version of the integration-parser ā€¦ as of now: please only copy the ā€œcookieā€ and ā€œx-goog-authā€ (==0 for me) line ā€¦ to the inputā€¦ see if that works ā€¦

JKW

Did it, no change.

So I might have to wait for the updated config flow.
Thank you!

@JKW the new build seems to address the playlist limit. thanks.

just curious, any reason why itā€™s hard coded to 99? Is there an upper limit (it looks like the YT API is limited to 50 for MaxResults).

Iā€™m just trying to find out were the upper limits might be.

no, honestly ā€¦ the 25 default limit seemed reasonable to me, but hey, youā€™ve proofed that it was to low. 99 should be high enough iā€™d assume. I didnā€™t find a way to get the number upfront ā€¦ so i just picked a high value.

Iā€™ve extended the token generation process and at least that part works reasonably well for me :slightly_smiling_face: (I can now generate header files easily with chrome / ubuntu / incognito). But I see some ā€œnewā€ behavior. The youtube component is quite often not capable to generate a valid streaming url. :dizzy_face:

A few more details for those who want to know: All Iā€™ve done is to combine two existing apis:

The first api will read the header file and can get all the information from you account as well as the songs in the playlist but ultimately wonā€™t return a streaming link.(or at least I donā€™t understand where Iā€™d get it). It will however return a ā€˜videoIdā€™

The second API will convert the videoId into a streaming link. The ā€œproblemā€ that I see here is that the second API isnā€™t using any of the login info at all. And sometimes it is not able to return a valid link at all

Iā€™m trying to understand the second API better and also to get into contact with the developer to see if I can use more information from api 1 (e.g. there is a cypher that already contains mostly the link but needs to be decrypted (which api 2 is doing with some sort of reverse lookup of the javascript code on the website) and less from api 2 to generate the link

jkw

2 Likes

@JKW your effort is greatly appreciated.

3 Likes

tried to follow these instructions >

 Basic steps for grabbing

Open the development tools (I've used google chrome) [Crtl+Shift+I]
Open the Network tab
Open https://music.youtube.com, log out, log in
Search for "/browse" (for me only one item shows up) [If you can't find it: I had issues with ubuntu, worked instantly with windows]
Go to "headers" -> "request headers" and copy everything starting at "accept: /" (mark with a mouse and copy to clipboard)

I tried the search for ā€œ/browseā€ no luck ā€¦ iā€™m using chrome on window 10
Plus the ā€œHeadersā€ tag is not listed under ā€œNetworkā€

any ideas ???

Regards
LeeB

Try clicking around in YouTube music web page. I didnā€™t get a working cookie until I browsed my library