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