Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ requires-python = ">= 3.10"

dependencies = [
"spotipy~=2.24.0",
"tidalapi==0.7.6",
"tidalapi==0.8.6",
"pyyaml~=6.0",
"tqdm~=4.64",
"sqlalchemy~=2.0",
Expand Down
21 changes: 17 additions & 4 deletions src/spotify_to_tidal/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ def test_album_similarity(spotify_album, tidal_album, threshold=0.6):
return SequenceMatcher(None, simple(spotify_album['name']), simple(tidal_album.name)).ratio() >= threshold and artist_match(tidal_album, spotify_album)

async def tidal_search(spotify_track, rate_limiter, tidal_session: tidalapi.Session) -> tidalapi.Track | None:
def _search_for_isrc_track():
if "isrc" in spotify_track["external_ids"]:
try:
for track in tidal_session.get_tracks_by_isrc(spotify_track["external_ids"]["isrc"]):
if match(track, spotify_track):
failure_cache.remove_match_failure(spotify_track['id'])
return track
except tidalapi.exceptions.ObjectNotFound:
return None

def _search_for_track_in_album():
# search for album name and first album artist
if 'album' in spotify_track and 'artists' in spotify_track['album'] and len(spotify_track['album']['artists']):
Expand All @@ -123,6 +133,10 @@ def _search_for_standalone_track():
failure_cache.remove_match_failure(spotify_track['id'])
return track
await rate_limiter.acquire()
isrc_search = await asyncio.to_thread( _search_for_isrc_track )
if isrc_search:
return isrc_search
await rate_limiter.acquire()
album_search = await asyncio.to_thread( _search_for_track_in_album )
if album_search:
return album_search
Expand Down Expand Up @@ -239,7 +253,7 @@ def get_tracks_for_new_tidal_playlist(spotify_tracks: Sequence[t_spotify.Spotify
if tidal_id in seen_tracks:
track_name = spotify_track['name']
artist_names = ', '.join([artist['name'] for artist in spotify_track['artists']])
print(f'Duplicate found: Track "{track_name}" by {artist_names} will be ignored')
print(f'Duplicate found: Track "{track_name}" by {artist_names} will be ignored')
else:
output.append(tidal_id)
seen_tracks.add(tidal_id)
Expand Down Expand Up @@ -285,7 +299,7 @@ async def _run_rate_limiter(semaphore):
for song in song404:
file.write(f"{song}\n")


async def sync_playlist(spotify_session: spotipy.Spotify, tidal_session: tidalapi.Session, spotify_playlist, tidal_playlist: tidalapi.Playlist | None, config: dict):
""" sync given playlist to tidal """
# Get the tracks from both Spotify and Tidal, creating a new Tidal playlist if necessary
Expand Down Expand Up @@ -319,7 +333,7 @@ async def sync_playlist(spotify_session: spotipy.Spotify, tidal_session: tidalap
async def sync_favorites(spotify_session: spotipy.Spotify, tidal_session: tidalapi.Session, config: dict):
""" sync user favorites to tidal """
async def get_tracks_from_spotify_favorites() -> List[dict]:
_get_favorite_tracks = lambda offset: spotify_session.current_user_saved_tracks(offset=offset)
_get_favorite_tracks = lambda offset: spotify_session.current_user_saved_tracks(offset=offset)
tracks = await repeat_on_request_error( _fetch_all_from_spotify_in_chunks, _get_favorite_tracks)
tracks.reverse()
return tracks
Expand Down Expand Up @@ -413,4 +427,3 @@ def get_playlist_ids(config):
raise e
output.append((spotify_playlist, tidal_playlist))
return output