diff --git a/app/checker/checker.go b/app/checker/checker.go index e4defda..fd480ca 100644 --- a/app/checker/checker.go +++ b/app/checker/checker.go @@ -53,26 +53,28 @@ func PrepareListsToCheck(files []string, urls []string, codes []string) []playli } } - ini, err := inifile.Init(app.Args.IniPath) - if err != nil { - log.Printf("Warning: %s, all --code flags will be ignored\n", err) - return lists - } - - if len(codes) > 0 { - for _, plsCode := range codes { - list := ini.Lists[plsCode] - if list.Url == "" { - log.Printf("Warning: playlist [%s] not found in ini-file, skipping\n", plsCode) - continue - } - lists = append(lists, list) + if len(lists) == 0 || len(codes) > 0 { + ini, err := inifile.Init(app.Args.IniPath) + if err != nil { + log.Printf("Warning: %s, all --code flags will be ignored\n", err) + return lists } - } else { - lists = slices.Collect(maps.Values(ini.Lists)) - if int(app.Args.RandomCount) > 0 && int(app.Args.RandomCount) <= len(lists) { - rand.Shuffle(len(lists), func(i int, j int) { lists[i], lists[j] = lists[j], lists[i] }) - lists = lists[:app.Args.RandomCount] + + if len(codes) > 0 { + for _, plsCode := range codes { + list := ini.Lists[plsCode] + if list.Url == "" { + log.Printf("Warning: playlist [%s] not found in ini-file, skipping\n", plsCode) + continue + } + lists = append(lists, list) + } + } else { + lists = slices.Collect(maps.Values(ini.Lists)) + if int(app.Args.RandomCount) > 0 && int(app.Args.RandomCount) <= len(lists) { + rand.Shuffle(len(lists), func(i int, j int) { lists[i], lists[j] = lists[j], lists[i] }) + lists = lists[:app.Args.RandomCount] + } } } diff --git a/cmd/check.go b/cmd/check.go index 3b22abf..f093175 100644 --- a/cmd/check.go +++ b/cmd/check.go @@ -12,7 +12,6 @@ import ( "axenov/iptv-checker/app/logger" "github.com/spf13/cobra" "log" - "os" ) // checkCmd represents the file command @@ -25,14 +24,10 @@ var checkCmd = &cobra.Command{ files, _ := cmd.Flags().GetStringSlice("file") urls, _ := cmd.Flags().GetStringSlice("url") codes, _ := cmd.Flags().GetStringSlice("code") - - if len(files) < 1 && len(urls) < 1 && len(codes) < 1 { - log.Println("ERROR: You should provide at least one of --file, --url or --code flags") - os.Exit(2) - } - lists := checker.PrepareListsToCheck(files, urls, codes) + checker.CheckPlaylists(lists) + log.Println("Done!") }, }