This commit is contained in:
2026-04-14 15:59:02 +02:00
parent d4356e7337
commit 287477753e
4 changed files with 85 additions and 21 deletions

View File

@@ -30,6 +30,7 @@ class SongData(BaseModel):
bpm: int = 0
duration_sec: int = 0
file_format: str = ""
mbid: str = ""
class DanceData(BaseModel):
name: str
@@ -97,22 +98,30 @@ def push(
for s in payload.songs:
if not s.title:
continue
# Match globalt på titel+artist — samme sang deles på tværs af brugere
existing = db.query(Song).filter(
Song.title == s.title,
Song.artist == s.artist,
).first()
# Match 1: MBID — sikrest
existing = None
if s.mbid:
existing = db.query(Song).filter_by(mbid=s.mbid).first()
# Match 2: titel+artist globalt
if not existing:
existing = db.query(Song).filter(
Song.title == s.title,
Song.artist == s.artist,
).first()
if existing:
song_id_map[s.local_id] = existing.id
# Opdater BPM hvis det mangler
# Opdater BPM og MBID hvis de mangler
if s.bpm and not existing.bpm:
existing.bpm = s.bpm
if s.mbid and not existing.mbid:
existing.mbid = s.mbid
else:
song = Song(
owner_id=me.id,
title=s.title, artist=s.artist, album=s.album,
bpm=s.bpm, duration_sec=s.duration_sec,
file_format=s.file_format,
mbid=s.mbid or None,
)
db.add(song)
db.flush()