Add caching for lrclib lyrics
This commit is contained in:
@@ -81,6 +81,7 @@ type nowPlayingPageState struct {
|
||||
canRate bool
|
||||
canShare bool
|
||||
lrcLib bool
|
||||
cacheDir string
|
||||
}
|
||||
|
||||
func NewNowPlayingPage(
|
||||
@@ -94,9 +95,10 @@ func NewNowPlayingPage(
|
||||
canRate bool,
|
||||
canShare bool,
|
||||
lrcLibEnabled bool,
|
||||
cacheDir string,
|
||||
) *NowPlayingPage {
|
||||
state := nowPlayingPageState{
|
||||
conf: conf, contr: contr, pool: pool, sm: sm, im: im, pm: pm, mp: mp, canRate: canRate, canShare: canShare, lrcLib: lrcLibEnabled,
|
||||
conf: conf, contr: contr, pool: pool, sm: sm, im: im, pm: pm, mp: mp, canRate: canRate, canShare: canShare, lrcLib: lrcLibEnabled, cacheDir: cacheDir,
|
||||
}
|
||||
if page, ok := pool.Obtain(util.WidgetTypeNowPlayingPage).(*NowPlayingPage); ok && page != nil {
|
||||
page.nowPlayingPageState = state
|
||||
@@ -362,7 +364,7 @@ func (a *NowPlayingPage) fetchLyrics(ctx context.Context, song *mediaprovider.Tr
|
||||
}
|
||||
}
|
||||
if lyrics == nil {
|
||||
lyrics, err = backend.FetchLrcLibLyrics(song.Title, song.ArtistNames[0], song.Album, song.Duration)
|
||||
lyrics, err = backend.FetchLrcLibLyricsCached(song.Title, song.ArtistNames[0], song.Album, song.Duration, a.cacheDir)
|
||||
if err != nil {
|
||||
log.Println(err.Error())
|
||||
}
|
||||
@@ -450,7 +452,7 @@ func (a *NowPlayingPage) Reload() {
|
||||
}
|
||||
|
||||
func (s *nowPlayingPageState) Restore() Page {
|
||||
return NewNowPlayingPage(s.conf, s.contr, s.pool, s.sm, s.im, s.pm, s.mp, s.canRate, s.canShare, s.lrcLib)
|
||||
return NewNowPlayingPage(s.conf, s.contr, s.pool, s.sm, s.im, s.pm, s.mp, s.canRate, s.canShare, s.lrcLib, s.cacheDir)
|
||||
}
|
||||
|
||||
var _ CanShowPlayTime = (*NowPlayingPage)(nil)
|
||||
|
||||
Reference in New Issue
Block a user