Files
iptvc/cmd/check.go

60 lines
1.9 KiB
Go

/*
* Copyright (c) 2025, Антон Аксенов
* This file is part of iptvc project
* MIT License: https://git.axenov.dev/IPTV/iptvc/src/branch/master/LICENSE
*/
package cmd
import (
"axenov/iptv-checker/app"
"axenov/iptv-checker/app/checker"
"encoding/json"
"fmt"
"github.com/spf13/cobra"
"log"
"time"
)
// checkCmd represents the file command
var checkCmd = &cobra.Command{
Use: "check",
Short: "Check playlists",
Run: func(cmd *cobra.Command, args []string) {
app.Init()
files, _ := cmd.Flags().GetStringSlice("file")
urls, _ := cmd.Flags().GetStringSlice("url")
codes, _ := cmd.Flags().GetStringSlice("code")
lists := checker.PrepareListsToCheck(files, urls, codes)
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))
}
},
}
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().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)")
checkCmd.Flags().StringSliceP("url", "u", []string{}, "URL to a remote playlist (http/https)")
checkCmd.Flags().StringSliceP("code", "c", []string{}, "code of playlist from ini-file")
rootCmd.AddCommand(checkCmd)
}