update docs
This commit is contained in:
parent
012a0fc85d
commit
461783f719
10 changed files with 69 additions and 43 deletions
92
docs/source/setup/browser.rst
Normal file
92
docs/source/setup/browser.rst
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
Browser authentication
|
||||
======================
|
||||
|
||||
This method of authentication emulates your browser session by reusing its request headers.
|
||||
Follow the instructions to have your browser's YouTube Music session request headers parsed
|
||||
to a ``ytmusicapi`` configuration file.
|
||||
|
||||
Copy authentication headers
|
||||
---------------------------
|
||||
|
||||
To run authenticated requests, set it up by first copying your request headers from an authenticated POST request in your browser.
|
||||
To do so, follow these steps:
|
||||
|
||||
- Open a new tab
|
||||
- Open the developer tools (Ctrl-Shift-I) and select the "Network" tab
|
||||
- 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 of the developer tools.
|
||||
If you don't see the request, try scrolling down a bit or clicking on the library button in the top 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)
|
||||
|
||||
.. raw:: html
|
||||
|
||||
</details>
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<details>
|
||||
<summary><a>Chromium (Chrome/Edge)</a></summary>
|
||||
|
||||
.. container::
|
||||
|
||||
- Verify that the request looks like this: **Status** 200, **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 console and call
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
ytmusicapi browser
|
||||
|
||||
Follow the instructions and paste the request headers to the terminal input.
|
||||
|
||||
If you don't want terminal interaction in your project, you can pass the request headers with the ``headers_raw`` parameter:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import ytmusicapi
|
||||
ytmusicapi.setup(filepath="browser.json", headers_raw="<headers copied above>")
|
||||
|
||||
The function returns a JSON string with the credentials needed for :doc:`../usage`. Alternatively, if you passed the filepath parameter as described above,
|
||||
a file called ``browser.json`` will be created in the current directory, which you can pass to ``YTMusic()`` for authentication.
|
||||
|
||||
These credentials remain valid as long as your YTMusic browser session is valid (about 2 years unless you log out).
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<details>
|
||||
<summary><a>MacOS special pasting instructions</a></summary>
|
||||
|
||||
.. container::
|
||||
|
||||
- MacOS terminal application can only accept 1024 characters pasted to std input. To paste in terminal, a small utility called pbpaste must be used.
|
||||
- In terminal just prefix the command used to run the script you created above with :kbd:`pbpaste | `
|
||||
- This will pipe the contents of the clipboard into the script just as if you had pasted it from the edit menu.
|
||||
|
||||
.. raw:: html
|
||||
|
||||
</details><br>
|
||||
|
||||
Manual file creation
|
||||
--------------------
|
||||
|
||||
Alternatively, you can create your own file ``browser.json`` and paste the cookie:
|
||||
|
||||
.. literalinclude:: headers_auth.json.example
|
||||
:language: JSON
|
||||
9
docs/source/setup/headers_auth.json.example
Normal file
9
docs/source/setup/headers_auth.json.example
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"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"
|
||||
}
|
||||
24
docs/source/setup/index.rst
Normal file
24
docs/source/setup/index.rst
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
Setup
|
||||
=====
|
||||
|
||||
To install, run:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
pip install ytmusicapi
|
||||
|
||||
|
||||
Further setup is only needed if you want to access account data using authenticated requests.
|
||||
|
||||
The simplest way of authentication is to use :doc:`oauth`.
|
||||
|
||||
However, these OAuth credentials do not work for uploads. If you need to upload music,
|
||||
instead follow the instructions at :doc:`browser`.
|
||||
|
||||
|
||||
|
||||
.. toctree::
|
||||
:caption: Table of Contents
|
||||
|
||||
oauth
|
||||
browser
|
||||
15
docs/source/setup/oauth.rst
Normal file
15
docs/source/setup/oauth.rst
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
OAuth authentication
|
||||
====================
|
||||
|
||||
After you have installed ``ytmusicapi``, simply run
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
ytmusicapi oauth
|
||||
|
||||
and follow the instructions. This will create a file ``oauth.json`` in the current directory.
|
||||
|
||||
You can pass this file to :py:class:`YTMusic` as explained in :doc:`../usage`.
|
||||
|
||||
This OAuth flow uses the
|
||||
`Google API flow for TV devices <https://developers.google.com/youtube/v3/guides/auth/devices>`_.
|
||||
Loading…
Reference in a new issue