sonda/internal/opensubsonic/store.go
tgiachi ccee5e8719 feat: OpenSubsonic playback, covers, lists and search
Apps can play and browse: stream and download send the original file (Range,
HEAD), getCoverArt serves the cover of an album, an artist or the album of a
song (300 pixels or less is the small one), getAlbumList2 knows every kind of
list, getRandomSongs and getSongsByGenre list songs, search3 finds artists,
albums and songs, and the starred calls answer with nothing so apps do not break.

- catalog.Filter has IDs to read albums and songs by id
- storage.SubsonicRepo answers the album and song lists (random, newest,
  frequent, recent, by name, by artist, by year, by genre)
2026-11-16 09:45:07 +01:00

83 lines
2.5 KiB
Go

package opensubsonic
import (
"context"
"time"
)
// TrackExtra is what an app asks about a song that the catalogue does not carry: from its tags and its first file.
type TrackExtra struct {
Year int // 0 when the file has none
Genres []string
Size int64 // bytes
BitrateKbps int // 0 when unknown
Suffix string // the extension of the file, without the dot
AddedAt time.Time
}
// AlbumExtra is the same for an album.
type AlbumExtra struct {
Year int // the earliest year of its songs, 0 when none has one
Genres []string
AddedAt time.Time // when its oldest file arrived
}
// Genre is a genre of the music, with how much of it there is.
type Genre struct {
Name string
Songs int
Albums int
}
// Extras reads what the catalogue does not carry.
type Extras interface {
// Tracks returns the extras of the songs that can be played; a song that cannot is left out.
Tracks(ctx context.Context, ids []int64) (map[int64]TrackExtra, error)
// Albums returns the extras of the albums that can be played.
Albums(ctx context.Context, ids []int64) (map[int64]AlbumExtra, error)
// Genres returns every genre of the songs that can be played.
Genres(ctx context.Context) ([]Genre, error)
}
// The kinds of list of albums an app can ask for.
const (
ListRandom = "random"
ListNewest = "newest"
ListFrequent = "frequent"
ListRecent = "recent"
ListStarred = "starred"
ListByName = "alphabeticalByName"
ListByArtist = "alphabeticalByArtist"
ListByYear = "byYear"
ListByGenre = "byGenre"
)
// AlbumQuery asks for a list of albums.
type AlbumQuery struct {
Type string // one of the List constants
Size int
Offset int
LibraryID int64 // 0 is every library
FromYear int // byYear: from FromYear to ToYear, backwards when FromYear is the later
ToYear int
Genre string // byGenre
UserID int64 // frequent and recent: whose listens
}
// SongQuery asks for a list of songs.
type SongQuery struct {
Random bool // in any order, otherwise by album
Size int
Offset int
LibraryID int64
FromYear int // 0 is no limit
ToYear int
Genre string // "" is any genre
}
// Lists answers the calls that ask for albums and songs in an order that the catalogue does not know. They answer
// with ids, only of what can be played; the catalogue describes them.
type Lists interface {
AlbumIDs(ctx context.Context, q AlbumQuery) ([]int64, error)
SongIDs(ctx context.Context, q SongQuery) ([]int64, error)
}