Skip to content

Commit

Permalink
Fixed small bugs in flags handling thanks to GrainyTV, added some doc…
Browse files Browse the repository at this point in the history
…umentation, added more test cases
  • Loading branch information
Baldomo committed Aug 26, 2024
1 parent 62032a3 commit fd25fc6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
6 changes: 4 additions & 2 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ players:
new_window: ""
needs_ipc: true
flag_overrides: {}

celluloid:
name: Celluloid
executable: celluloid
Expand All @@ -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
Expand All @@ -26,4 +28,4 @@ players:
enqueue: "--queue"
new_window: ""
needs_ipc: false
flag_overrides: {}
flag_overrides: {}
4 changes: 2 additions & 2 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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 != "" {
Expand Down
27 changes: 22 additions & 5 deletions options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down

0 comments on commit fd25fc6

Please sign in to comment.