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```
355| `SkipEd` | Boolean | `true`, `false` | Automatically skips the ending of episodes when supported. | 355| `SkipEd` | Boolean | `true`, `false` | Automatically skips the ending of episodes when supported. |
356| `SkipRecap` | Boolean | `true`, `false` | Skips recap sections in episodes when supported. | 356| `SkipRecap` | Boolean | `true`, `false` | Skips recap sections in episodes when supported. |
357| `ImagePreview` | Boolean | `true`, `false` | Enables or disables image previews during anime selection (only for rofi). | 357| `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`. |
359| `SaveMpvSpeed` | Boolean | `true`, `false` | Retains the playback speed set in MPV for next episode. | 359| `SaveMpvSpeed` | Boolean | `true`, `false` | Retains the playback speed set in MPV for next episode. |
360| `SkipFiller` | Boolean | `true`, `false` | Skips filler episodes when supported. | 360| `SkipFiller` | Boolean | `true`, `false` | Skips filler episodes when supported. |
361| `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` | 361| `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```
365- Add a better way to do commands in windows (Convinience for users) 365- Add a better way to do commands in windows (Convinience for users)
366 366
367## Dependencies 367## 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
369- rofi - Selection menu 370- rofi - Selection menu
370- ueberzug - Display images in rofi 371- ueberzug - Display images in rofi
371 372
cmd/curd/main.go +1 −1
@@ -43,7 +43,7 @@ func main() {
43 internal.ClearLogFile(logFile) 43 internal.ClearLogFile(logFile)
44 44
45 // Flags configured here cause userconfig needs to be changed. 45 // 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)")
47 flag.StringVar(&userCurdConfig.StoragePath, "storage-path", userCurdConfig.StoragePath, "Path to the storage directory") 47 flag.StringVar(&userCurdConfig.StoragePath, "storage-path", userCurdConfig.StoragePath, "Path to the storage directory")
48 flag.StringVar(&userCurdConfig.SubsLanguage, "subs-lang", userCurdConfig.SubsLanguage, "Subtitles language") 48 flag.StringVar(&userCurdConfig.SubsLanguage, "subs-lang", userCurdConfig.SubsLanguage, "Subtitles language")
49 flag.IntVar(&userCurdConfig.PercentageToMarkComplete, "percentage-to-mark-complete", userCurdConfig.PercentageToMarkComplete, "Percentage to mark episode as complete") 49 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
3import ( 3import (
4 "crypto/rand" 4 "crypto/rand"
5 "encoding/json" 5 "encoding/json"
6 "errors"
7 "fmt" 6 "fmt"
8 "os" 7 "os"
9 "os/exec" 8 "os/exec"
@@ -16,16 +15,137 @@ import (
16 15
17var logFile = "debug.log" 16var logFile = "debug.log"
18 17
19func getMPVPath() (string, error) { 18func getBundledMPVPath() (string, error) {
20 exePath, err := os.Executable() 19 exePath, err := os.Executable()
21 if err != nil { 20 if err != nil {
22 return "", err 21 return "", err
23 } 22 }
24 exeDir := filepath.Dir(exePath) 23 exeDir := filepath.Dir(exePath)
25 mpvPath := filepath.Join(exeDir, "bin", "mpv.exe") // Adjust the relative path 24 mpvPath := filepath.Join(exeDir, "bin", "mpv.exe")
26 return mpvPath, nil 25 return mpvPath, nil
27} 26}
28 27
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
29func StartVideo(link string, args []string, title string, anime *Anime) (string, error) { 149func StartVideo(link string, args []string, title string, anime *Anime) (string, error) {
30 var command *exec.Cmd 150 var command *exec.Cmd
31 var mpvSocketPath string 151 var mpvSocketPath string
@@ -98,13 +218,14 @@ func StartVideo(link string, args []string, title string, anime *Anime) (string,
98 args = append(args, "--force-window=yes", "--idle=yes") 218 args = append(args, "--force-window=yes", "--idle=yes")
99 args = append(args, titleArgs...) 219 args = append(args, titleArgs...)
100 220
101 // Prepare arguments for mpv 221 // Prepare arguments for mpv-compatible players.
102 var mpvArgs []string 222 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))
104 // Add any additional arguments passed 224 // Add any additional arguments passed
105 if len(args) > 0 { 225 if len(args) > 0 {
106 mpvArgs = append(mpvArgs, args...) 226 mpvArgs = append(mpvArgs, args...)
107 } 227 }
228 mpvArgs = append(mpvArgs, link)
108 229
109 // Check for Android environment 230 // Check for Android environment
110 amPath, err := exec.LookPath("am") 231 amPath, err := exec.LookPath("am")
@@ -128,36 +249,26 @@ func StartVideo(link string, args []string, title string, anime *Anime) (string,
128 return "android-intent", nil 249 return "android-intent", nil
129 } 250 }
130 251
131 if runtime.GOOS == "windows" { 252 resolvedPlayerBinary, effectivePlayerName, err := resolveConfiguredPlayerBinary(userConfig.Player)
132 // Get the path to mpv.exe for Windows 253 if err != nil {
133 mpvPath, err := getMPVPath() 254 CurdOut("Error: Failed to resolve media player")
134 if err != nil { 255 Log(fmt.Sprintf("Player resolution failed for '%s': %v", userConfig.Player, err))
135 CurdOut("Error: Failed to get MPV path") 256 return "", err
136 Log("Failed to get mpv path.") 257 }
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...)
146 258
147 } else { 259 playerArgs := mpvArgs
148 Log("Failed to get mpv path.") 260 if isIINAPlayer(effectivePlayerName, resolvedPlayerBinary) {
149 return "", err 261 playerArgs = translateMPVArgsForIINA(mpvArgs)
150 } 262 playerArgs = append(playerArgs, "--no-stdin")
151 } else {
152 // Create command for Unix-like systems
153 command = exec.Command("mpv", mpvArgs...)
154 } 263 }
155 264
156 // Start the mpv process 265 command = exec.Command(resolvedPlayerBinary, playerArgs...)
266
267 // Start the selected mpv-compatible player process
157 err = command.Start() 268 err = command.Start()
158 if err != nil { 269 if err != nil {
159 CurdOut("Error: Failed to start mpv process") 270 CurdOut(fmt.Sprintf("Error: Failed to start %s process", effectivePlayerName))
160 return "", fmt.Errorf("failed to start mpv: %w", err) 271 return "", fmt.Errorf("failed to start %s: %w", effectivePlayerName, err)
161 } 272 }
162 273
163 // Wait for the socket to become available with retries 274 // Wait for the socket to become available with retries