Improve setup documentation (closes #58)
This commit is contained in:
parent
7835d229dd
commit
de64b0864f
1 changed files with 41 additions and 7 deletions
|
|
@ -10,27 +10,61 @@ Installation
|
||||||
Authenticated requests
|
Authenticated requests
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
To run authenticated requests you need to set up you need to copy your request headers from a POST request in your YTMusic Web Client.
|
Copy authentication headers
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
To run authenticated requests you need to set up you need to copy your request headers from a POST request in your browser.
|
||||||
To do so, follow these steps:
|
To do so, follow these steps:
|
||||||
|
|
||||||
- Open https://music.youtube.com in Firefox
|
- Open a new tab
|
||||||
- Go to the developer tools (Ctrl-Shift-I) and open the "Network" tab.
|
- Open the developer tools (Ctrl-Shift-I) and select the "Network" tab
|
||||||
- Find an authenticated POST request (Status: 200, Method: POST, Domain: music.youtube.com, File: log_event?...). You can filter for /browse to easily find a suitable request.
|
- Go to https://music.youtube.com and ensure you are logged in
|
||||||
|
- Find an authenticated POST request. The simplest way is to filter by ``/browse`` using the search bar
|
||||||
|
|
||||||
|
.. raw:: html
|
||||||
|
|
||||||
|
<details open>
|
||||||
|
<summary><a>Firefox</a></summary>
|
||||||
|
|
||||||
|
.. container::
|
||||||
|
|
||||||
|
- Verify that the request looks like this: **Status** 200, **Method** POST, **Domain** music.youtube.com, **File** ``browse?...``
|
||||||
- Copy the request headers (right click > copy > copy request headers)
|
- Copy the request headers (right click > copy > copy request headers)
|
||||||
|
|
||||||
Now open a python console and call :py:func:`YTMusic.setup` with the parameter ``filepath=headers_auth.json`` and follow the instructions and paste the request headers to the terminal input:
|
.. raw:: html
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
.. raw:: html
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary><a>Chromium (Chrome/Edge)</a></summary>
|
||||||
|
|
||||||
|
.. container::
|
||||||
|
|
||||||
|
- Verify that the request looks like this: **Status** 200, **Type** xhr, **Name** ``browse?...``
|
||||||
|
- Click on the Name of any matching request. In the "Headers" tab, scroll to the section "Request headers" and copy everything starting from "accept: \*/\*" to the end of the section
|
||||||
|
|
||||||
|
.. raw:: html
|
||||||
|
|
||||||
|
</details><br>
|
||||||
|
|
||||||
|
Using the headers in your project
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
To set up your project, open a Python console and call :py:func:`YTMusic.setup` with the parameter ``filepath=headers_auth.json`` and follow the instructions and paste the request headers to the terminal input:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
from ytmusicapi import YTMusic
|
from ytmusicapi import YTMusic
|
||||||
YTMusic.setup(filepath=headers_auth.json)
|
YTMusic.setup(filepath=headers_auth.json)
|
||||||
|
|
||||||
If you don't want terminal interaction you can pass the request headers with the ``headers_raw`` parameter:
|
If you don't want terminal interaction in your project, you can pass the request headers with the ``headers_raw`` parameter:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
from ytmusicapi import YTMusic
|
from ytmusicapi import YTMusic
|
||||||
YTMusic.setup(filepath=headers_auth.json, headers_raw="very long string")
|
YTMusic.setup(filepath=headers_auth.json, headers_raw="<headers copied above>")
|
||||||
|
|
||||||
The function returns a JSON string with the credentials needed for :doc:`Usage <usage>`. Alternatively, if you passed the filepath parameter as described above,
|
The function returns a JSON string with the credentials needed for :doc:`Usage <usage>`. Alternatively, if you passed the filepath parameter as described above,
|
||||||
a file called ``headers_auth.json`` will be created in the current directory, which you can pass to ``YTMusic()`` for authentication.
|
a file called ``headers_auth.json`` will be created in the current directory, which you can pass to ``YTMusic()`` for authentication.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue