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() {
203203 } else {
204204 anime.FillerEpisodes = fillerList
205205 internal.Log("Filler list fetched successfully", logFile)
206 fmt.Println("Filler episodes: ", anime.FillerEpisodes)
206 // fmt.Println("Filler episodes: ", anime.FillerEpisodes)
207207 }
208208 }()
209209
internal/config.go +59 −24
@@ -14,35 +14,37 @@ import (
1414
1515// CurdConfig struct with field names that match the config keys
1616type CurdConfig struct {
17 Player string `config:"Player"`
18 SubsLanguage string `config:"SubsLanguage"`
19 SubOrDub string `config:"SubOrDub"`
20 StoragePath string `config:"StoragePath"`
21 AnimeNameLanguage string `config:"AnimeNameLanguage"`
22 PercentageToMarkComplete int `config:"PercentageToMarkComplete"`
23 NextEpisodePrompt bool `config:"NextEpisodePrompt"`
24 SkipOp bool `config:"SkipOp"`
25 SkipEd bool `config:"SkipEd"`
26 SkipFiller bool `config:"SkipFiller"`
27 ImagePreview bool `config:"ImagePreview"`
28 SkipRecap bool `config:"SkipRecap"`
29 RofiSelection bool `config:"RofiSelection"`
30 CurrentCategory bool `config:"CurrentCategory"`
31 ScoreOnCompletion bool `config:"ScoreOnCompletion"`
32 SaveMpvSpeed bool `config:"SaveMpvSpeed"`
33 AddMissingOptions bool `config:"AddMissingOptions"`
34 AlternateScreen bool `config:"AlternateScreen"`
35 DiscordPresence bool `config:"DiscordPresence"`
17 Player string `config:"Player"`
18 MpvArgs []string `config:MpvArgs`
19 SubsLanguage string `config:"SubsLanguage"`
20 SubOrDub string `config:"SubOrDub"`
21 StoragePath string `config:"StoragePath"`
22 AnimeNameLanguage string `config:"AnimeNameLanguage"`
23 PercentageToMarkComplete int `config:"PercentageToMarkComplete"`
24 NextEpisodePrompt bool `config:"NextEpisodePrompt"`
25 SkipOp bool `config:"SkipOp"`
26 SkipEd bool `config:"SkipEd"`
27 SkipFiller bool `config:"SkipFiller"`
28 ImagePreview bool `config:"ImagePreview"`
29 SkipRecap bool `config:"SkipRecap"`
30 RofiSelection bool `config:"RofiSelection"`
31 CurrentCategory bool `config:"CurrentCategory"`
32 ScoreOnCompletion bool `config:"ScoreOnCompletion"`
33 SaveMpvSpeed bool `config:"SaveMpvSpeed"`
34 AddMissingOptions bool `config:"AddMissingOptions"`
35 AlternateScreen bool `config:"AlternateScreen"`
36 DiscordPresence bool `config:"DiscordPresence"`
3637}
3738
3839// Default configuration values as a map
3940func defaultConfigMap() map[string]string {
4041 return map[string]string{
41 "Player": "mpv",
42 "StoragePath": "$HOME/.local/share/curd",
43 "AnimeNameLanguage": "english",
44 "SubsLanguage": "english",
45 "SubOrDub": "sub",
42 "Player": "mpv",
43 "MpvArgs": "[]",
44 "StoragePath": "$HOME/.local/share/curd",
45 "AnimeNameLanguage": "english",
46 "SubsLanguage": "english",
47 "SubOrDub": "sub",
4648 "PercentageToMarkComplete": "85",
4749 "NextEpisodePrompt": "false",
4850 "SkipOp": "true",
@@ -69,6 +71,29 @@ func GetGlobalConfig() *CurdConfig {
6971 return globalConfig
7072}
7173
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
7297// LoadConfig reads or creates the config file, adds missing fields, and returns the populated CurdConfig struct
7398func LoadConfig(configPath string) (CurdConfig, error) {
7499 configPath = os.ExpandEnv(configPath) // Substitute environment variables like $HOME
@@ -111,6 +136,11 @@ func LoadConfig(configPath string) (CurdConfig, error) {
111136 }
112137 }
113138
139 // Parse string arrays
140 if mpvArgs, exists := configMap["MpvArgs"]; exists {
141 configMap["MpvArgs"] = mpvArgs
142 }
143
114144 // Populate the CurdConfig struct from the config map
115145 config := populateConfig(configMap)
116146
@@ -279,5 +309,10 @@ func populateConfig(configMap map[string]string) CurdConfig {
279309 }
280310 }
281311
312 // Handle MpvArgs specially
313 if mpvArgs, exists := configMap["MpvArgs"]; exists {
314 config.MpvArgs = parseStringArray(mpvArgs)
315 }
316
282317 return config
283318}
internal/player.go +7
@@ -30,6 +30,13 @@ func StartVideo(link string, args []string, title string, anime *Anime) (string,
3030 var mpvSocketPath string
3131 var err error
3232
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
3340 // Check if we have an existing socket and if MPV is still running
3441 if anime.Ep.Player.SocketPath != "" && IsMPVRunning(anime.Ep.Player.SocketPath) {
3542 // Reuse existing socket