diff --git a/core/beatport.py b/core/beatport.py index addb705..890c6e1 100644 --- a/core/beatport.py +++ b/core/beatport.py @@ -7,6 +7,31 @@ Vedi docs/superpowers/specs/2026-07-14-beatport-charts-design.md. from __future__ import annotations +from dataclasses import dataclass + + +@dataclass(frozen=True) +class BeatportTrack: + position: int + title: str + mix: str # es. "Extended Mix", "Original Mix", "" + artists: str # es. "A, B & C" già formattato + duration_sec: int + beatport_id: int + + @property + def display(self) -> str: + """Formato testo compatibile coi file .txt curati a mano: + 'Artista – Titolo (Mix) (M:SS)'.""" + m, s = divmod(self.duration_sec, 60) + return f"{self.artists} – {self.title} ({self.mix}) ({m}:{s:02d})" + + @property + def spotify_query(self) -> str: + """Query pura per la search Spotify (senza mix name, che disturba + il matching su titoli tipo 'Extended Mix').""" + return f"{self.artists} {self.title}" + # Mappa slug URL Beatport -> (numeric_id, display_name) # Enumerata via scripts/refresh_beatport_genres.py (Task 1). diff --git a/tests/test_beatport.py b/tests/test_beatport.py index b68dd40..fb4ddd5 100644 --- a/tests/test_beatport.py +++ b/tests/test_beatport.py @@ -27,3 +27,42 @@ class TestListGenres: result = beatport.list_genres() slugs = [g["slug"] for g in result] assert "melodic-house-techno" in slugs + + +class TestBeatportTrack: + def test_display_format(self): + t = beatport.BeatportTrack( + position=1, + title="Hot Sauce", + mix="Extended", + artists="Kapuchon, Miss Monique & GLZ", + duration_sec=336, + beatport_id=12345, + ) + assert t.display == "Kapuchon, Miss Monique & GLZ – Hot Sauce (Extended) (5:36)" + + def test_display_pads_seconds(self): + t = beatport.BeatportTrack( + position=1, title="X", mix="Y", artists="A", + duration_sec=65, beatport_id=1, + ) + assert t.display.endswith("(1:05)") + + def test_spotify_query(self): + t = beatport.BeatportTrack( + position=1, + title="Hot Sauce", + mix="Extended", + artists="Kapuchon, Miss Monique & GLZ", + duration_sec=336, + beatport_id=12345, + ) + assert t.spotify_query == "Kapuchon, Miss Monique & GLZ Hot Sauce" + + def test_is_frozen(self): + t = beatport.BeatportTrack( + position=1, title="X", mix="Y", artists="A", + duration_sec=1, beatport_id=1, + ) + with pytest.raises(Exception): + t.title = "Z" # frozen=True impedisce mutazione