From 0ab8e13a7f8d0293a2d6761d8e31612435d2c6f9 Mon Sep 17 00:00:00 2001 From: rpop0 <38384209+rpop0@users.noreply.github.com> Date: Sat, 16 Nov 2024 00:56:02 +0200 Subject: [PATCH] feat: Add ytmusicapi browser auth setup option Added doc for browser auth --- spotify_to_ytmusic/setup.py | 14 ++++++++++++-- tests/test_cli.py | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/spotify_to_ytmusic/setup.py b/spotify_to_ytmusic/setup.py index 1426c37..fbb955f 100644 --- a/spotify_to_ytmusic/setup.py +++ b/spotify_to_ytmusic/setup.py @@ -17,8 +17,9 @@ def setup(file: Optional[Path] = None): if not DEFAULT_PATH.is_file(): shutil.copy(EXAMPLE_PATH, DEFAULT_PATH) - choice = input("Choose which API to set up\n" "(1) Spotify\n" "(2) YouTube\n" "(3) both\n") - choices = ["1", "2", "3"] + choice = input("Choose which API to set up\n(1) Spotify\n(2) YouTube (oAuth)\n(3) Youtube (Browser)\n(4) both \n") + + choices = ["1", "2", "3", "4"] if choice not in choices: sys.exit("Invalid choice") @@ -27,6 +28,8 @@ def setup(file: Optional[Path] = None): elif choice == choices[1]: setup_youtube() elif choice == choices[2]: + setup_youtube_browser() + elif choice == choices[3]: setup_spotify() setup_youtube() @@ -37,6 +40,13 @@ def setup_youtube(): settings["youtube"]["headers"] = json.dumps(credentials.as_dict()) settings.save() +def setup_youtube_browser(): + settings = Settings() + print('Please see https://ytmusicapi.readthedocs.io/en/stable/setup/browser.html for instructions.') + credentials = ytmusicapi.setup() + settings["youtube"]["headers"] = credentials + settings.save + def setup_spotify(): settings = Settings() diff --git a/tests/test_cli.py b/tests/test_cli.py index 78d719f..98d34ff 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -60,7 +60,7 @@ def test_setup(self): tmp_path = DEFAULT_PATH.with_suffix(".tmp") with ( mock.patch("sys.argv", ["", "setup"]), - mock.patch("builtins.input", side_effect=["3", "a", "b", "yes", ""]), + mock.patch("builtins.input", side_effect=["4", "a", "b", "yes", ""]), mock.patch( "ytmusicapi.auth.oauth.credentials.OAuthCredentials.token_from_code", return_value=json.loads(Settings()["youtube"]["headers"]),