Add option to do auth manually on headless server (#88)
This commit is contained in:
@@ -3,6 +3,7 @@ spotify:
|
|||||||
client_secret: your_client_secret
|
client_secret: your_client_secret
|
||||||
username: your_spotify_username
|
username: your_spotify_username
|
||||||
redirect_uri: http://localhost:8888/callback
|
redirect_uri: http://localhost:8888/callback
|
||||||
|
open_browser: True # Set to False if using a headless server environment
|
||||||
|
|
||||||
|
|
||||||
# uncomment this block if you want to only sync specific playlist IDs
|
# uncomment this block if you want to only sync specific playlist IDs
|
||||||
|
|||||||
@@ -15,11 +15,12 @@ SPOTIFY_SCOPES = 'playlist-read-private, user-library-read'
|
|||||||
|
|
||||||
def open_spotify_session(config) -> spotipy.Spotify:
|
def open_spotify_session(config) -> spotipy.Spotify:
|
||||||
credentials_manager = spotipy.SpotifyOAuth(username=config['username'],
|
credentials_manager = spotipy.SpotifyOAuth(username=config['username'],
|
||||||
scope=SPOTIFY_SCOPES,
|
scope=SPOTIFY_SCOPES,
|
||||||
client_id=config['client_id'],
|
client_id=config['client_id'],
|
||||||
client_secret=config['client_secret'],
|
client_secret=config['client_secret'],
|
||||||
redirect_uri=config['redirect_uri'],
|
redirect_uri=config['redirect_uri'],
|
||||||
requests_timeout=2)
|
requests_timeout=2,
|
||||||
|
open_browser=config.get('open_browser', True))
|
||||||
try:
|
try:
|
||||||
credentials_manager.get_access_token(as_dict=False)
|
credentials_manager.get_access_token(as_dict=False)
|
||||||
except spotipy.SpotifyOauthError:
|
except spotipy.SpotifyOauthError:
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ def test_open_spotify_session(mocker):
|
|||||||
"client_id": "test_client_id",
|
"client_id": "test_client_id",
|
||||||
"client_secret": "test_client_secret",
|
"client_secret": "test_client_secret",
|
||||||
"redirect_uri": "http://localhost/",
|
"redirect_uri": "http://localhost/",
|
||||||
|
"open_browser": True,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create a mock SpotifyOAuth instance
|
# Create a mock SpotifyOAuth instance
|
||||||
@@ -41,6 +42,7 @@ def test_open_spotify_session(mocker):
|
|||||||
client_secret="test_client_secret",
|
client_secret="test_client_secret",
|
||||||
redirect_uri="http://localhost/",
|
redirect_uri="http://localhost/",
|
||||||
requests_timeout=2,
|
requests_timeout=2,
|
||||||
|
open_browser=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Assert that the Spotify instance was created
|
# Assert that the Spotify instance was created
|
||||||
|
|||||||
Reference in New Issue
Block a user