From a346d9e2d78b34b74b1baad060a44df60c9c6f43 Mon Sep 17 00:00:00 2001 From: AnthonyAxenov Date: Tue, 6 May 2025 22:52:26 +0800 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D0=B8=D0=B3=D0=BD?= =?UTF-8?q?=D0=BE=D1=80=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D1=84=D0=BB=D0=B0=D0=B3=D0=BE=D0=B2=20-f/-u/-c=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B8=20=D0=BD=D0=B0=D0=BB=D0=B8=D1=87=D0=B8=D0=B8=20playlists?= =?UTF-8?q?.ini?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/checker/checker.go | 40 +++++++++++++++++++++------------------- cmd/check.go | 9 ++------- 2 files changed, 23 insertions(+), 26 deletions(-) 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!") }, }