Add local agent, only for images

This commit is contained in:
Deluan
2022-12-30 23:52:53 -05:00
committed by Deluan Quintão
parent 387acc5f63
commit bf461473ef
15 changed files with 134 additions and 76 deletions
+1 -1
View File
@@ -9,4 +9,4 @@ A new agent must comply with these simple implementation rules:
For an agent to be used it needs to be listed in the `Agents` config option (default is `"lastfm,spotify"`). The order dictates the priority of the agents
For a simple Agent example, look at the [placeholders](placeholders.go) agent source code.
For a simple Agent example, look at the [local_agent](local_agent.go) agent source code.
+1 -1
View File
@@ -22,7 +22,7 @@ func New(ds model.DataStore) *Agents {
if conf.Server.Agents != "" {
order = strings.Split(conf.Server.Agents, ",")
}
order = append(order, PlaceholderAgentName)
order = append(order, LocalAgentName)
var res []Interface
for _, name := range order {
init, ok := Map[name]
+49
View File
@@ -0,0 +1,49 @@
package agents
import (
"context"
"path/filepath"
"github.com/navidrome/navidrome/consts"
"github.com/navidrome/navidrome/core/artwork"
"github.com/navidrome/navidrome/model"
)
const LocalAgentName = "local"
const (
localBiography = "Biography not available"
)
type localAgent struct{}
func localsConstructor(_ model.DataStore) Interface {
return &localAgent{}
}
func (p *localAgent) AgentName() string {
return LocalAgentName
}
func (p *localAgent) GetBiography(ctx context.Context, id, name, mbid string) (string, error) {
return localBiography, nil
}
func (p *localAgent) GetImages(_ context.Context, id, name, mbid string) ([]ArtistImage, error) {
return []ArtistImage{
p.artistImage(id, 300),
p.artistImage(id, 174),
p.artistImage(id, 64),
}, nil
}
func (p *localAgent) artistImage(id string, size int) ArtistImage {
return ArtistImage{
filepath.Join(consts.URLPathPublicImages, artwork.Public(model.NewArtworkID(model.KindArtistArtwork, id), size)),
size,
}
}
func init() {
Register(LocalAgentName, localsConstructor)
}
-43
View File
@@ -1,43 +0,0 @@
package agents
import (
"context"
"github.com/navidrome/navidrome/consts"
"github.com/navidrome/navidrome/model"
)
const PlaceholderAgentName = "placeholder"
const (
placeholderArtistImageSmallUrl = consts.URLPathUI + "/artist-placeholder.webp"
placeholderArtistImageMediumUrl = consts.URLPathUI + "/artist-placeholder.webp"
placeholderArtistImageLargeUrl = consts.URLPathUI + "/artist-placeholder.webp"
placeholderBiography = "Biography not available"
)
type placeholderAgent struct{}
func placeholdersConstructor(_ model.DataStore) Interface {
return &placeholderAgent{}
}
func (p *placeholderAgent) AgentName() string {
return PlaceholderAgentName
}
func (p *placeholderAgent) GetBiography(ctx context.Context, id, name, mbid string) (string, error) {
return placeholderBiography, nil
}
func (p *placeholderAgent) GetImages(ctx context.Context, id, name, mbid string) ([]ArtistImage, error) {
return []ArtistImage{
{placeholderArtistImageLargeUrl, 300},
{placeholderArtistImageMediumUrl, 174},
{placeholderArtistImageSmallUrl, 64},
}, nil
}
func init() {
Register(PlaceholderAgentName, placeholdersConstructor)
}