From 461783f7191cd3e3c7d2e8e1e3d930ea0f491a47 Mon Sep 17 00:00:00 2001 From: sigma67 Date: Wed, 5 Apr 2023 23:23:11 +0200 Subject: [PATCH] update docs --- README.rst | 2 +- docs/source/conf.py | 4 -- docs/source/faq.rst | 2 +- docs/source/index.rst | 9 +--- docs/source/reference.rst | 8 ++-- docs/source/{setup.rst => setup/browser.rst} | 42 +++++++++---------- .../{ => setup}/headers_auth.json.example | 0 docs/source/setup/index.rst | 24 +++++++++++ docs/source/setup/oauth.rst | 15 +++++++ docs/source/usage.rst | 6 +-- 10 files changed, 69 insertions(+), 43 deletions(-) rename docs/source/{setup.rst => setup/browser.rst} (69%) rename docs/source/{ => setup}/headers_auth.json.example (100%) create mode 100644 docs/source/setup/index.rst create mode 100644 docs/source/setup/oauth.rst diff --git a/README.rst b/README.rst index 90d026b..04955e3 100644 --- a/README.rst +++ b/README.rst @@ -72,7 +72,7 @@ Usage from ytmusicapi import YTMusic - yt = YTMusic('headers_auth.json') + yt = YTMusic('oauth.json') playlistId = yt.create_playlist('test', 'test description') search_results = yt.search('Oasis Wonderwall') yt.add_playlist_items(playlistId, [search_results[0]['videoId']]) diff --git a/docs/source/conf.py b/docs/source/conf.py index 6610745..88c05c1 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -68,7 +68,3 @@ else: # Set theme to 'default' for ReadTheDocs. 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'] diff --git a/docs/source/faq.rst b/docs/source/faq.rst index 73a03b1..015ee6a 100644 --- a/docs/source/faq.rst +++ b/docs/source/faq.rst @@ -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? -*********************************************************************** +********************************************************************************* 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 indicates the server-side pagination increment. ytmusicapi will keep fetching continuations from the server until it has diff --git a/docs/source/index.rst b/docs/source/index.rst index ef8fcb6..f30b893 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -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 ================================================== The purpose of this library is to automate interactions with `YouTube Music `_, @@ -15,7 +10,7 @@ To achieve this, it emulates web requests that would occur if you performed the :start-after: features :end-before: end-features -To **get started**, read the :doc:`setup instructions `. +To **get started**, read the :doc:`setup instructions `. For a **complete documentation** of available functions, see the :doc:`Reference `. @@ -29,7 +24,7 @@ Contents .. toctree:: - setup + setup/index usage reference faq diff --git a/docs/source/reference.rst b/docs/source/reference.rst index c3e277c..09f145a 100644 --- a/docs/source/reference.rst +++ b/docs/source/reference.rst @@ -1,19 +1,19 @@ Reference ================== - - Reference for the YTMusic class. .. currentmodule:: ytmusicapi .. autoclass:: YTMusic .. automethod:: YTMusic.__init__ + Setup ----- -See also the :doc:`Setup ` page +See also the :doc:`Setup ` page -.. automethod:: YTMusic.setup +.. autofunction:: setup +.. autofunction:: setup_oauth Search ------ diff --git a/docs/source/setup.rst b/docs/source/setup/browser.rst similarity index 69% rename from docs/source/setup.rst rename to docs/source/setup/browser.rst index 82db098..e08ae0c 100644 --- a/docs/source/setup.rst +++ b/docs/source/setup/browser.rst @@ -1,17 +1,12 @@ -Setup -===== +Browser authentication +====================== -Installation ------------- -.. code-block:: bash - - pip install ytmusicapi - -Authenticated requests ----------------------- +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: @@ -51,24 +46,25 @@ To do so, follow these steps:
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 - YTMusic.setup(filepath="headers_auth.json") + 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 - from ytmusicapi import YTMusic - YTMusic.setup(filepath="headers_auth.json", headers_raw="") - -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. + import ytmusicapi + ytmusicapi.setup(filepath="browser.json", headers_raw="") + +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). @@ -80,7 +76,7 @@ These credentials remain valid as long as your YTMusic browser session is valid .. 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 ``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. .. raw:: html @@ -90,7 +86,7 @@ These credentials remain valid as long as your YTMusic browser session is valid 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 :language: JSON diff --git a/docs/source/headers_auth.json.example b/docs/source/setup/headers_auth.json.example similarity index 100% rename from docs/source/headers_auth.json.example rename to docs/source/setup/headers_auth.json.example diff --git a/docs/source/setup/index.rst b/docs/source/setup/index.rst new file mode 100644 index 0000000..056bfdf --- /dev/null +++ b/docs/source/setup/index.rst @@ -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 \ No newline at end of file diff --git a/docs/source/setup/oauth.rst b/docs/source/setup/oauth.rst new file mode 100644 index 0000000..62e6bbd --- /dev/null +++ b/docs/source/setup/oauth.rst @@ -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 `_. \ No newline at end of file diff --git a/docs/source/usage.rst b/docs/source/usage.rst index e28b22e..0ba69a5 100644 --- a/docs/source/usage.rst +++ b/docs/source/usage.rst @@ -17,14 +17,14 @@ If an endpoint requires authentication you will receive an error: Authenticated ------------- -For authenticated requests you need to set up your credentials first: :doc:`Setup ` +For authenticated requests you need to set up your credentials first: :doc:`Setup ` After you have created the authentication JSON, you can instantiate the class: .. code-block:: python from ytmusicapi import YTMusic - ytmusic = YTMusic('headers_auth.json') + ytmusic = YTMusic("oauth.json") With the :code:`ytmusic` instance you can now perform authenticated requests: @@ -47,6 +47,6 @@ Example: .. code-block:: python from ytmusicapi import YTMusic - ytmusic = YTMusic('headers_auth.json', "101234161234936123473") + ytmusic = YTMusic("oauth.json", "101234161234936123473")