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)
|
_, _ = a.ImageManager.GetCoverThumbnail(coverID)
|
||||||
})
|
})
|
||||||
if a.Config.Application.EnableLrcLib {
|
if a.Config.Application.EnableLrcLib {
|
||||||
a.LrcLibFetcher = NewLrcLibFetcher(a.cacheDir)
|
a.LrcLibFetcher = NewLrcLibFetcher(a.cacheDir, a.Config.Application.CustomLrcLibUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
a.PlaybackManager.OnPlaying(func() {
|
a.PlaybackManager.OnPlaying(func() {
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ type AppConfig struct {
|
|||||||
AddToPlaylistSkipDuplicates bool
|
AddToPlaylistSkipDuplicates bool
|
||||||
ShowTrackChangeNotification bool
|
ShowTrackChangeNotification bool
|
||||||
EnableLrcLib bool
|
EnableLrcLib bool
|
||||||
|
CustomLrcLibUrl string
|
||||||
EnablePasswordStorage bool
|
EnablePasswordStorage bool
|
||||||
SkipSSLVerify bool
|
SkipSSLVerify bool
|
||||||
EnqueueBatchSize int
|
EnqueueBatchSize int
|
||||||
|
|||||||
+22
-3
@@ -9,6 +9,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
@@ -24,12 +25,13 @@ const lrclibCacheFolder = "lrclib"
|
|||||||
|
|
||||||
type LrcLibFetcher struct {
|
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)
|
cachePath := filepath.Join(baseCacheDir, lrclibCacheFolder)
|
||||||
configdir.MakePath(cachePath)
|
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) {
|
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)
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
defer cancel()
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -91,6 +95,21 @@ func (l *LrcLibFetcher) fetchFromServer(name, artist, album string, durationSecs
|
|||||||
return parseLrcLibResponse(resp)
|
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) {
|
func parseLrcLibResponse(resp *http.Response) (*mediaprovider.Lyrics, error) {
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
return nil, errors.New("lrclib lyrics not found")
|
return nil, errors.New("lrclib lyrics not found")
|
||||||
|
|||||||
Reference in New Issue
Block a user