Skip to content

Commit

Permalink
feat: Add ytmusicapi browser auth setup option
Browse files Browse the repository at this point in the history
  • Loading branch information
rpop0 committed Nov 15, 2024
1 parent f2f0b25 commit d441110
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions spotify_to_ytmusic/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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()

Expand All @@ -37,6 +40,12 @@ def setup_youtube():
settings["youtube"]["headers"] = json.dumps(credentials.as_dict())
settings.save()

def setup_youtube_browser():
settings = Settings()
credentials = ytmusicapi.setup()
settings["youtube"]["headers"] = credentials
settings.save


def setup_spotify():
settings = Settings()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]),
Expand Down

0 comments on commit d441110

Please sign in to comment.