Frontend : filtres

This commit is contained in:
2025-12-22 15:53:26 +01:00
parent b0ba1e886c
commit 6c47f0760e
5 changed files with 351 additions and 10 deletions

View File

@@ -22,6 +22,9 @@ async def get_tracks(
energy_min: Optional[float] = Query(None, ge=0, le=1),
energy_max: Optional[float] = Query(None, ge=0, le=1),
has_vocals: Optional[bool] = None,
key: Optional[str] = None,
instrument: Optional[str] = None,
tempo_range: Optional[str] = Query(None, regex="^(slow|medium|fast)$"),
sort_by: str = Query("analyzed_at", regex="^(analyzed_at|tempo_bpm|duration_seconds|filename|energy)$"),
sort_desc: bool = True,
db: Session = Depends(get_db),
@@ -38,6 +41,9 @@ async def get_tracks(
energy_min: Minimum energy
energy_max: Maximum energy
has_vocals: Filter by vocal presence
key: Filter by musical key
instrument: Filter by instrument
tempo_range: Filter by tempo range (slow: <100, medium: 100-140, fast: >140)
sort_by: Field to sort by
sort_desc: Sort descending
db: Database session
@@ -45,6 +51,16 @@ async def get_tracks(
Returns:
Paginated list of tracks with total count
"""
# Convert tempo_range to bpm_min/bpm_max
if tempo_range:
if tempo_range == "slow":
bpm_max = 100.0 if bpm_max is None else min(bpm_max, 100.0)
elif tempo_range == "medium":
bpm_min = 100.0 if bpm_min is None else max(bpm_min, 100.0)
bpm_max = 140.0 if bpm_max is None else min(bpm_max, 140.0)
elif tempo_range == "fast":
bpm_min = 140.0 if bpm_min is None else max(bpm_min, 140.0)
tracks, total = crud.get_tracks(
db=db,
skip=skip,
@@ -56,6 +72,8 @@ async def get_tracks(
energy_min=energy_min,
energy_max=energy_max,
has_vocals=has_vocals,
key=key,
instrument=instrument,
sort_by=sort_by,
sort_desc=sort_desc,
)