Externalize MPV command template (#2948)

* externalise MPVTemplate

* Remove unnecessary comment

---------

Co-authored-by: Deluan <deluan@navidrome.org>
This commit is contained in:
Jonathan 2024-04-16 03:31:54 +02:00 committed by GitHub
parent cf6603e3ec
commit bcec15dc13
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 9 deletions

View File

@ -57,6 +57,7 @@ type configOptions struct {
SubsonicArtistParticipations bool SubsonicArtistParticipations bool
FFmpegPath string FFmpegPath string
MPVPath string MPVPath string
MPVCmdTemplate string
CoverArtPriority string CoverArtPriority string
CoverJpegQuality int CoverJpegQuality int
ArtistArtPriority string ArtistArtPriority string
@ -303,6 +304,8 @@ func init() {
viper.SetDefault("indexgroups", "A B C D E F G H I J K L M N O P Q R S T U V W X-Z(XYZ) [Unknown]([)") viper.SetDefault("indexgroups", "A B C D E F G H I J K L M N O P Q R S T U V W X-Z(XYZ) [Unknown]([)")
viper.SetDefault("subsonicartistparticipations", false) viper.SetDefault("subsonicartistparticipations", false)
viper.SetDefault("ffmpegpath", "") viper.SetDefault("ffmpegpath", "")
viper.SetDefault("mpvcmdtemplate", "mpv --audio-device=%d --no-audio-display --pause %f --input-ipc-server=%s")
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")

View File

@ -14,11 +14,6 @@ import (
"github.com/navidrome/navidrome/log" "github.com/navidrome/navidrome/log"
) )
// mpv --no-audio-display --pause 'Jack Johnson/On And On/01 Times Like These.m4a' --input-ipc-server=/tmp/gonzo.socket
const (
mpvComdTemplate = "mpv --audio-device=%d --no-audio-display --pause %f --input-ipc-server=%s"
)
func start(args []string) (Executor, error) { func start(args []string) (Executor, error) {
log.Debug("Executing mpv command", "cmd", args) log.Debug("Executing mpv command", "cmd", args)
j := Executor{args: args} j := Executor{args: args}
@ -78,15 +73,14 @@ func (j *Executor) wait() {
} }
// Path will always be an absolute path // Path will always be an absolute path
func createMPVCommand(cmd, deviceName string, filename string, socketName string) []string { func createMPVCommand(deviceName string, filename string, socketName string) []string {
split := strings.Split(fixCmd(cmd), " ") split := strings.Split(fixCmd(conf.Server.MPVCmdTemplate), " ")
for i, s := range split { for i, s := range split {
s = strings.ReplaceAll(s, "%d", deviceName) s = strings.ReplaceAll(s, "%d", deviceName)
s = strings.ReplaceAll(s, "%f", filename) s = strings.ReplaceAll(s, "%f", filename)
s = strings.ReplaceAll(s, "%s", socketName) s = strings.ReplaceAll(s, "%s", socketName)
split[i] = s split[i] = s
} }
return split return split
} }

View File

@ -33,7 +33,7 @@ func NewTrack(playbackDoneChannel chan bool, deviceName string, mf model.MediaFi
tmpSocketName := socketName("mpv-ctrl-", ".socket") tmpSocketName := socketName("mpv-ctrl-", ".socket")
args := createMPVCommand(mpvComdTemplate, deviceName, mf.Path, tmpSocketName) args := createMPVCommand(deviceName, mf.Path, tmpSocketName)
exe, err := start(args) exe, err := start(args)
if err != nil { if err != nil {
log.Error("Error starting mpv process", err) log.Error("Error starting mpv process", err)