Skip to content

Commit cdd4e38

Browse files
authored
update oauth docs and request interactive input instead of aborting (#694)
* update oauth docs and request interactive input instead of aborting * move input inside oauth path, improve filename output * update oauth.rst
1 parent df1c3bd commit cdd4e38

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

docs/source/setup/oauth.rst

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
OAuth authentication
22
====================
33

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
514

615
.. code-block:: bash
716
@@ -11,5 +20,11 @@ and follow the instructions. This will create a file ``oauth.json`` in the curre
1120

1221
You can pass this file to :py:class:`YTMusic` as explained in :doc:`../usage`.
1322

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+
1429
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>`_.

ytmusicapi/setup.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import argparse
22
import sys
33
from pathlib import Path
4-
from typing import Optional
4+
from typing import Optional, Union
55

66
import requests
77

@@ -72,16 +72,15 @@ def parse_args(args):
7272
return parser.parse_args(args)
7373

7474

75-
def main():
75+
def main() -> Union[RefreshingToken, str]:
7676
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
8277
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...")
8479
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: ")
8584
return setup_oauth(
8685
client_id=args.client_id, client_secret=args.client_secret, filepath=filename, open_browser=True
8786
)

0 commit comments

Comments
 (0)