f03ca44a8e
* feat(plugins): add lyrics provider plugin capability Refactor the lyrics system from a static function to an interface-based service that supports WASM plugin providers. Plugins listed in the LyricsPriority config (alongside "embedded" and file extensions) are now resolved through the plugin system. Includes capability definition, Go/Rust PDK, adapter, Wire integration, and tests for plugin fallback behavior. * test(plugins): add lyrics capability integration test with test plugin * fix(plugins): default lyrics language to 'xxx' when plugin omits it Per the OpenSubsonic spec, the server must return 'und' or 'xxx' when the lyrics language is unknown. The lyrics plugin adapter was passing an empty string through when a plugin didn't provide a language value. This defaults the language to 'xxx', consistent with all other callers of model.ToLyrics() in the codebase. * refactor(plugins): rename lyrics import to improve clarity Signed-off-by: Deluan <deluan@navidrome.org> * refactor(lyrics): update TrackInfo description for clarity Signed-off-by: Deluan <deluan@navidrome.org> * fix(lyrics): enhance lyrics plugin handling and case sensitivity Signed-off-by: Deluan <deluan@navidrome.org> * fix(plugins): update payload type to string with byte format for task data Signed-off-by: Deluan <deluan@navidrome.org> --------- Signed-off-by: Deluan <deluan@navidrome.org>
76 lines
2.0 KiB
Go
76 lines
2.0 KiB
Go
package lyrics
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"os"
|
|
"path"
|
|
|
|
"github.com/navidrome/navidrome/log"
|
|
"github.com/navidrome/navidrome/model"
|
|
"github.com/navidrome/navidrome/utils/ioutils"
|
|
)
|
|
|
|
func fromEmbedded(ctx context.Context, mf *model.MediaFile) (model.LyricList, error) {
|
|
if mf.Lyrics != "" {
|
|
log.Trace(ctx, "embedded lyrics found in file", "title", mf.Title)
|
|
return mf.StructuredLyrics()
|
|
}
|
|
|
|
log.Trace(ctx, "no embedded lyrics for file", "path", mf.Title)
|
|
|
|
return nil, nil
|
|
}
|
|
|
|
func fromExternalFile(ctx context.Context, mf *model.MediaFile, suffix string) (model.LyricList, error) {
|
|
basePath := mf.AbsolutePath()
|
|
ext := path.Ext(basePath)
|
|
|
|
externalLyric := basePath[0:len(basePath)-len(ext)] + suffix
|
|
|
|
contents, err := ioutils.UTF8ReadFile(externalLyric)
|
|
if errors.Is(err, os.ErrNotExist) {
|
|
log.Trace(ctx, "no lyrics found at path", "path", externalLyric)
|
|
return nil, nil
|
|
} else if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
lyrics, err := model.ToLyrics("xxx", string(contents))
|
|
if err != nil {
|
|
log.Error(ctx, "error parsing lyric external file", "path", externalLyric, err)
|
|
return nil, err
|
|
} else if lyrics == nil {
|
|
log.Trace(ctx, "empty lyrics from external file", "path", externalLyric)
|
|
return nil, nil
|
|
}
|
|
|
|
log.Trace(ctx, "retrieved lyrics from external file", "path", externalLyric)
|
|
|
|
return model.LyricList{*lyrics}, nil
|
|
}
|
|
|
|
// fromPlugin attempts to load lyrics from a plugin with the given name.
|
|
func (l *lyricsService) fromPlugin(ctx context.Context, mf *model.MediaFile, pluginName string) (model.LyricList, error) {
|
|
if l.pluginLoader == nil {
|
|
log.Debug(ctx, "Invalid lyric source", "source", pluginName)
|
|
return nil, nil
|
|
}
|
|
|
|
provider, ok := l.pluginLoader.LoadLyricsProvider(pluginName)
|
|
if !ok {
|
|
log.Warn(ctx, "Lyrics plugin not found", "plugin", pluginName)
|
|
return nil, nil
|
|
}
|
|
|
|
lyricsList, err := provider.GetLyrics(ctx, mf)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if len(lyricsList) > 0 {
|
|
log.Trace(ctx, "Retrieved lyrics from plugin", "plugin", pluginName, "count", len(lyricsList))
|
|
}
|
|
return lyricsList, nil
|
|
}
|