6 Commits
0.1.1 ... 0.1.3

Author SHA1 Message Date
Tim Rae
0c859cc9aa Bump version to 0.1.3 2024-06-08 12:55:09 +02:00
Tim Rae
bb0f3cffd0 Fix rate limit accuracy
Batching multiple updates to the leaky bucket at a fixed interval
improves the accuracy of the rate limiter. Previously the rate would
drop substantially over the course of the sync operation.
2024-06-08 12:54:27 +02:00
Adria Jimenez
ecc642ba7d fix: sync first playlists page
This commit: 1e8366a0e8 broke the loading of playlists. The first results coming back from the Spotify API were not being added to the playlists array.
2024-06-06 13:33:40 +02:00
Tim Rae
3e9b2ef0ec Update readme.md 2024-06-05 09:22:24 +02:00
Tim Rae
a16f764bee Bump version to 0.1.2 2024-06-03 23:38:21 +02:00
Tim Rae
c1956d19cc Fix bug where occasionally wrong track is inserted 2024-06-03 23:38:21 +02:00
4 changed files with 16 additions and 6 deletions

View File

@@ -16,4 +16,4 @@ spotify:
# increasing these parameters should increase the search speed, while decreasing reduces likelihood of 429 errors
max_concurrency: 10 # max concurrent connections at any given time
rate_limit: 12 # max sustained connections per second
rate_limit: 10 # max sustained connections per second

View File

@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "spotify_to_tidal"
version = "0.1.1"
version = "0.1.3"
requires-python = ">= 3.10"
dependencies = [

View File

@@ -1,4 +1,4 @@
A command line tool for importing your Spotify playlists into Tidal
A command line tool for importing your Spotify playlists into Tidal. Due to various performance optimisations, it is particularly suited for periodic synchronisation of very large collections.
Installation
-----------

View File

@@ -2,6 +2,7 @@
import asyncio
from .cache import failure_cache, track_match_cache
import datetime
from functools import partial
from typing import List, Sequence, Set, Mapping
import math
@@ -85,6 +86,7 @@ def artist_match(tidal_track: tidalapi.Track, spotify_track) -> bool:
return get_tidal_artists(tidal_track, True).intersection(get_spotify_artists(spotify_track, True)) != set()
def match(tidal_track, spotify_track) -> bool:
if not spotify_track['id']: return False
return isrc_match(tidal_track, spotify_track) or (
duration_match(tidal_track, spotify_track)
and name_match(tidal_track, spotify_track)
@@ -214,6 +216,7 @@ def get_tracks_for_new_tidal_playlist(spotify_tracks: Sequence[t_spotify.Spotify
output = []
seen_tracks = set()
for spotify_track in spotify_tracks:
if not spotify_track['id']: continue
tidal_id = track_match_cache.get(spotify_track['id'])
if tidal_id and not tidal_id in seen_tracks:
output.append(tidal_id)
@@ -222,10 +225,16 @@ def get_tracks_for_new_tidal_playlist(spotify_tracks: Sequence[t_spotify.Spotify
async def sync_playlist(spotify_session: spotipy.Spotify, tidal_session: tidalapi.Session, spotify_playlist, tidal_playlist: tidalapi.Playlist | None, config):
async def _run_rate_limiter(semaphore):
''' Leaky bucket algorithm for rate limiting. Periodically releases an item from semaphore at rate_limit'''
''' Leaky bucket algorithm for rate limiting. Periodically releases items from semaphore at rate_limit'''
_sleep_time = config.get('max_concurrency', 10)/config.get('rate_limit', 10)/4 # aim to sleep approx time to drain 1/4 of 'bucket'
t0 = datetime.datetime.now()
while True:
await asyncio.sleep(1/config.get('rate_limit', 12)) # sleep for min time between new function executions
semaphore.release() # leak one item from the 'bucket'
await asyncio.sleep(_sleep_time)
t = datetime.datetime.now()
dt = (t - t0).total_seconds()
new_items = round(config.get('rate_limit', 10)*dt)
t0 = t
[semaphore.release() for i in range(new_items)] # leak new_items from the 'bucket'
# Create a new Tidal playlist if required
if not tidal_playlist:
@@ -294,6 +303,7 @@ async def get_playlists_from_spotify(spotify_session: spotipy.Spotify, config):
print("Loading Spotify playlists")
results = spotify_session.user_playlists(config['spotify']['username'])
exclude_list = set([x.split(':')[-1] for x in config.get('excluded_playlists', [])])
playlists.extend([p for p in results['items'] if p['owner']['id'] == config['spotify']['username'] and not p['id'] in exclude_list])
# get all the remaining playlists in parallel
if results['next']: