Commit adcafea6e3

adcafea6e318892a28aa1745c69e144c06b2cee7

parent: bcca33076b

Unregistered key

Rushikesh Gaikwad <81632222+Wraient@users.noreply.github.com> · 2026-03-23 12:25 UTC
committer: <noreply@github.com>

Add: IINA and mpv based player support (#82)

* Add: Mpv Based Player Support

* add --no-stdin to iina command (#81)

---------

Co-authored-by: Striker lulu <38893265+strikerlulu@users.noreply.github.com>

Layout: unified · split

README.md +3 −2
@@ -355,7 +355,7 @@ config file is located at ```~/.config/curd/curd.conf```
355355| `SkipEd` | Boolean | `true`, `false` | Automatically skips the ending of episodes when supported. |
356356| `SkipRecap` | Boolean | `true`, `false` | Skips recap sections in episodes when supported. |
357357| `ImagePreview` | Boolean | `true`, `false` | Enables or disables image previews during anime selection (only for rofi). |
358| `Player` | String | `mpv` (redundant rn) | Specifies the media player used for streaming or playing anime. |
358| `Player` | String | any mpv-compatible binary (e.g. `mpv`, `iina`) | Player binary used for playback. If not found, Curd falls back to `mpv`. |
359359| `SaveMpvSpeed` | Boolean | `true`, `false` | Retains the playback speed set in MPV for next episode. |
360360| `SkipFiller` | Boolean | `true`, `false` | Skips filler episodes when supported. |
361361| `MenuOrder` | String | Comma-separated list | Controls which menu items appear and their order. Available options: `CURRENT`, `ALL`, `UNTRACKED`, `UPDATE`, `CONTINUE_LAST`, `PLANNING`, `COMPLETED`, `PAUSED`, `DROPPED`, `REWATCHING`. Only listed items will be shown. Default: `CURRENT,ALL,UNTRACKED,UPDATE,CONTINUE_LAST` |
@@ -365,7 +365,8 @@ config file is located at ```~/.config/curd/curd.conf```
365365- Add a better way to do commands in windows (Convinience for users)
366366
367367## Dependencies
368- mpv - Video player (vlc support might be added later)
368- mpv - Video player (required fallback)
369- iina - Optional mpv-based player on macOS
369370- rofi - Selection menu
370371- ueberzug - Display images in rofi
371372
cmd/curd/main.go +1 −1
@@ -43,7 +43,7 @@ func main() {
4343 internal.ClearLogFile(logFile)
4444
4545 // Flags configured here cause userconfig needs to be changed.
46 flag.StringVar(&userCurdConfig.Player, "player", userCurdConfig.Player, "Player to use for playback (Only mpv supported currently)")
46 flag.StringVar(&userCurdConfig.Player, "player", userCurdConfig.Player, "Player binary for playback (mpv-compatible; falls back to mpv if unavailable)")
4747 flag.StringVar(&userCurdConfig.StoragePath, "storage-path", userCurdConfig.StoragePath, "Path to the storage directory")
4848 flag.StringVar(&userCurdConfig.SubsLanguage, "subs-lang", userCurdConfig.SubsLanguage, "Subtitles language")
4949 flag.IntVar(&userCurdConfig.PercentageToMarkComplete, "percentage-to-mark-complete", userCurdConfig.PercentageToMarkComplete, "Percentage to mark episode as complete")
internal/player.go +141 −30
@@ -3,7 +3,6 @@ package internal
33import (
44 "crypto/rand"
55 "encoding/json"
6 "errors"
76 "fmt"
87 "os"
98 "os/exec"
@@ -16,16 +15,137 @@ import (
1615
1716var logFile = "debug.log"
1817
19func getMPVPath() (string, error) {
18func getBundledMPVPath() (string, error) {
2019 exePath, err := os.Executable()
2120 if err != nil {
2221 return "", err
2322 }
2423 exeDir := filepath.Dir(exePath)
25 mpvPath := filepath.Join(exeDir, "bin", "mpv.exe") // Adjust the relative path
24 mpvPath := filepath.Join(exeDir, "bin", "mpv.exe")
2625 return mpvPath, nil
2726}
2827
28func resolveExecutable(binary string) (string, error) {
29 binary = strings.TrimSpace(binary)
30 if binary == "" {
31 return "", fmt.Errorf("empty binary name")
32 }
33
34 if filepath.IsAbs(binary) || strings.Contains(binary, "/") || strings.Contains(binary, "\\") {
35 if _, err := os.Stat(binary); err == nil {
36 return binary, nil
37 }
38 return "", fmt.Errorf("binary path not found: %s", binary)
39 }
40
41 resolvedPath, err := exec.LookPath(binary)
42 if err != nil {
43 return "", err
44 }
45
46 return resolvedPath, nil
47}
48
49func candidatePlayerBinaries(configuredPlayer string) []string {
50 player := strings.TrimSpace(configuredPlayer)
51 if player == "" {
52 player = "mpv"
53 }
54
55 var candidates []string
56 addUnique := func(value string) {
57 value = strings.TrimSpace(value)
58 if value == "" {
59 return
60 }
61 for _, existing := range candidates {
62 if existing == value {
63 return
64 }
65 }
66 candidates = append(candidates, value)
67 }
68
69 addUnique(player)
70
71 if strings.EqualFold(player, "iina") {
72 // iina is mpv-based and may be exposed either on PATH or via app bundle.
73 addUnique("iina")
74 if runtime.GOOS == "darwin" {
75 addUnique("/Applications/IINA.app/Contents/MacOS/IINA")
76 }
77 }
78
79 return candidates
80}
81
82func resolveMPVBinary() (string, error) {
83 if runtime.GOOS == "windows" {
84 bundledMPVPath, err := getBundledMPVPath()
85 if err == nil {
86 if _, statErr := os.Stat(bundledMPVPath); statErr == nil {
87 return bundledMPVPath, nil
88 }
89 }
90 }
91
92 return resolveExecutable("mpv")
93}
94
95func resolveConfiguredPlayerBinary(configuredPlayer string) (string, string, error) {
96 configuredPlayer = strings.TrimSpace(configuredPlayer)
97 if configuredPlayer == "" {
98 configuredPlayer = "mpv"
99 }
100
101 for _, candidate := range candidatePlayerBinaries(configuredPlayer) {
102 resolvedPath, err := resolveExecutable(candidate)
103 if err == nil {
104 return resolvedPath, configuredPlayer, nil
105 }
106 }
107
108 mpvPath, mpvErr := resolveMPVBinary()
109 if mpvErr != nil {
110 return "", "", fmt.Errorf("configured player %q was not found and fallback to mpv failed: %w", configuredPlayer, mpvErr)
111 }
112
113 if !strings.EqualFold(configuredPlayer, "mpv") {
114 warning := fmt.Sprintf("Configured player '%s' was not found. Falling back to mpv.", configuredPlayer)
115 CurdOut(warning)
116 Log(warning)
117 }
118
119 return mpvPath, "mpv", nil
120}
121
122func isIINAPlayer(effectivePlayerName string, resolvedPlayerBinary string) bool {
123 if strings.EqualFold(strings.TrimSpace(effectivePlayerName), "iina") {
124 return true
125 }
126
127 binaryName := strings.TrimSuffix(filepath.Base(resolvedPlayerBinary), filepath.Ext(resolvedPlayerBinary))
128 return strings.EqualFold(binaryName, "iina")
129}
130
131func translateMPVArgsForIINA(mpvArgs []string) []string {
132 translated := make([]string, 0, len(mpvArgs))
133 for _, arg := range mpvArgs {
134 if strings.HasPrefix(arg, "--") {
135 if strings.HasPrefix(arg, "--mpv-") {
136 translated = append(translated, arg)
137 continue
138 }
139 translated = append(translated, "--mpv-"+strings.TrimPrefix(arg, "--"))
140 continue
141 }
142
143 translated = append(translated, arg)
144 }
145
146 return translated
147}
148
29149func StartVideo(link string, args []string, title string, anime *Anime) (string, error) {
30150 var command *exec.Cmd
31151 var mpvSocketPath string
@@ -98,13 +218,14 @@ func StartVideo(link string, args []string, title string, anime *Anime) (string,
98218 args = append(args, "--force-window=yes", "--idle=yes")
99219 args = append(args, titleArgs...)
100220
101 // Prepare arguments for mpv
221 // Prepare arguments for mpv-compatible players.
102222 var mpvArgs []string
103 mpvArgs = append(mpvArgs, "--no-terminal", "--really-quiet", fmt.Sprintf("--input-ipc-server=%s", mpvSocketPath), link)
223 mpvArgs = append(mpvArgs, "--no-terminal", "--really-quiet", fmt.Sprintf("--input-ipc-server=%s", mpvSocketPath))
104224 // Add any additional arguments passed
105225 if len(args) > 0 {
106226 mpvArgs = append(mpvArgs, args...)
107227 }
228 mpvArgs = append(mpvArgs, link)
108229
109230 // Check for Android environment
110231 amPath, err := exec.LookPath("am")
@@ -128,36 +249,26 @@ func StartVideo(link string, args []string, title string, anime *Anime) (string,
128249 return "android-intent", nil
129250 }
130251
131 if runtime.GOOS == "windows" {
132 // Get the path to mpv.exe for Windows
133 mpvPath, err := getMPVPath()
134 if err != nil {
135 CurdOut("Error: Failed to get MPV path")
136 Log("Failed to get mpv path.")
137 return "", err
138 }
139
140 if _, err := os.Stat(mpvPath); err == nil {
141 command = exec.Command(mpvPath, mpvArgs...)
142
143 } else if errors.Is(err, os.ErrNotExist) {
144 //for windows with mpv on PATH
145 command = exec.Command("mpv", mpvArgs...)
252 resolvedPlayerBinary, effectivePlayerName, err := resolveConfiguredPlayerBinary(userConfig.Player)
253 if err != nil {
254 CurdOut("Error: Failed to resolve media player")
255 Log(fmt.Sprintf("Player resolution failed for '%s': %v", userConfig.Player, err))
256 return "", err
257 }
146258
147 } else {
148 Log("Failed to get mpv path.")
149 return "", err
150 }
151 } else {
152 // Create command for Unix-like systems
153 command = exec.Command("mpv", mpvArgs...)
259 playerArgs := mpvArgs
260 if isIINAPlayer(effectivePlayerName, resolvedPlayerBinary) {
261 playerArgs = translateMPVArgsForIINA(mpvArgs)
262 playerArgs = append(playerArgs, "--no-stdin")
154263 }
155264
156 // Start the mpv process
265 command = exec.Command(resolvedPlayerBinary, playerArgs...)
266
267 // Start the selected mpv-compatible player process
157268 err = command.Start()
158269 if err != nil {
159 CurdOut("Error: Failed to start mpv process")
160 return "", fmt.Errorf("failed to start mpv: %w", err)
270 CurdOut(fmt.Sprintf("Error: Failed to start %s process", effectivePlayerName))
271 return "", fmt.Errorf("failed to start %s: %w", effectivePlayerName, err)
161272 }
162273
163274 // Wait for the socket to become available with retries