mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-04 21:17:37 +03:00
Merge 67162326a9
into 2b84c574ba
This commit is contained in:
commit
e7d47c66a7
4 changed files with 46 additions and 1 deletions
|
@ -63,6 +63,7 @@ type configOptions struct {
|
||||||
FFmpegPath string
|
FFmpegPath string
|
||||||
MPVPath string
|
MPVPath string
|
||||||
MPVCmdTemplate string
|
MPVCmdTemplate string
|
||||||
|
ArtworkFolder string
|
||||||
CoverArtPriority string
|
CoverArtPriority string
|
||||||
CoverJpegQuality int
|
CoverJpegQuality int
|
||||||
ArtistArtPriority string
|
ArtistArtPriority string
|
||||||
|
@ -243,6 +244,10 @@ func Load(noConfigDump bool) {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if Server.ArtworkFolder == "" {
|
||||||
|
Server.ArtworkFolder = filepath.Join(Server.DataFolder, "artwork")
|
||||||
|
}
|
||||||
|
|
||||||
Server.ConfigFile = viper.GetViper().ConfigFileUsed()
|
Server.ConfigFile = viper.GetViper().ConfigFileUsed()
|
||||||
if Server.DbPath == "" {
|
if Server.DbPath == "" {
|
||||||
Server.DbPath = filepath.Join(Server.DataFolder, consts.DefaultDbPath)
|
Server.DbPath = filepath.Join(Server.DataFolder, consts.DefaultDbPath)
|
||||||
|
@ -456,6 +461,7 @@ func init() {
|
||||||
viper.SetDefault("ffmpegpath", "")
|
viper.SetDefault("ffmpegpath", "")
|
||||||
viper.SetDefault("mpvcmdtemplate", "mpv --audio-device=%d --no-audio-display --pause %f --input-ipc-server=%s")
|
viper.SetDefault("mpvcmdtemplate", "mpv --audio-device=%d --no-audio-display --pause %f --input-ipc-server=%s")
|
||||||
|
|
||||||
|
viper.SetDefault("ArtworkFolder", "")
|
||||||
viper.SetDefault("coverartpriority", "cover.*, folder.*, front.*, embedded, external")
|
viper.SetDefault("coverartpriority", "cover.*, folder.*, front.*, embedded, external")
|
||||||
viper.SetDefault("coverjpegquality", 75)
|
viper.SetDefault("coverjpegquality", 75)
|
||||||
viper.SetDefault("artistartpriority", "artist.*, album/artist.*, external")
|
viper.SetDefault("artistartpriority", "artist.*, album/artist.*, external")
|
||||||
|
|
|
@ -15,7 +15,10 @@ type mimeConf struct {
|
||||||
Lossless []string `yaml:"lossless"`
|
Lossless []string `yaml:"lossless"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var LosslessFormats []string
|
var (
|
||||||
|
LosslessFormats []string
|
||||||
|
ValidImageExtensions []string
|
||||||
|
)
|
||||||
|
|
||||||
func initMimeTypes() {
|
func initMimeTypes() {
|
||||||
// In some circumstances, Windows sets JS mime-type to `text/plain`!
|
// In some circumstances, Windows sets JS mime-type to `text/plain`!
|
||||||
|
@ -36,6 +39,9 @@ func initMimeTypes() {
|
||||||
}
|
}
|
||||||
for ext, typ := range mimeConf.Types {
|
for ext, typ := range mimeConf.Types {
|
||||||
_ = mime.AddExtensionType(ext, typ)
|
_ = mime.AddExtensionType(ext, typ)
|
||||||
|
if strings.HasPrefix(typ, "image/") {
|
||||||
|
ValidImageExtensions = append(ValidImageExtensions, ext)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, ext := range mimeConf.Lossless {
|
for _, ext := range mimeConf.Lossless {
|
||||||
|
|
|
@ -44,6 +44,7 @@ func (a *playlistArtworkReader) LastUpdated() time.Time {
|
||||||
|
|
||||||
func (a *playlistArtworkReader) Reader(ctx context.Context) (io.ReadCloser, string, error) {
|
func (a *playlistArtworkReader) Reader(ctx context.Context) (io.ReadCloser, string, error) {
|
||||||
ff := []sourceFunc{
|
ff := []sourceFunc{
|
||||||
|
fromNamedArtwork(ctx, "playlist", a.pl.ID, a.pl.Name),
|
||||||
a.fromGeneratedTiledCover(ctx),
|
a.fromGeneratedTiledCover(ctx),
|
||||||
fromAlbumPlaceholder(),
|
fromAlbumPlaceholder(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package artwork
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -16,6 +17,8 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/dhowden/tag"
|
"github.com/dhowden/tag"
|
||||||
|
"github.com/navidrome/navidrome/conf"
|
||||||
|
"github.com/navidrome/navidrome/conf/mime"
|
||||||
"github.com/navidrome/navidrome/consts"
|
"github.com/navidrome/navidrome/consts"
|
||||||
"github.com/navidrome/navidrome/core"
|
"github.com/navidrome/navidrome/core"
|
||||||
"github.com/navidrome/navidrome/core/ffmpeg"
|
"github.com/navidrome/navidrome/core/ffmpeg"
|
||||||
|
@ -192,3 +195,32 @@ func fromURL(ctx context.Context, imageUrl *url.URL) (io.ReadCloser, string, err
|
||||||
}
|
}
|
||||||
return resp.Body, imageUrl.String(), nil
|
return resp.Body, imageUrl.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fromNamedArtwork(ctx context.Context, resource string, names ...string) sourceFunc {
|
||||||
|
return func() (io.ReadCloser, string, error) {
|
||||||
|
for _, name := range names {
|
||||||
|
playlistName := name
|
||||||
|
imagePath, err := findMatchingImage(ctx, resource, playlistName)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
file, err := os.Open(imagePath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", err
|
||||||
|
}
|
||||||
|
return file, imagePath, nil
|
||||||
|
}
|
||||||
|
return nil, "", errors.New("no matching image found")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func findMatchingImage(_ context.Context, resource string, name string) (string, error) {
|
||||||
|
path := filepath.Join(conf.Server.ArtworkFolder, resource, name)
|
||||||
|
for _, ext := range mime.ValidImageExtensions {
|
||||||
|
filename := path + ext
|
||||||
|
if _, err := os.Stat(filename); err == nil {
|
||||||
|
return filename, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "", errors.New("no matching image found")
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue