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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user