Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a438cda72b | ||
|
|
2f1985a42b | ||
|
|
bcf2bbca0d | ||
|
|
457da1724f | ||
|
|
4d7c3b0ef0 |
@@ -3,6 +3,7 @@ spotify:
|
||||
client_secret: your_client_secret
|
||||
username: your_spotify_username
|
||||
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
|
||||
|
||||
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "spotify_to_tidal"
|
||||
version = "1.0.2"
|
||||
version = "1.0.4"
|
||||
requires-python = ">= 3.10"
|
||||
|
||||
dependencies = [
|
||||
|
||||
@@ -15,11 +15,12 @@ SPOTIFY_SCOPES = 'playlist-read-private, user-library-read'
|
||||
|
||||
def open_spotify_session(config) -> spotipy.Spotify:
|
||||
credentials_manager = spotipy.SpotifyOAuth(username=config['username'],
|
||||
scope=SPOTIFY_SCOPES,
|
||||
client_id=config['client_id'],
|
||||
client_secret=config['client_secret'],
|
||||
redirect_uri=config['redirect_uri'],
|
||||
requests_timeout=2)
|
||||
scope=SPOTIFY_SCOPES,
|
||||
client_id=config['client_id'],
|
||||
client_secret=config['client_secret'],
|
||||
redirect_uri=config['redirect_uri'],
|
||||
requests_timeout=2,
|
||||
open_browser=config.get('open_browser', True))
|
||||
try:
|
||||
credentials_manager.get_access_token(as_dict=False)
|
||||
except spotipy.SpotifyOauthError:
|
||||
|
||||
@@ -184,7 +184,8 @@ async def get_tracks_from_spotify_playlist(spotify_session: spotipy.Spotify, spo
|
||||
print(f"Loading tracks from Spotify playlist '{spotify_playlist['name']}'")
|
||||
items = await repeat_on_request_error( _fetch_all_from_spotify_in_chunks, lambda offset: _get_tracks_from_spotify_playlist(offset=offset, playlist_id=spotify_playlist["id"]))
|
||||
track_filter = lambda item: item.get('type', 'track') == 'track' # type may be 'episode' also
|
||||
return list(filter(track_filter, items))
|
||||
sanity_filter = lambda item: 'album' in item and 'name' in item['album'] and 'artists' in item['album'] and len(item['album']['artists']) > 0
|
||||
return list(filter(sanity_filter, filter(track_filter, items)))
|
||||
|
||||
def populate_track_match_cache(spotify_tracks_: Sequence[t_spotify.SpotifyTrack], tidal_tracks_: Sequence[tidalapi.Track]):
|
||||
""" Populate the track match cache with all the existing tracks in Tidal playlist corresponding to Spotify playlist """
|
||||
@@ -386,7 +387,7 @@ async def get_playlists_from_spotify(spotify_session: spotipy.Spotify, config):
|
||||
playlists.extend([p for p in extra_result['items']])
|
||||
|
||||
# filter out playlists that don't belong to us or are on the exclude list
|
||||
my_playlist_filter = lambda p: p['owner']['id'] == user_id
|
||||
my_playlist_filter = lambda p: p and p['owner']['id'] == user_id
|
||||
exclude_filter = lambda p: not p['id'] in exclude_list
|
||||
return list(filter( exclude_filter, filter( my_playlist_filter, playlists )))
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ def test_open_spotify_session(mocker):
|
||||
"client_id": "test_client_id",
|
||||
"client_secret": "test_client_secret",
|
||||
"redirect_uri": "http://localhost/",
|
||||
"open_browser": True,
|
||||
}
|
||||
|
||||
# Create a mock SpotifyOAuth instance
|
||||
@@ -41,6 +42,7 @@ def test_open_spotify_session(mocker):
|
||||
client_secret="test_client_secret",
|
||||
redirect_uri="http://localhost/",
|
||||
requests_timeout=2,
|
||||
open_browser=True,
|
||||
)
|
||||
|
||||
# Assert that the Spotify instance was created
|
||||
|
||||
Reference in New Issue
Block a user