This commit is contained in:
14
app/app.go
14
app/app.go
@@ -18,12 +18,14 @@ const VERSION = "1.0.6"
|
|||||||
|
|
||||||
// Arguments описывает аргументы командной строки
|
// Arguments описывает аргументы командной строки
|
||||||
type Arguments struct {
|
type Arguments struct {
|
||||||
IniPath string
|
IniPath string
|
||||||
TagsPath string
|
TagsPath string
|
||||||
RandomCount uint
|
RandomCount uint
|
||||||
NeedJson bool
|
RepeatCount uint
|
||||||
NeedQuiet bool
|
RepeatEverySec uint
|
||||||
Verbose bool
|
NeedJson bool
|
||||||
|
NeedQuiet bool
|
||||||
|
Verbose bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
55
cmd/check.go
55
cmd/check.go
@@ -29,20 +29,49 @@ var checkCmd = &cobra.Command{
|
|||||||
codes, _ := cmd.Flags().GetStringSlice("code")
|
codes, _ := cmd.Flags().GetStringSlice("code")
|
||||||
lists := checker.PrepareListsToCheck(files, urls, codes)
|
lists := checker.PrepareListsToCheck(files, urls, codes)
|
||||||
|
|
||||||
startTime := time.Now()
|
waitSeconds := app.Args.RepeatEverySec
|
||||||
onlineCount, offlineCount := checker.CheckPlaylists(lists)
|
if waitSeconds <= 0 {
|
||||||
|
waitSeconds = 5
|
||||||
|
}
|
||||||
|
|
||||||
log.Printf(
|
currentIteration := 1
|
||||||
"Done! count=%d online=%d offline=%d elapsedTime=%.2fs\n",
|
iterationCount := app.Args.RepeatCount
|
||||||
len(lists),
|
if iterationCount <= 0 {
|
||||||
onlineCount,
|
iterationCount = 1
|
||||||
offlineCount,
|
}
|
||||||
time.Since(startTime).Seconds(),
|
|
||||||
)
|
|
||||||
|
|
||||||
if app.Args.NeedJson {
|
for {
|
||||||
marshal, _ := json.Marshal(lists)
|
if app.Args.RepeatCount > 1 {
|
||||||
fmt.Println(string(marshal))
|
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.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().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.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.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().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)")
|
checkCmd.Flags().StringSliceP("file", "f", []string{}, "path to a local playlist file (m3u/m3u8)")
|
||||||
|
|||||||
Reference in New Issue
Block a user