forked from 0xleizhang/video-srt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
69 lines (62 loc) · 1.35 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"fmt"
"log"
"os"
"github.com/seven4x/videosrt/app"
"github.com/spf13/cobra"
)
var (
fileName string
instance = app.NewByConfig(CONFIG)
)
//定义配置文件
const CONFIG = "config-prod.ini"
var rootCmd = &cobra.Command{
Use: "srt",
Short: "srt",
Long: `srt`,
Run: func(cmd *cobra.Command, args []string) {
if fileName == "" {
println("缺少参数")
return
}
instance.Run(fileName)
},
}
var mp3Cmd = &cobra.Command{
Use: "audio",
Short: "audio",
Long: `audio`,
Run: func(cmd *cobra.Command, args []string) {
instance.RunWithoutExtract(fileName)
},
}
var clearCmd = &cobra.Command{
Use: "clear",
Short: "clear",
Long: `clear`,
Run: func(cmd *cobra.Command, args []string) {
instance.ClearOssFile(app.GetMp3FileList(app.Mp3UploadRecord))
log.Print("清除成功")
err := os.Remove(app.Mp3UploadRecord)
if err != nil {
log.Fatal(err.Error())
}
},
}
func Execute() {
rootCmd.PersistentFlags().StringVarP(&fileName, "fileName", "f", "demo.mp4", "fileName")
mp3Cmd.PersistentFlags().StringVarP(&fileName, "fileName", "f", "demo.mp4", "fileName")
_ = rootCmd.MarkFlagRequired("fileName")
_ = mp3Cmd.MarkFlagRequired("fileName")
rootCmd.AddCommand(mp3Cmd)
rootCmd.AddCommand(clearCmd)
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
func main() {
Execute()
}