Фикс игнорирования флагов -f/-u/-c при наличии playlists.ini

This commit is contained in:
2025-05-06 22:52:26 +08:00
parent 9c4f09db81
commit a346d9e2d7
2 changed files with 23 additions and 26 deletions

View File

@@ -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]
}
}
}

View File

@@ -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!")
},
}