forked from oopsguy/m3u8
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
54 lines (48 loc) · 956 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
54
package main
import (
"flag"
"fmt"
"os"
"github.com/oopsguy/m3u8/dl"
)
var (
url string
output string
chanSize int
filename string
)
func init() {
flag.StringVar(&url, "u", "", "M3U8 URL, required")
flag.IntVar(&chanSize, "c", 25, "Maximum number of occurrences")
flag.StringVar(&output, "o", "", "Output folder, required")
flag.StringVar(&filename, "f", "", "filename, required")
}
func main() {
flag.Parse()
defer func() {
if r := recover(); r != nil {
fmt.Println("[error]", r)
os.Exit(-1)
}
}()
if url == "" {
panicParameter("u")
}
if output == "" {
panicParameter("o")
}
if chanSize <= 0 {
panic("parameter 'c' must be greater than 0")
}
downloader, err := dl.NewTask(output, url, filename)
if err != nil {
panic(err)
}
if err := downloader.Start(chanSize); err != nil {
panic(err)
}
fmt.Println("Done!")
}
func panicParameter(name string) {
panic("parameter '" + name + "' is required")
}