This commit is contained in:
2026-05-30 09:24:42 +08:00
parent 6c3de4b2ef
commit e054f458bb
17 changed files with 533 additions and 78 deletions

View File

@@ -9,7 +9,6 @@ package cmd
import (
"axenov/iptv-checker/app"
"axenov/iptv-checker/app/checker"
"axenov/iptv-checker/app/playlist"
"encoding/json"
"fmt"
"log"
@@ -44,18 +43,14 @@ var checkCmd = &cobra.Command{
)
}
var lists []playlist.Playlist
if len(files) == 0 && len(urls) == 0 && len(codes) == 0 {
lists = checker.PrepareListsToCheck(files, urls, codes)
} else {
if currentIteration == 1 {
lists = checker.PrepareListsToCheck(files, urls, codes)
}
}
ch := checker.NewChecker(app.Args.TagsPath)
lists := ch.PrepareListsToCheck(files, urls, codes)
if len(lists) > 0 {
startTime := time.Now()
onlineCount, offlineCount := checker.CheckPlaylists(lists)
ctx := cmd.Context()
onlineCount, offlineCount := ch.CheckPlaylists(ctx, lists)
log.Printf(
"Done! count=%d online=%d offline=%d elapsedTime=%.2fs\n",
@@ -66,8 +61,12 @@ var checkCmd = &cobra.Command{
)
if app.Args.NeedJson {
marshal, _ := json.Marshal(lists)
fmt.Println(string(marshal))
marshal, err := json.Marshal(lists)
if err != nil {
log.Printf("Error marshaling results: %s", err)
} else {
fmt.Println(string(marshal))
}
}
} else {
log.Println("There are no playlists to check")

View File

@@ -8,6 +8,7 @@ package cmd
import (
"axenov/iptv-checker/app"
"context"
"os"
"github.com/spf13/cobra"
@@ -33,6 +34,11 @@ func Execute() {
}
}
// ExecuteContext runs the root command with the given context.
func ExecuteContext(ctx context.Context) error {
return rootCmd.ExecuteContext(ctx)
}
func init() {
rootCmd.PersistentFlags().BoolVarP(&app.Args.Verbose, "verbose", "v", false, "enable additional output")
}

View File

@@ -18,7 +18,7 @@ var versionCmd = &cobra.Command{
Use: "version",
Short: "Show version",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("iptvc v" + app.VERSION)
fmt.Println("iptvc v" + app.Version())
},
}