diff --git a/spotify_to_ytmusic/settings.ini.example b/spotify_to_ytmusic/settings.ini.example index c55421f..ced616e 100644 --- a/spotify_to_ytmusic/settings.ini.example +++ b/spotify_to_ytmusic/settings.ini.example @@ -5,3 +5,4 @@ user_id = [spotify] client_id = id_from_developer_console client_secret = secret_from_developer_console +use_oauth = no diff --git a/spotify_to_ytmusic/setup.py b/spotify_to_ytmusic/setup.py index 4da5b46..2262760 100644 --- a/spotify_to_ytmusic/setup.py +++ b/spotify_to_ytmusic/setup.py @@ -43,6 +43,7 @@ def setup_spotify(): "Paste your client id from the Spotify developer dashboard:" ), "client_secret": input("Paste your client secret from the Spotify developer dashboard:"), + "use_oauth": input("Use OAuth method for authorization (required for transfer liked songs) yes/no:"), } settings["spotify"].update(credentials) settings.save() diff --git a/spotify_to_ytmusic/spotify.py b/spotify_to_ytmusic/spotify.py index 9377da7..9ccfd3f 100644 --- a/spotify_to_ytmusic/spotify.py +++ b/spotify_to_ytmusic/spotify.py @@ -4,6 +4,7 @@ import spotipy from spotipy.oauth2 import SpotifyClientCredentials +from spotipy.oauth2 import SpotifyOAuth from spotify_to_ytmusic.settings import Settings @@ -22,10 +23,15 @@ def __init__(self): string.hexdigits ), f"Spotify client_secret not set or invalid: {client_secret}" - client_credentials_manager = SpotifyClientCredentials( - client_id=client_id, client_secret=client_secret - ) - self.api = spotipy.Spotify(client_credentials_manager=client_credentials_manager) + use_oauth = conf["use_oauth"] == "y" or conf["use_oauth"] == "yes" + if use_oauth: + auth = SpotifyOAuth(client_id=client_id, client_secret=client_secret, redirect_uri="http://localhost", scope="user-library-read") + self.api = spotipy.Spotify(auth_manager=auth) + else: + client_credentials_manager = SpotifyClientCredentials( + client_id=client_id, client_secret=client_secret + ) + self.api = spotipy.Spotify(client_credentials_manager=client_credentials_manager) def getSpotifyPlaylist(self, url): playlistId = get_id_from_url(url)