diff --git a/app/checker/checker.go b/app/checker/checker.go index 0dce5ec..51959b8 100644 --- a/app/checker/checker.go +++ b/app/checker/checker.go @@ -13,8 +13,6 @@ import ( "axenov/iptv-checker/app/tagfile" "axenov/iptv-checker/app/utils" "crypto/tls" - "encoding/json" - "fmt" "io" "log" "maps" @@ -82,8 +80,8 @@ func PrepareListsToCheck(files []string, urls []string, codes []string) []playli } // CheckPlaylists проверяет плейлисты и возвращает их же с результатами проверки -func CheckPlaylists(lists []playlist.Playlist) { - step := 0 +func CheckPlaylists(lists []playlist.Playlist) (int, int) { + step, onlineCount, offlineCount := 0, 0, 0 count := len(lists) tagBlocks = tagfile.Init(app.Args.TagsPath) @@ -115,12 +113,14 @@ func CheckPlaylists(lists []playlist.Playlist) { } if err != nil { - log.Printf("Cannot read playlist [%s]: %s", pls.Url, err) + log.Printf("Cannot read playlist [%s]: %s\n", pls.Url, err) + offlineCount++ continue } log.Println("Parsing content...") pls.IsOnline = true + onlineCount++ pls = pls.Parse() log.Printf("Parsed, checking channels (%d)...\n", len(pls.Channels)) @@ -129,10 +129,7 @@ func CheckPlaylists(lists []playlist.Playlist) { lists[idx] = pls } - if app.Args.NeedJson { - marshal, _ := json.Marshal(lists) - fmt.Println(string(marshal)) - } + return onlineCount, offlineCount } // CheckChannels проверяет каналы и возвращает их же с результатами проверки diff --git a/cmd/check.go b/cmd/check.go index f093175..f221bcf 100644 --- a/cmd/check.go +++ b/cmd/check.go @@ -10,8 +10,11 @@ import ( "axenov/iptv-checker/app" "axenov/iptv-checker/app/checker" "axenov/iptv-checker/app/logger" + "encoding/json" + "fmt" "github.com/spf13/cobra" "log" + "time" ) // checkCmd represents the file command @@ -26,8 +29,21 @@ var checkCmd = &cobra.Command{ codes, _ := cmd.Flags().GetStringSlice("code") lists := checker.PrepareListsToCheck(files, urls, codes) - checker.CheckPlaylists(lists) - log.Println("Done!") + 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)) + } }, }