Debian Codegraph @

docs/source/usage.rst

raw
1 Usage
2 =======
3
4 Unauthenticated
5 ---------------
6 Unauthenticated requests for retrieving playlist content or searching:
7
8 .. code-block:: python
9
10 from ytmusicapi import YTMusic
11
12 ytmusic = YTMusic()
13
14
15 If an endpoint requires authentication you will receive an error:
16 ``Please provide authentication before using this function``
17
18 Authenticated
19 -------------
20 For authenticated requests you need to set up your credentials first: :doc:`Setup <setup/index>`
21
22 After you have created the authentication JSON, you can instantiate the class:
23
24 .. code-block:: python
25
26 from ytmusicapi import YTMusic, OAuthCredentials
27 ytmusic = YTMusic("browser.json") # or, alternatively
28 ytmusic = YTMusic("oauth.json", oauth_credentials=OAuthCredentials(client_id=client_id, client_secret=client_secret)
29
30
31 With the :code:`ytmusic` instance you can now perform authenticated requests:
32
33 .. code-block:: python
34
35 playlistId = ytmusic.create_playlist("test", "test description")
36 search_results = ytmusic.search("Oasis Wonderwall")
37 ytmusic.add_playlist_items(playlistId, [search_results[0]['videoId']])
38
39 Brand accounts
40 ##############
41 To send requests as a brand account, there is no need to change authentication credentials.
42 Simply provide the ID of the brand account when instantiating YTMusic.
43 You can get the ID from https://myaccount.google.com/ after selecting your brand account
44 (https://myaccount.google.com/b/21_digit_number).
45
46 Example:
47
48 .. code-block:: python
49
50 from ytmusicapi import YTMusic
51 ytmusic = YTMusic("oauth.json", "101234161234936123473")
52
53