working on plex_playlists based on gemini
This commit is contained in:
parent
ce48d867a9
commit
88d1f94748
3 changed files with 142 additions and 96 deletions
|
|
@ -1,7 +1,9 @@
|
|||
# discovery_sync.py
|
||||
|
||||
from config import *
|
||||
from lastfm_helpers import lf_request, recent_artists
|
||||
from lidarr_helpers import lidarr_api_add_artist
|
||||
from musicbrainz_helpers import load_cache, save_cache
|
||||
from lastfm_helpers import recent_artists, get_similar_artists_pylast # Korrekt
|
||||
from lidarr_helpers import lidarr_api_add_artist # Antar att lidarr_helpers bara har denna funktion att exportera
|
||||
from musicbrainz_helpers import load_cache, save_cache # Antar att musicbrainz_helpers bara har dessa funktioner att exportera
|
||||
import time, logging
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
|
@ -14,9 +16,9 @@ def sync():
|
|||
similar_cache = cache.setdefault("similar_cache", {})
|
||||
|
||||
recent = recent_artists()
|
||||
log.info(f"🎧 Analyserar {len(recent)} senaste artister från Last.fm")
|
||||
log.info(f"🎧 Analyzing {len(recent)} recent artists from Last.fm")
|
||||
|
||||
new = 0
|
||||
new_artists_added_count = 0
|
||||
for name, mbid in recent:
|
||||
if not mbid or mbid in added_artists:
|
||||
continue
|
||||
|
|
@ -24,25 +26,25 @@ def sync():
|
|||
if mbid in similar_cache:
|
||||
sims = similar_cache[mbid]["data"]
|
||||
else:
|
||||
js = lf_request("artist.getSimilar", mbid=mbid, limit=MAX_SIMILAR_PER_ART)
|
||||
sims = js.get("similarartists", {}).get("artist", []) if js else []
|
||||
sims = get_similar_artists_pylast(mbid, MAX_SIMILAR_PER_ART)
|
||||
similar_cache[mbid] = {"ts": time.time(), "data": sims}
|
||||
save_cache(cache)
|
||||
|
||||
for sim in sims:
|
||||
sid = sim.get("mbid")
|
||||
match = float(sim.get("match", 0))
|
||||
if not sid or sid in added_artists or match < SIMILAR_MATCH_MIN:
|
||||
for sim_artist_obj, match in sims:
|
||||
sid = sim_artist_obj.mbid
|
||||
match_float = float(match)
|
||||
|
||||
if not sid or sid in added_artists or match_float < SIMILAR_MATCH_MIN:
|
||||
continue
|
||||
|
||||
log.info(f"✨ Ny artist: {sim.get('name')} (match {match:.2f})")
|
||||
log.info(f"✨ New artist: {sim_artist_obj.name} (match {match_float:.2f})")
|
||||
if lidarr_api_add_artist(sid):
|
||||
added_artists.add(sid)
|
||||
new += 1
|
||||
new_artists_added_count += 1
|
||||
cache["added_artists"] = list(added_artists)
|
||||
save_cache(cache)
|
||||
|
||||
log.info(f"✅ Klar! {new} nya artister tillagda på {((time.time()-start)/60):.1f} min")
|
||||
log.info(f"✅ Done! {new_artists_added_count} new artists added in {((time.time()-start)/60):.1f} min")
|
||||
|
||||
if __name__ == "__main__":
|
||||
sync()
|
||||
sync()
|
||||
Loading…
Add table
Add a link
Reference in a new issue