File tree Expand file tree Collapse file tree 2 files changed +24
-10
lines changed Expand file tree Collapse file tree 2 files changed +24
-10
lines changed Original file line number Diff line number Diff line change 1
1
OAuth authentication
2
2
====================
3
3
4
- After you have installed ``ytmusicapi ``, simply run
4
+ .. attention ::
5
+
6
+ As of November 2024, YouTube Music requires a Client Id and Secret for the YouTube Data API to connect to the API.
7
+
8
+ Go to the `YouTube Data API docs <https://developers.google.com/youtube/registering_an_application >`_ to
9
+ obtain the credentials. This requires a Google Cloud Console account and project.
10
+
11
+ For your new credentials, select ``OAuth client ID `` and pick ``TVs and Limited Input devices ``.
12
+
13
+ After you have installed ``ytmusicapi ``, run
5
14
6
15
.. code-block :: bash
7
16
@@ -11,5 +20,11 @@ and follow the instructions. This will create a file ``oauth.json`` in the curre
11
20
12
21
You can pass this file to :py:class: `YTMusic ` as explained in :doc: `../usage `.
13
22
23
+ You will also need to pass ``client_id `` and ``client_secret `` to :py:class: `YTMusic `:
24
+
25
+ .. code-block ::
26
+
27
+ ytmusic = YTMusic('oauth.json', oauth_credentials=OAuthCredentials(client_id=client_id, client_secret=client_secret)
28
+
14
29
This OAuth flow uses the
15
- `Google API flow for TV devices <https://developers.google.com/youtube/v3/guides/auth/devices >`_.
30
+ `Google API flow for TV devices <https://developers.google.com/youtube/v3/guides/auth/devices >`_.
Original file line number Diff line number Diff line change 1
1
import argparse
2
2
import sys
3
3
from pathlib import Path
4
- from typing import Optional
4
+ from typing import Optional , Union
5
5
6
6
import requests
7
7
@@ -72,16 +72,15 @@ def parse_args(args):
72
72
return parser .parse_args (args )
73
73
74
74
75
- def main ():
75
+ def main () -> Union [ RefreshingToken , str ] :
76
76
args = parse_args (sys .argv [1 :])
77
- if args .setup_type == "oauth" and (args .client_id is None or args .client_secret is None ):
78
- print (
79
- "You have to supply both your Google Youtube API client ID and client secret to create a valid oauth token."
80
- )
81
- return
82
77
filename = args .file .as_posix () if args .file else f"{ args .setup_type } .json"
83
- print (f"Creating { filename } with your authentication credentials..." )
78
+ print (f"Creating { Path ( filename ). as_uri () } with your authentication credentials..." )
84
79
if args .setup_type == "oauth" :
80
+ if args .client_id is None :
81
+ args .client_id = input ("Enter your Google Youtube Data API client ID: " )
82
+ if args .client_secret is None :
83
+ args .client_secret = input ("Enter your Google Youtube Data API client secret: " )
85
84
return setup_oauth (
86
85
client_id = args .client_id , client_secret = args .client_secret , filepath = filename , open_browser = True
87
86
)
You can’t perform that action at this time.
0 commit comments