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

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