A kind of initial commit

This commit is contained in:
heboba
2026-02-26 19:33:05 +00:00
commit 9ab125b1a6
37 changed files with 3053 additions and 0 deletions

0
app/utils/__init__.py Normal file
View File

14
app/utils/text.py Normal file
View File

@@ -0,0 +1,14 @@
from __future__ import annotations
import re
_WS_RE = re.compile(r"\s+")
_FEAT_RE = re.compile(r"\s*[\(\[\-–—]\s*(feat|ft)\.?.*$", re.IGNORECASE)
def normalize_track_signature(name: str, artists: list[str]) -> str:
clean_name = _FEAT_RE.sub("", name).strip().lower()
clean_name = _WS_RE.sub(" ", clean_name)
clean_artists = ",".join(sorted(a.strip().lower() for a in artists if a.strip()))
return f"{clean_name}::{clean_artists}"

25
app/utils/time.py Normal file
View File

@@ -0,0 +1,25 @@
from __future__ import annotations
from datetime import datetime, timezone
def utcnow() -> datetime:
return datetime.now(timezone.utc)
def ensure_utc(dt: datetime) -> datetime:
if dt.tzinfo is None or dt.tzinfo.utcoffset(dt) is None:
return dt.replace(tzinfo=timezone.utc)
return dt.astimezone(timezone.utc)
def parse_spotify_datetime(value: str | None) -> datetime | None:
if not value:
return None
if value.endswith("Z"):
value = value.replace("Z", "+00:00")
return datetime.fromisoformat(value)
def to_unix_ms(dt: datetime) -> int:
return int(dt.timestamp() * 1000)