wire tag.Reader to subsonic Controller

This commit is contained in:
sentriz
2025-09-29 18:24:10 +01:00
parent e413bc35de
commit 2fcba12650
3 changed files with 41 additions and 35 deletions

No files matched your search

+34 -29
View File
@@ -24,6 +24,7 @@ import (
"go.senan.xyz/gonic/scrobble"
"go.senan.xyz/gonic/server/ctrlsubsonic/params"
"go.senan.xyz/gonic/server/ctrlsubsonic/spec"
"go.senan.xyz/gonic/tags"
"go.senan.xyz/gonic/transcode"
)
@@ -52,41 +53,45 @@ type ProxyPathResolver func(in string) string
type Controller struct {
*http.ServeMux
dbc *db.DB
scanner *scanner.Scanner
musicPaths []MusicPath
podcastsPath string
cacheAudioPath string
cacheCoverPath string
jukebox *jukebox.Jukebox
playlistStore *playlist.Store
scrobblers []scrobble.Scrobbler
podcasts *podcast.Podcasts
transcoder transcode.Transcoder
lastFMClient *lastfm.Client
artistInfoCache *artistinfocache.ArtistInfoCache
albumInfoCache *albuminfocache.AlbumInfoCache
dbc *db.DB
scanner *scanner.Scanner
musicPaths []MusicPath
podcastsPath string
cacheAudioPath string
cacheCoverPath string
jukebox *jukebox.Jukebox
playlistStore *playlist.Store
scrobblers []scrobble.Scrobbler
podcasts *podcast.Podcasts
transcoder transcode.Transcoder
lastFMClient *lastfm.Client
artistInfoCache *artistinfocache.ArtistInfoCache
albumInfoCache *albuminfocache.AlbumInfoCache
tagReader tags.Reader
resolveProxyPath ProxyPathResolver
}
func New(dbc *db.DB, scannr *scanner.Scanner, musicPaths []MusicPath, podcastsPath string, cacheAudioPath string, cacheCoverPath string, jukebox *jukebox.Jukebox, playlistStore *playlist.Store, scrobblers []scrobble.Scrobbler, podcasts *podcast.Podcasts, transcoder transcode.Transcoder, lastFMClient *lastfm.Client, artistInfoCache *artistinfocache.ArtistInfoCache, albumInfoCache *albuminfocache.AlbumInfoCache, resolveProxyPath ProxyPathResolver) (*Controller, error) {
func New(dbc *db.DB, scannr *scanner.Scanner, musicPaths []MusicPath, podcastsPath string, cacheAudioPath string, cacheCoverPath string, jukebox *jukebox.Jukebox, playlistStore *playlist.Store, scrobblers []scrobble.Scrobbler, podcasts *podcast.Podcasts, transcoder transcode.Transcoder, lastFMClient *lastfm.Client, artistInfoCache *artistinfocache.ArtistInfoCache, albumInfoCache *albuminfocache.AlbumInfoCache, tagReader tags.Reader, resolveProxyPath ProxyPathResolver) (*Controller, error) {
c := Controller{
ServeMux: http.NewServeMux(),
dbc: dbc,
scanner: scannr,
musicPaths: musicPaths,
podcastsPath: podcastsPath,
cacheAudioPath: cacheAudioPath,
cacheCoverPath: cacheCoverPath,
jukebox: jukebox,
playlistStore: playlistStore,
scrobblers: scrobblers,
podcasts: podcasts,
transcoder: transcoder,
lastFMClient: lastFMClient,
artistInfoCache: artistInfoCache,
albumInfoCache: albumInfoCache,
dbc: dbc,
scanner: scannr,
musicPaths: musicPaths,
podcastsPath: podcastsPath,
cacheAudioPath: cacheAudioPath,
cacheCoverPath: cacheCoverPath,
jukebox: jukebox,
playlistStore: playlistStore,
scrobblers: scrobblers,
podcasts: podcasts,
transcoder: transcoder,
lastFMClient: lastFMClient,
artistInfoCache: artistInfoCache,
albumInfoCache: albumInfoCache,
tagReader: tagReader,
resolveProxyPath: resolveProxyPath,
}
+6 -5
View File
@@ -85,7 +85,7 @@ func coverFor(dbc *db.DB, artistInfoCache *artistinfocache.ArtistInfoCache, id s
case specid.Podcast:
return coverForPodcast(dbc, id.Value)
case specid.PodcastEpisode:
return coverGetPathPodcastEpisode(dbc, id.Value)
return coverForPodcastEpisode(dbc, id.Value)
default:
return nil, errCoverNotFound
}
@@ -135,7 +135,7 @@ func coverForPodcast(dbc *db.DB, id int) (*os.File, error) {
return os.Open(filepath.Join(podcast.RootDir, podcast.Image))
}
func coverGetPathPodcastEpisode(dbc *db.DB, id int) (*os.File, error) {
func coverForPodcastEpisode(dbc *db.DB, id int) (*os.File, error) {
var pe db.PodcastEpisode
err := dbc.
Preload("Podcast").
@@ -155,9 +155,10 @@ func coverScaleAndSave(reader io.Reader, cachePath string, size int) error {
if err != nil {
return fmt.Errorf("resizing: %w", err)
}
width := min(size,
// don't upscale images
src.Bounds().Dx())
// don't upscale images
width := min(size, src.Bounds().Dx())
if err := imaging.Save(imaging.Resize(src, width, 0, imaging.Lanczos), cachePath); err != nil {
return fmt.Errorf("caching %q: %w", cachePath, err)
}