| @@ -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 |
| 16 | type CurdConfig struct { |
16 | type 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 |
| 39 | func defaultConfigMap() map[string]string { |
40 | func 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 |
| |
75 | func 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 |
| 73 | func LoadConfig(configPath string) (CurdConfig, error) { |
98 | func 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 | } |