File: usage.rst

package info (click to toggle)
python-ytmusicapi 1.10.2-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,412 kB
  • sloc: python: 4,324; sh: 14; makefile: 12
file content (53 lines) | stat: -rw-r--r-- 1,566 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Usage
=======

Unauthenticated
---------------
Unauthenticated requests for retrieving playlist content or searching:

.. code-block:: python

    from ytmusicapi import YTMusic

    ytmusic = YTMusic()


If an endpoint requires authentication you will receive an error:
``Please provide authentication before using this function``

Authenticated
-------------
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:

.. code-block:: python

    from ytmusicapi import YTMusic, OAuthCredentials
    ytmusic = YTMusic("browser.json") # or, alternatively
    ytmusic = YTMusic("oauth.json", oauth_credentials=OAuthCredentials(client_id=client_id, client_secret=client_secret)


With the :code:`ytmusic` instance you can now perform authenticated requests:

.. code-block:: python

    playlistId = ytmusic.create_playlist("test", "test description")
    search_results = ytmusic.search("Oasis Wonderwall")
    ytmusic.add_playlist_items(playlistId, [search_results[0]['videoId']])

Brand accounts
##############
To send requests as a brand account, there is no need to change authentication credentials.
Simply provide the ID of the brand account when instantiating YTMusic.
You can get the ID from https://myaccount.google.com/ after selecting your brand account
(https://myaccount.google.com/b/21_digit_number).

Example:

.. code-block:: python

    from ytmusicapi import YTMusic
    ytmusic = YTMusic("oauth.json", "101234161234936123473")