feat(lyrics): LRCLIB provider + cached lyrics endpoints (§6.7)
GET /tracks/{id}/lyrics (get-or-fetch, caches found/not_found with a 7-day
miss TTL) and POST /tracks/{id}/lyrics/refetch (force). Hexagonal wiring:
LyricsProvider/LyricsRepository ports, LrclibHttpClient adapter (keyless,
degrades to not_found on error), SqlAlchemyLyricsRepository (upsert on the
existing lyrics table), LyricsService, LyricsOut schema, deps.py factory.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -12,12 +12,14 @@ from app.api.deps import (
|
||||
ArtistRepoDep,
|
||||
CurrentUser,
|
||||
FileStorageDep,
|
||||
LyricsServiceDep,
|
||||
MetadataServiceDep,
|
||||
RemoteLibraryServiceDep,
|
||||
StreamUser,
|
||||
TrackRepoDep,
|
||||
)
|
||||
from app.api.schemas.download import DownloadJobOut
|
||||
from app.api.schemas.lyrics import LyricsOut
|
||||
from app.api.schemas.pagination import PagedResponse
|
||||
from app.api.schemas.track import (
|
||||
MaterializeResponse,
|
||||
@@ -224,6 +226,24 @@ async def get_similar_tracks(track_id: uuid.UUID, _: CurrentUser) -> Any: ...
|
||||
async def optimize_track(track_id: uuid.UUID, _: CurrentUser) -> Any: ...
|
||||
|
||||
|
||||
@router.get("/{track_id}/lyrics")
|
||||
async def get_track_lyrics(
|
||||
track_id: uuid.UUID, lyrics: LyricsServiceDep, _: CurrentUser
|
||||
) -> LyricsOut:
|
||||
"""Cached lyrics for the Now Playing panel (§6.7). A miss is a normal 200
|
||||
with ``status="not_found"`` — the provider (LRCLIB) is queried at most once,
|
||||
then the outcome is cached."""
|
||||
return LyricsOut.from_entity(await lyrics.get_lyrics(track_id))
|
||||
|
||||
|
||||
@router.post("/{track_id}/lyrics/refetch")
|
||||
async def refetch_track_lyrics(
|
||||
track_id: uuid.UUID, lyrics: LyricsServiceDep, _: CurrentUser
|
||||
) -> LyricsOut:
|
||||
"""Force a fresh provider lookup, bypassing the cache (user-triggered)."""
|
||||
return LyricsOut.from_entity(await lyrics.get_lyrics(track_id, force=True))
|
||||
|
||||
|
||||
@router.get("/{track_id}/cover")
|
||||
async def get_track_cover(
|
||||
track_id: uuid.UUID,
|
||||
|
||||
Reference in New Issue
Block a user