diff --git a/config.yml b/config.yml index e0d208c..e09b26b 100644 --- a/config.yml +++ b/config.yml @@ -8,6 +8,7 @@ players: new_window: "" needs_ipc: true flag_overrides: {} + celluloid: name: Celluloid executable: celluloid @@ -16,8 +17,9 @@ players: enqueue: "--enqueue" new_window: "--new-window" needs_ipc: false - flag_overrides: + flag_overrides: "*": "--mpv-%s" + mpvnet: name: mpv.net executable: mpvnet.exe @@ -26,4 +28,4 @@ players: enqueue: "--queue" new_window: "" needs_ipc: false - flag_overrides: {} \ No newline at end of file + flag_overrides: {} diff --git a/options.go b/options.go index 01f0737..a651b8a 100644 --- a/options.go +++ b/options.go @@ -95,7 +95,7 @@ func (o *Options) Parse(uri string) error { } o.Enqueue = u.Query().Get("enqueue") == "1" - o.Fullscreen = u.Query().Get("fullscreen") == "1" + o.Fullscreen = u.Query().Get("full_screen") == "1" o.NewWindow = u.Query().Get("new_window") == "1" o.Pip = u.Query().Get("pip") == "1" @@ -159,7 +159,7 @@ func (o Options) GenerateCommand() (string, []string) { } if o.Pip { - ret = append(ret, playerConfig.Pip) + ret = append(ret, strings.Split(playerConfig.Pip, " ")...) } if o.Flags != "" { diff --git a/options_test.go b/options_test.go index fb12a15..cd537de 100644 --- a/options_test.go +++ b/options_test.go @@ -10,7 +10,7 @@ var fakePlayer = Player{ Name: "FakePlayer", Executable: "fakeplayer", Fullscreen: "", - Pip: "", + Pip: `--ontop --no-border --autofit=384x216 --geometry=98%:98%`, Enqueue: "", NewWindow: "", NeedsIpc: true, @@ -22,17 +22,34 @@ func testUrl(query ...string) string { elems := []string{ `mpv:///open?url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DdQw4w9WgXcQ`, } - return strings.Join(append(elems, query...), "&") + for _, elem := range query { + key, value, _ := strings.Cut(elem, "=") + elems = append(elems, url.QueryEscape(key)+"="+url.QueryEscape(value)) + } + return strings.Join(elems, "&") } func Test_GenerateCommand(t *testing.T) { + defaultConfig.Players["fakeplayer"] = fakePlayer + o := NewOptions() - o.Url, _ = url.Parse("example.com") - o.Flags = "--vo=gpu" - o.Pip = true + err := o.Parse(testUrl("player=fakeplayer", "flags=--ytdl-format=bestvideo[height<=480]+bestaudio", "pip=1")) + if err != nil { + t.Error(err) + } executable, args := o.GenerateCommand() t.Logf("%s %v", executable, args) + + if executable != fakePlayer.Executable { + t.Logf("expected the default player to be %s", fakePlayer.Executable) + t.Fail() + } + // We expect 6 args: 1 from o.Flags, 4 from o.Pip and 1 is o.Url + if args == nil || len(args) < 6 { + t.Logf("expected 6 args, got %d", len(args)) + t.Fail() + } } func Test_GenerateIPC(t *testing.T) {