This commit is contained in:
49
cmd/check.go
Normal file
49
cmd/check.go
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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"
|
||||
"axenov/iptv-checker/app/logger"
|
||||
"github.com/spf13/cobra"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
// checkCmd represents the file command
|
||||
var checkCmd = &cobra.Command{
|
||||
Use: "check",
|
||||
Short: "Check playlists",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
logger.Init(app.Args.NeedQuiet)
|
||||
|
||||
files, _ := cmd.Flags().GetStringSlice("file")
|
||||
urls, _ := cmd.Flags().GetStringSlice("url")
|
||||
codes, _ := cmd.Flags().GetStringSlice("code")
|
||||
|
||||
if len(files) < 1 && len(urls) < 1 && len(codes) < 1 {
|
||||
log.Println("ERROR: You should provide at least one of --file, --url or --code flags")
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
lists := checker.PrepareListsToCheck(files, urls, codes)
|
||||
checker.CheckPlaylists(lists)
|
||||
},
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
39
cmd/root.go
Normal file
39
cmd/root.go
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// rootCmd represents the base command when called without any subcommands
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "iptvc",
|
||||
Short: "Simple utility to check iptv playlists. Part of iptv.axenov.dev project.",
|
||||
Long: `Simple utility to check iptv playlists. Part of iptv.axenov.dev project.
|
||||
Copyright (c) 2025, Антон Аксенов, MIT license.`,
|
||||
// Uncomment the following line if your bare application
|
||||
// has an action associated with it:
|
||||
// Run: func(cmd *cobra.Command, args []string) { },
|
||||
}
|
||||
|
||||
// Execute adds all child commands to the root command and sets flags appropriately.
|
||||
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
||||
func Execute() {
|
||||
app.Init()
|
||||
err := rootCmd.Execute()
|
||||
if err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.PersistentFlags().BoolVarP(&app.Args.Verbose, "verbose", "v", false, "enable additional output")
|
||||
}
|
||||
27
cmd/version.go
Normal file
27
cmd/version.go
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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"
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// versionCmd represents the version command
|
||||
var versionCmd = &cobra.Command{
|
||||
Use: "version",
|
||||
Short: "Show version",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("iptvc v" + app.VERSION)
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(versionCmd)
|
||||
}
|
||||
Reference in New Issue
Block a user