refactor scrobblers (#383)

- no need to explicitly pass api key
- move packages up a level
- catch more errors by extended scrobbler interface with IsUserAuthenticated
- move interface to server
- delete scrobbber package, clients implicitly satisfy Scrobble

this also helps with gonic-lastfm-sync
This commit is contained in:
Senan Kelly
2023-09-27 01:13:00 +01:00
committed by GitHub
parent 32064d0279
commit f119659acf
27 changed files with 1100 additions and 1144 deletions

View File

@@ -7,11 +7,12 @@ import (
"io"
"log"
"net/http"
"time"
"go.senan.xyz/gonic/db"
"go.senan.xyz/gonic/jukebox"
"go.senan.xyz/gonic/lastfm"
"go.senan.xyz/gonic/podcasts"
"go.senan.xyz/gonic/scrobble"
"go.senan.xyz/gonic/scrobble/lastfm"
"go.senan.xyz/gonic/server/ctrlbase"
"go.senan.xyz/gonic/server/ctrlsubsonic/artistinfocache"
"go.senan.xyz/gonic/server/ctrlsubsonic/params"
@@ -39,6 +40,11 @@ func PathsOf(paths []MusicPath) []string {
return r
}
type Scrobbler interface {
IsUserAuthenticated(user *db.User) bool
Scrobble(user *db.User, track *db.Track, stamp time.Time, submission bool) error
}
type Controller struct {
*ctrlbase.Controller
MusicPaths []MusicPath
@@ -46,7 +52,7 @@ type Controller struct {
CacheAudioPath string
CacheCoverPath string
Jukebox *jukebox.Jukebox
Scrobblers []scrobble.Scrobbler
Scrobblers []Scrobbler
Podcasts *podcasts.Podcasts
Transcoder transcode.Transcoder
LastFMClient *lastfm.Client