Commit 2b609e9bec

2b609e9bec2966aa1ab62ffb793b8e7bb0ba05a5

parent: e4b3096cd6

Unregistered key

Rushikesh Gaikwad <81632222+Wraient@users.noreply.github.com> · 2025-02-05 14:31 UTC
committer: <noreply@github.com>

Add: add custom mpv flags (#33)

Layout: unified · split

cmd/curd/main.go +1 −1
@@ -203,7 +203,7 @@ func main() {
203 } else { 203 } else {
204 anime.FillerEpisodes = fillerList 204 anime.FillerEpisodes = fillerList
205 internal.Log("Filler list fetched successfully", logFile) 205 internal.Log("Filler list fetched successfully", logFile)
206 fmt.Println("Filler episodes: ", anime.FillerEpisodes) 206 // fmt.Println("Filler episodes: ", anime.FillerEpisodes)
207 } 207 }
208 }() 208 }()
209 209
internal/config.go +59 −24
@@ -14,35 +14,37 @@ import (
14 14
15// CurdConfig struct with field names that match the config keys 15// CurdConfig struct with field names that match the config keys
16type CurdConfig struct { 16type CurdConfig struct {
17 Player string `config:"Player"` 17 Player string `config:"Player"`
18 SubsLanguage string `config:"SubsLanguage"` 18 MpvArgs []string `config:MpvArgs`
19 SubOrDub string `config:"SubOrDub"` 19 SubsLanguage string `config:"SubsLanguage"`
20 StoragePath string `config:"StoragePath"` 20 SubOrDub string `config:"SubOrDub"`
21 AnimeNameLanguage string `config:"AnimeNameLanguage"` 21 StoragePath string `config:"StoragePath"`
22 PercentageToMarkComplete int `config:"PercentageToMarkComplete"` 22 AnimeNameLanguage string `config:"AnimeNameLanguage"`
23 NextEpisodePrompt bool `config:"NextEpisodePrompt"` 23 PercentageToMarkComplete int `config:"PercentageToMarkComplete"`
24 SkipOp bool `config:"SkipOp"` 24 NextEpisodePrompt bool `config:"NextEpisodePrompt"`
25 SkipEd bool `config:"SkipEd"` 25 SkipOp bool `config:"SkipOp"`
26 SkipFiller bool `config:"SkipFiller"` 26 SkipEd bool `config:"SkipEd"`
27 ImagePreview bool `config:"ImagePreview"` 27 SkipFiller bool `config:"SkipFiller"`
28 SkipRecap bool `config:"SkipRecap"` 28 ImagePreview bool `config:"ImagePreview"`
29 RofiSelection bool `config:"RofiSelection"` 29 SkipRecap bool `config:"SkipRecap"`
30 CurrentCategory bool `config:"CurrentCategory"` 30 RofiSelection bool `config:"RofiSelection"`
31 ScoreOnCompletion bool `config:"ScoreOnCompletion"` 31 CurrentCategory bool `config:"CurrentCategory"`
32 SaveMpvSpeed bool `config:"SaveMpvSpeed"` 32 ScoreOnCompletion bool `config:"ScoreOnCompletion"`
33 AddMissingOptions bool `config:"AddMissingOptions"` 33 SaveMpvSpeed bool `config:"SaveMpvSpeed"`
34 AlternateScreen bool `config:"AlternateScreen"` 34 AddMissingOptions bool `config:"AddMissingOptions"`
35 DiscordPresence bool `config:"DiscordPresence"` 35 AlternateScreen bool `config:"AlternateScreen"`
36 DiscordPresence bool `config:"DiscordPresence"`
36} 37}
37 38
38// Default configuration values as a map 39// Default configuration values as a map
39func defaultConfigMap() map[string]string { 40func defaultConfigMap() map[string]string {
40 return map[string]string{ 41 return map[string]string{
41 "Player": "mpv", 42 "Player": "mpv",
42 "StoragePath": "$HOME/.local/share/curd", 43 "MpvArgs": "[]",
43 "AnimeNameLanguage": "english", 44 "StoragePath": "$HOME/.local/share/curd",
44 "SubsLanguage": "english", 45 "AnimeNameLanguage": "english",
45 "SubOrDub": "sub", 46 "SubsLanguage": "english",
47 "SubOrDub": "sub",
46 "PercentageToMarkComplete": "85", 48 "PercentageToMarkComplete": "85",
47 "NextEpisodePrompt": "false", 49 "NextEpisodePrompt": "false",
48 "SkipOp": "true", 50 "SkipOp": "true",
@@ -69,6 +71,29 @@ func GetGlobalConfig() *CurdConfig {
69 return globalConfig 71 return globalConfig
70} 72}
71 73
74// Helper function to parse string array from config
75func parseStringArray(value string) []string {
76 // Remove brackets and split by comma
77 value = strings.TrimPrefix(value, "[")
78 value = strings.TrimSuffix(value, "]")
79 if value == "" {
80 return nil
81 }
82
83 // Split by comma and trim spaces and quotes from each element
84 parts := strings.Split(value, ",")
85 result := make([]string, 0, len(parts))
86 for _, part := range parts {
87 // Trim spaces and quotes
88 part = strings.TrimSpace(part)
89 part = strings.Trim(part, "\"")
90 if part != "" {
91 result = append(result, part)
92 }
93 }
94 return result
95}
96
72// LoadConfig reads or creates the config file, adds missing fields, and returns the populated CurdConfig struct 97// LoadConfig reads or creates the config file, adds missing fields, and returns the populated CurdConfig struct
73func LoadConfig(configPath string) (CurdConfig, error) { 98func LoadConfig(configPath string) (CurdConfig, error) {
74 configPath = os.ExpandEnv(configPath) // Substitute environment variables like $HOME 99 configPath = os.ExpandEnv(configPath) // Substitute environment variables like $HOME
@@ -111,6 +136,11 @@ func LoadConfig(configPath string) (CurdConfig, error) {
111 } 136 }
112 } 137 }
113 138
139 // Parse string arrays
140 if mpvArgs, exists := configMap["MpvArgs"]; exists {
141 configMap["MpvArgs"] = mpvArgs
142 }
143
114 // Populate the CurdConfig struct from the config map 144 // Populate the CurdConfig struct from the config map
115 config := populateConfig(configMap) 145 config := populateConfig(configMap)
116 146
@@ -279,5 +309,10 @@ func populateConfig(configMap map[string]string) CurdConfig {
279 } 309 }
280 } 310 }
281 311
312 // Handle MpvArgs specially
313 if mpvArgs, exists := configMap["MpvArgs"]; exists {
314 config.MpvArgs = parseStringArray(mpvArgs)
315 }
316
282 return config 317 return config
283} 318}
internal/player.go +7
@@ -30,6 +30,13 @@ func StartVideo(link string, args []string, title string, anime *Anime) (string,
30 var mpvSocketPath string 30 var mpvSocketPath string
31 var err error 31 var err error
32 32
33 userConfig := GetGlobalConfig()
34
35 // Add custom MPV arguments from config if they exist
36 if userConfig.MpvArgs != nil {
37 args = append(args, userConfig.MpvArgs...)
38 }
39
33 // Check if we have an existing socket and if MPV is still running 40 // Check if we have an existing socket and if MPV is still running
34 if anime.Ep.Player.SocketPath != "" && IsMPVRunning(anime.Ep.Player.SocketPath) { 41 if anime.Ep.Player.SocketPath != "" && IsMPVRunning(anime.Ep.Player.SocketPath) {
35 // Reuse existing socket 42 // Reuse existing socket