-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (45 loc) · 1005 Bytes
/
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
package main
import (
"fmt"
"github.com/urfave/cli/v2"
"log"
"os"
"sanjieke/config"
"sanjieke/pkg"
)
func main() {
app := cli.App{
Name: "下载器",
Flags: Flags(),
Version: "1.0.0",
Action: mainLoop,
}
if err := app.Run(os.Args); err != nil {
log.Println("!!程序运行错误 ===> ", err.Error())
return
}
}
func mainLoop(c *cli.Context) error {
if cmdFlags.Ffmpeg != "" {
config.Config.FfmpegPath = cmdFlags.Ffmpeg
}
if cmdFlags.Config != "" {
err := pkg.YamlReader(cmdFlags.Config, config.Config)
if err != nil {
return fmt.Errorf("读取配置文件错误:%v", err.Error())
}
} else {
if !checkInputConfig() {
return fmt.Errorf("请检查输入参数")
}
}
if config.Config.FfmpegPath == "" {
return fmt.Errorf("请检查ffmpeg路径")
}
err := downloadCourse()
if err != nil {
return fmt.Errorf("下载课程错误:%v", err.Error())
}
fmt.Printf("课程 [%v] 全部下载完成,再见!\n", config.Config.Title)
return nil
}