Config for custom lrclib server url
This commit is contained in:
+1
-1
@@ -146,7 +146,7 @@ func StartupApp(appName, displayAppName, appVersion, appVersionTag, latestReleas
|
||||
_, _ = a.ImageManager.GetCoverThumbnail(coverID)
|
||||
})
|
||||
if a.Config.Application.EnableLrcLib {
|
||||
a.LrcLibFetcher = NewLrcLibFetcher(a.cacheDir)
|
||||
a.LrcLibFetcher = NewLrcLibFetcher(a.cacheDir, a.Config.Application.CustomLrcLibUrl)
|
||||
}
|
||||
|
||||
a.PlaybackManager.OnPlaying(func() {
|
||||
|
||||
@@ -47,6 +47,7 @@ type AppConfig struct {
|
||||
AddToPlaylistSkipDuplicates bool
|
||||
ShowTrackChangeNotification bool
|
||||
EnableLrcLib bool
|
||||
CustomLrcLibUrl string
|
||||
EnablePasswordStorage bool
|
||||
SkipSSLVerify bool
|
||||
EnqueueBatchSize int
|
||||
|
||||
+23
-4
@@ -9,6 +9,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
@@ -23,13 +24,14 @@ import (
|
||||
const lrclibCacheFolder = "lrclib"
|
||||
|
||||
type LrcLibFetcher struct {
|
||||
cachePath string
|
||||
cachePath string
|
||||
customLrcLibUrl string
|
||||
}
|
||||
|
||||
func NewLrcLibFetcher(baseCacheDir string) *LrcLibFetcher {
|
||||
func NewLrcLibFetcher(baseCacheDir string, customLrcLibUrl string) *LrcLibFetcher {
|
||||
cachePath := filepath.Join(baseCacheDir, lrclibCacheFolder)
|
||||
configdir.MakePath(cachePath)
|
||||
return &LrcLibFetcher{cachePath: cachePath}
|
||||
return &LrcLibFetcher{cachePath: cachePath, customLrcLibUrl: customLrcLibUrl}
|
||||
}
|
||||
|
||||
func (l *LrcLibFetcher) FetchLrcLibLyrics(name, artist, album string, durationSecs int) (*mediaprovider.Lyrics, error) {
|
||||
@@ -68,7 +70,9 @@ func (l *LrcLibFetcher) fetchFromServer(name, artist, album string, durationSecs
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://lrclib.net/api/get", nil)
|
||||
lrclibUrl := l.getLrclibUrl()
|
||||
fmt.Println(lrclibUrl)
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, lrclibUrl, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -91,6 +95,21 @@ func (l *LrcLibFetcher) fetchFromServer(name, artist, album string, durationSecs
|
||||
return parseLrcLibResponse(resp)
|
||||
}
|
||||
|
||||
// Returns the Lrclib url the fetcher should use, based on the configuration.
|
||||
func (l *LrcLibFetcher) getLrclibUrl() string {
|
||||
if l.customLrcLibUrl != "" {
|
||||
u, err := url.JoinPath(l.customLrcLibUrl, "/api/get")
|
||||
if err == nil {
|
||||
// Return custom cunfig url
|
||||
return u
|
||||
}
|
||||
|
||||
log.Printf("Invalid LrcLib URL passed (err: %s). Falling back to default", err)
|
||||
}
|
||||
|
||||
return "https://lrclib.net/api/get"
|
||||
}
|
||||
|
||||
func parseLrcLibResponse(resp *http.Response) (*mediaprovider.Lyrics, error) {
|
||||
if resp.StatusCode == http.StatusNotFound {
|
||||
return nil, errors.New("lrclib lyrics not found")
|
||||
|
||||
Reference in New Issue
Block a user