diff --git a/app/app.go b/app/app.go index 7c27e27..3086446 100644 --- a/app/app.go +++ b/app/app.go @@ -18,12 +18,14 @@ const VERSION = "1.0.6" // Arguments описывает аргументы командной строки type Arguments struct { - IniPath string - TagsPath string - RandomCount uint - NeedJson bool - NeedQuiet bool - Verbose bool + IniPath string + TagsPath string + RandomCount uint + RepeatCount uint + RepeatEverySec uint + NeedJson bool + NeedQuiet bool + Verbose bool } var ( diff --git a/cmd/check.go b/cmd/check.go index 155d0d2..6698eb9 100644 --- a/cmd/check.go +++ b/cmd/check.go @@ -29,20 +29,49 @@ var checkCmd = &cobra.Command{ codes, _ := cmd.Flags().GetStringSlice("code") lists := checker.PrepareListsToCheck(files, urls, codes) - startTime := time.Now() - onlineCount, offlineCount := checker.CheckPlaylists(lists) + waitSeconds := app.Args.RepeatEverySec + if waitSeconds <= 0 { + waitSeconds = 5 + } - log.Printf( - "Done! count=%d online=%d offline=%d elapsedTime=%.2fs\n", - len(lists), - onlineCount, - offlineCount, - time.Since(startTime).Seconds(), - ) + currentIteration := 1 + iterationCount := app.Args.RepeatCount + if iterationCount <= 0 { + iterationCount = 1 + } - if app.Args.NeedJson { - marshal, _ := json.Marshal(lists) - fmt.Println(string(marshal)) + for { + if app.Args.RepeatCount > 1 { + log.Printf( + "@ New iteration current=%d count=%d\n", + currentIteration, + app.Args.RepeatCount, + ) + } + + startTime := time.Now() + onlineCount, offlineCount := checker.CheckPlaylists(lists) + + log.Printf( + "Done! count=%d online=%d offline=%d elapsedTime=%.2fs\n", + len(lists), + onlineCount, + offlineCount, + time.Since(startTime).Seconds(), + ) + + if app.Args.NeedJson { + marshal, _ := json.Marshal(lists) + fmt.Println(string(marshal)) + } + + if app.Args.RepeatCount <= 1 || uint(currentIteration) == app.Args.RepeatCount { + break + } + + currentIteration++ + log.Printf("Waiting for new iteration... seconds=%d\n", app.Args.RepeatEverySec) + time.Sleep(time.Duration(app.Args.RepeatEverySec) * time.Second) } }, } @@ -51,6 +80,8 @@ func init() { checkCmd.Flags().StringVarP(&app.Args.TagsPath, "tags", "t", "./channels.json", "path to a local tagfile") checkCmd.Flags().StringVarP(&app.Args.IniPath, "ini", "i", "./playlists.ini", "path to a local ini-file") checkCmd.Flags().UintVarP(&app.Args.RandomCount, "random", "r", 0, "take this count of random playlists to check from ini-file") + checkCmd.Flags().UintVarP(&app.Args.RepeatCount, "repeat", "", 1, "repeat same check X times") + checkCmd.Flags().UintVarP(&app.Args.RepeatEverySec, "every", "", 5, "wait N seconds after every check") checkCmd.Flags().BoolVarP(&app.Args.NeedJson, "json", "j", false, "print results in JSON format in the end") checkCmd.Flags().BoolVarP(&app.Args.NeedQuiet, "quiet", "q", false, "suppress logs (does not affect on -j)") checkCmd.Flags().StringSliceP("file", "f", []string{}, "path to a local playlist file (m3u/m3u8)")