feat: import library from media root and stream tracks

Add a filesystem scanner that ingests supported audio files from MEDIA_ROOT into SQLite using embedded tags with filename fallbacks. Wire startup scanning, manual rescan, and authenticated audio streaming into the backend, then connect the web player to the real stream endpoint.
This commit is contained in:
2026-04-02 22:29:04 +03:00
parent e6a8d9411e
commit 46c2c3fb28
10 changed files with 468 additions and 5 deletions

View File

@@ -160,3 +160,34 @@ func (s *Service) Tracks(ctx context.Context, limit int) ([]Track, error) {
return tracks, rows.Err()
}
func (s *Service) TrackByID(ctx context.Context, id string) (Track, error) {
var track Track
err := s.db.QueryRowContext(
ctx,
`SELECT t.id, t.album_id, t.artist_id, t.title, a.name, al.title, COALESCE(t.track_number, 0),
COALESCE(t.duration_seconds, 0), t.file_path, COALESCE(t.content_type, '')
FROM tracks t
JOIN artists a ON a.id = t.artist_id
JOIN albums al ON al.id = t.album_id
WHERE t.id = ?`,
id,
).Scan(
&track.ID,
&track.AlbumID,
&track.ArtistID,
&track.Title,
&track.ArtistName,
&track.AlbumTitle,
&track.TrackNumber,
&track.DurationSecs,
&track.FilePath,
&track.ContentType,
)
if err != nil {
return Track{}, fmt.Errorf("query track by id: %w", err)
}
return track, nil
}