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
This commit is contained in:
parent
df1c3bdd5b
commit
cdd4e38a57
2 changed files with 24 additions and 10 deletions
|
|
@ -1,7 +1,16 @@
|
||||||
OAuth authentication
|
OAuth authentication
|
||||||
====================
|
====================
|
||||||
|
|
||||||
After you have installed ``ytmusicapi``, simply run
|
.. attention::
|
||||||
|
|
||||||
|
As of November 2024, YouTube Music requires a Client Id and Secret for the YouTube Data API to connect to the API.
|
||||||
|
|
||||||
|
Go to the `YouTube Data API docs <https://developers.google.com/youtube/registering_an_application>`_ to
|
||||||
|
obtain the credentials. This requires a Google Cloud Console account and project.
|
||||||
|
|
||||||
|
For your new credentials, select ``OAuth client ID`` and pick ``TVs and Limited Input devices``.
|
||||||
|
|
||||||
|
After you have installed ``ytmusicapi``, run
|
||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
|
|
@ -11,5 +20,11 @@ and follow the instructions. This will create a file ``oauth.json`` in the curre
|
||||||
|
|
||||||
You can pass this file to :py:class:`YTMusic` as explained in :doc:`../usage`.
|
You can pass this file to :py:class:`YTMusic` as explained in :doc:`../usage`.
|
||||||
|
|
||||||
|
You will also need to pass ``client_id`` and ``client_secret`` to :py:class:`YTMusic`:
|
||||||
|
|
||||||
|
.. code-block::
|
||||||
|
|
||||||
|
ytmusic = YTMusic('oauth.json', oauth_credentials=OAuthCredentials(client_id=client_id, client_secret=client_secret)
|
||||||
|
|
||||||
This OAuth flow uses the
|
This OAuth flow uses the
|
||||||
`Google API flow for TV devices <https://developers.google.com/youtube/v3/guides/auth/devices>`_.
|
`Google API flow for TV devices <https://developers.google.com/youtube/v3/guides/auth/devices>`_.
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional
|
from typing import Optional, Union
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
|
@ -72,16 +72,15 @@ def parse_args(args):
|
||||||
return parser.parse_args(args)
|
return parser.parse_args(args)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main() -> Union[RefreshingToken, str]:
|
||||||
args = parse_args(sys.argv[1:])
|
args = parse_args(sys.argv[1:])
|
||||||
if args.setup_type == "oauth" and (args.client_id is None or args.client_secret is None):
|
|
||||||
print(
|
|
||||||
"You have to supply both your Google Youtube API client ID and client secret to create a valid oauth token."
|
|
||||||
)
|
|
||||||
return
|
|
||||||
filename = args.file.as_posix() if args.file else f"{args.setup_type}.json"
|
filename = args.file.as_posix() if args.file else f"{args.setup_type}.json"
|
||||||
print(f"Creating {filename} with your authentication credentials...")
|
print(f"Creating {Path(filename).as_uri()} with your authentication credentials...")
|
||||||
if args.setup_type == "oauth":
|
if args.setup_type == "oauth":
|
||||||
|
if args.client_id is None:
|
||||||
|
args.client_id = input("Enter your Google Youtube Data API client ID: ")
|
||||||
|
if args.client_secret is None:
|
||||||
|
args.client_secret = input("Enter your Google Youtube Data API client secret: ")
|
||||||
return setup_oauth(
|
return setup_oauth(
|
||||||
client_id=args.client_id, client_secret=args.client_secret, filepath=filename, open_browser=True
|
client_id=args.client_id, client_secret=args.client_secret, filepath=filename, open_browser=True
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue