sigma67 / ytmusicapi

Unofficial API for YouTube Music
https://ytmusicapi.readthedocs.io
MIT License
1.69k stars 192 forks source link

Please clarify the setup documentation #228

Closed salsaman closed 2 years ago

salsaman commented 2 years ago

Hi, I have been struggling to get thius set up,, and am not finding the setup instructions very helpful. Please can you clarify what the general forrmat of the request headers text and the 'cookie' should look like.. I have gone through the steps best as I can make out, but when I try to use the cookie (?) in Home Assistant, I keep getting an error teeling me it is unable to connect.. Without clearer exemples to follow, I cannot be sure if the issue is with Home Assistant integration or with the text which I am pasting in the Cookie field.

sigma67 commented 2 years ago

Hi, please refer to the documentation to point out where exactly it is unclear: https://ytmusicapi.readthedocs.io/en/latest/setup.html

For Home Assistant, please refer to https://github.com/KoljaWindeler/ytube_music_player/

salsaman commented 2 years ago

The problem I am having is this - when I try to do the setup in Home Assistant, there is a text field where I am supposed to enter the cookie text. I followed the instructions and opened dev tools, searched for /browse and found the request headers. Amongst the headers, there is a "Cookie" field. I copied the value into the HA setup, and it came back with an error, "Something with your cookie wasn't right. Format and fields are ok but the login failed:." So then returning to the documentation, I see "Using the headers in your project". Thus, I figured maybe I had to follow the instructions and process the headers using a python console, and paste in the resulting output. I tried this, and again received the same error in HA. So then I began to question exactly what I was supposed to cut and paste. Since there was no example of what the cookie data is supposed to look like, I cannot tell if I am pasting in the necessary data or not. The cookie data I have begins with "VISITOR_INFO1_LIVE=...:" and then contains several other pieces of data separated with ";" ending with "__Secure-3PSIDCC=...". It is not clear if I should paste in all of this, or if in fact I do need to run the python console commands and paste in the resulting output. Anyway, neither worked for me, I continue to get the same error. Since there are no examples of what the cookie data is supposed to look like, I have no way of telling if the problem is with the data returned from the browser, or if the problem is with the HA setup. Including an example of what the cookie data should look like would be useful to try to troubleshoot this issue. Frustratingly, the part of the documentation where it would be sensible to provide an example, ie. the file fields, the text simply says "PASTE_COOKIE". Not very helpful in this instance. I am rasing the issue here, because in ytube_msuci_player, it simply suggests referring to the documentation here.

salsaman commented 2 years ago

Checking logs in Homea Assistent I see the following:

2021-09-26 15:34:59 ERROR (MainThread) [custom_components.ytube_music_player.config_flow] Traceback (most recent call last): File "/config/custom_components/ytube_music_player/config_flow.py", line 188, in async_check_data YTMusic.setup(filepath = user_input[CONF_HEADER_PATH], headers_raw = c) File "/usr/local/lib/python3.9/site-packages/ytmusicapi/ytmusic.py", line 156, in setup return setup(filepath, headers_raw) File "/usr/local/lib/python3.9/site-packages/ytmusicapi/setup.py", line 36, in setup raise Exception( Exception: The following entries are missing in your headers: cookie, x-goog-authuser. Please try a different request (such as /browse) and make sure you are logged in.

However, that field does exist in the cookie text, ie: "x-goog-authuser": "0",

I can confirm this was copied from a /browse request and I am logged in. I do have a field x-goog-visitor-id, with non-zero data, so maybe Google has updated the request headers in some way ? Or perhaps it has something to do with 2-step authorization which I do have enabled ?

sigma67 commented 2 years ago

If you want me to check your cookie you can send it to ytmusicapi@gmail.com, maybe I can find the issue

khmikkelsen commented 2 years ago

The problem I am having is this - when I try to do the setup in Home Assistant, there is a text field where I am supposed to enter the cookie text. I followed the instructions and opened dev tools, searched for /browse and found the request headers. Amongst the headers, there is a "Cookie" field. I copied the value into the HA setup, and it came back with an error, "Something with your cookie wasn't right. Format and fields are ok but the login failed:." So then returning to the documentation, I see "Using the headers in your project". Thus, I figured maybe I had to follow the instructions and process the headers using a python console, and paste in the resulting output. I tried this, and again received the same error in HA. So then I began to question exactly what I was supposed to cut and paste. Since there was no example of what the cookie data is supposed to look like, I cannot tell if I am pasting in the necessary data or not. The cookie data I have begins with "VISITOR_INFO1_LIVE=...:" and then contains several other pieces of data separated with ";" ending with "__Secure-3PSIDCC=...". It is not clear if I should paste in all of this, or if in fact I do need to run the python console commands and paste in the resulting output. Anyway, neither worked for me, I continue to get the same error. Since there are no examples of what the cookie data is supposed to look like, I have no way of telling if the problem is with the data returned from the browser, or if the problem is with the HA setup. Including an example of what the cookie data should look like would be useful to try to troubleshoot this issue. Frustratingly, the part of the documentation where it would be sensible to provide an example, ie. the file fields, the text simply says "PASTE_COOKIE". Not very helpful in this instance. I am rasing the issue here, because in ytube_msuci_player, it simply suggests referring to the documentation here.

The way I got around this issue in HA is by running the package through my normal python development environment, and just copy pasting the output from ytmusicapi.

salsaman commented 2 years ago

Can this really be closed ? The suggested solution above would be troublesmoe for me as I do not have the development environment set up, a not uncommon case, I would imagine. Without going through the instaltion process to get a development envirnment set up, I cannot confirm whether or no the suggestion above would work in my case, as it does seem likely that the problem is the format of the cookie, which lacks the specific field mentioned.

I apologise for not emailing the cookie, as I am right in the middle of moving home and overseeing the large scal refurbishment taking place there. As soon as I get a free hour I will forward it. Closing this without offering a more convenient solution which doesn't require installing a complete dev. environment seems a little premature to me.

khmikkelsen commented 2 years ago

This is not a ytmusicapi issue, it's a HA issue not being able to use the console. You could probably get around this connecting to your HA through SSH, then running ytmusicapi. However, it's really not much trouble to install python and running a small script once. You could always create an additional argument in the YTMusic with a path, which then reads a file, and make a pull request :)