feat(subsonic): cache and use lastfm responses for covers, bios, top songs

This commit is contained in:
sentriz
2023-09-13 20:35:38 +01:00
parent 2b9052ca87
commit c374577328
7 changed files with 236 additions and 89 deletions

View File

@@ -26,6 +26,7 @@ import (
"github.com/sentriz/gormstore"
"go.senan.xyz/gonic"
"go.senan.xyz/gonic/artistinfocache"
"go.senan.xyz/gonic/db"
"go.senan.xyz/gonic/jukebox"
"go.senan.xyz/gonic/playlist"
@@ -205,6 +206,8 @@ func main() {
sessDB.SessionOpts.HttpOnly = true
sessDB.SessionOpts.SameSite = http.SameSiteLaxMode
artistInfoCache := artistinfocache.New(dbc, lastfmClient)
ctrlBase := &ctrlbase.Controller{
DB: dbc,
PlaylistStore: playlistStore,
@@ -216,12 +219,13 @@ func main() {
log.Panicf("error creating admin controller: %v\n", err)
}
ctrlSubsonic := &ctrlsubsonic.Controller{
Controller: ctrlBase,
MusicPaths: musicPaths,
PodcastsPath: *confPodcastPath,
CacheAudioPath: cacheDirAudio,
CacheCoverPath: cacheDirCovers,
LastFMClient: lastfmClient,
Controller: ctrlBase,
MusicPaths: musicPaths,
PodcastsPath: *confPodcastPath,
CacheAudioPath: cacheDirAudio,
CacheCoverPath: cacheDirCovers,
LastFMClient: lastfmClient,
ArtistInfoCache: artistInfoCache,
Scrobblers: []scrobble.Scrobbler{
lastfm.NewScrobbler(dbc, lastfmClient),
listenbrainz.NewScrobbler(),
@@ -345,6 +349,14 @@ func main() {
})
}
lastfmAPIKey, _ := dbc.GetSetting("lastfm_api_key")
if lastfmAPIKey != "" {
g.Add(func() error {
log.Printf("starting job 'refresh artist info'\n")
return artistInfoCache.Refresh(lastfmAPIKey, 5*time.Second)
}, nil)
}
if *confScanAtStart {
if _, err := scannr.ScanAndClean(scanner.ScanOptions{}); err != nil {
log.Panicf("error scanning at start: %v\n", err)