update docs

This commit is contained in:
sigma67 2023-04-05 23:23:11 +02:00 • committed by sigma67
commit 461783f719
10 changed files with 69 additions and 43 deletions

View file

@ -72,7 +72,7 @@ Usage
from ytmusicapi import YTMusic from ytmusicapi import YTMusic
yt = YTMusic('headers_auth.json') yt = YTMusic('oauth.json')
playlistId = yt.create_playlist('test', 'test description') playlistId = yt.create_playlist('test', 'test description')
search_results = yt.search('Oasis Wonderwall') search_results = yt.search('Oasis Wonderwall')
yt.add_playlist_items(playlistId, [search_results[0]['videoId']]) yt.add_playlist_items(playlistId, [search_results[0]['videoId']])

View file

@ -68,7 +68,3 @@ else:
# Set theme to 'default' for ReadTheDocs. # Set theme to 'default' for ReadTheDocs.
html_theme = 'default' html_theme = 'default'
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

View file

@ -74,7 +74,7 @@ A ``browseId`` is an internal, globally unique identifier used by YouTube Music
Why is ytmusicapi returning more results than requested with the limit parameter? Why is ytmusicapi returning more results than requested with the limit parameter?
*********************************************************************** *********************************************************************************
YouTube Music always returns increments of a specific pagination value, usually between 20 and 100 items at a time. YouTube Music always returns increments of a specific pagination value, usually between 20 and 100 items at a time.
This is the case if a ytmusicapi method supports the ``limit`` parameter. The default value of the ``limit`` parameter This is the case if a ytmusicapi method supports the ``limit`` parameter. The default value of the ``limit`` parameter
indicates the server-side pagination increment. ytmusicapi will keep fetching continuations from the server until it has indicates the server-side pagination increment. ytmusicapi will keep fetching continuations from the server until it has

View file

@ -1,8 +1,3 @@
.. ytmusicapi documentation master file, created by
sphinx-quickstart on Fri Feb 21 12:48:31 2020.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
ytmusicapi: Unofficial API for YouTube Music ytmusicapi: Unofficial API for YouTube Music
================================================== ==================================================
The purpose of this library is to automate interactions with `YouTube Music <https://music.youtube.com/>`_, The purpose of this library is to automate interactions with `YouTube Music <https://music.youtube.com/>`_,
@ -15,7 +10,7 @@ To achieve this, it emulates web requests that would occur if you performed the
:start-after: features :start-after: features
:end-before: end-features :end-before: end-features
To **get started**, read the :doc:`setup instructions <setup>`. To **get started**, read the :doc:`setup instructions <setup/index>`.
For a **complete documentation** of available functions, see the :doc:`Reference <reference>`. For a **complete documentation** of available functions, see the :doc:`Reference <reference>`.
@ -29,7 +24,7 @@ Contents
.. toctree:: .. toctree::
setup setup/index
usage usage
reference reference
faq faq

View file

@ -1,19 +1,19 @@
Reference Reference
================== ==================
Reference for the YTMusic class. Reference for the YTMusic class.
.. currentmodule:: ytmusicapi .. currentmodule:: ytmusicapi
.. autoclass:: YTMusic .. autoclass:: YTMusic
.. automethod:: YTMusic.__init__ .. automethod:: YTMusic.__init__
Setup Setup
----- -----
See also the :doc:`Setup <setup>` page See also the :doc:`Setup <setup/index>` page
.. automethod:: YTMusic.setup .. autofunction:: setup
.. autofunction:: setup_oauth
Search Search
------ ------

View file

@ -1,17 +1,12 @@
Setup Browser authentication
===== ======================
Installation 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
.. code-block:: bash to a ``ytmusicapi`` configuration file.
pip install ytmusicapi
Authenticated requests
----------------------
Copy authentication headers 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 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: To do so, follow these steps:
@ -51,24 +46,25 @@ To do so, follow these steps:
</details><br> </details><br>
Using the headers in your project 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: To set up your project, open a console and call
.. code-block:: python .. code-block:: bash
from ytmusicapi import YTMusic ytmusicapi browser
YTMusic.setup(filepath="headers_auth.json")
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: 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 import ytmusicapi
YTMusic.setup(filepath="headers_auth.json", headers_raw="<headers copied above>") ytmusicapi.setup(filepath="browser.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`. 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 ``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). These credentials remain valid as long as your YTMusic browser session is valid (about 2 years unless you log out).
@ -80,7 +76,7 @@ These credentials remain valid as long as your YTMusic browser session is valid
.. container:: .. 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. - 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 ``pbpaste | `` - 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. - This will pipe the contents of the clipboard into the script just as if you had pasted it from the edit menu.
.. raw:: html .. raw:: html
@ -90,7 +86,7 @@ These credentials remain valid as long as your YTMusic browser session is valid
Manual file creation Manual file creation
-------------------- --------------------
Alternatively, you can paste the cookie to ``headers_auth.json`` below and create your own file: Alternatively, you can create your own file ``browser.json`` and paste the cookie:
.. literalinclude:: headers_auth.json.example .. literalinclude:: headers_auth.json.example
:language: JSON :language: JSON

View 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

View 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>`_.

View file

@ -17,14 +17,14 @@ If an endpoint requires authentication you will receive an error:
Authenticated Authenticated
------------- -------------
For authenticated requests you need to set up your credentials first: :doc:`Setup <setup>` For authenticated requests you need to set up your credentials first: :doc:`Setup <setup/index>`
After you have created the authentication JSON, you can instantiate the class: After you have created the authentication JSON, you can instantiate the class:
.. code-block:: python .. code-block:: python
from ytmusicapi import YTMusic from ytmusicapi import YTMusic
ytmusic = YTMusic('headers_auth.json') ytmusic = YTMusic("oauth.json")
With the :code:`ytmusic` instance you can now perform authenticated requests: With the :code:`ytmusic` instance you can now perform authenticated requests:
@ -47,6 +47,6 @@ Example:
.. code-block:: python .. code-block:: python
from ytmusicapi import YTMusic from ytmusicapi import YTMusic
ytmusic = YTMusic('headers_auth.json', "101234161234936123473") ytmusic = YTMusic("oauth.json", "101234161234936123473")