-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.go
81 lines (71 loc) · 2.21 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
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"flag"
"fmt"
"os"
"sync"
"github.com/mattetti/m3u8Grabber/m3u8"
"github.com/mattetti/m3u8Grabber/server"
)
// Flags
var (
m3u8Url = flag.String("m3u8", "", "Url of the m3u8 file to download.")
m3u8File = flag.String("m3u8File", "", "path to file to use")
outputFileName = flag.String("output", "downloaded_video", "The name of the output file without the extension.")
httpProxy = flag.String("http_proxy", "", "The url of the HTTP proxy to use.")
socksProxy = flag.String("socks_proxy", "", "<host>:<port> of the socks5 proxy to use.")
debug = flag.Bool("debug", false, "Enable debugging messages.")
subsOnly = flag.Bool("subsOnly", false, "Only download the subtitles.")
serverPort = flag.Int("server_port", 13535, "The port to run the http server on.")
serverMode = flag.Bool("server", false, "Enable running a local web server (not working yet).")
dlRootDir = flag.String("root_dir", "/tmp", "The root dir to download files to")
mp4Conv = flag.Bool("mp4", true, "should try to convert to mp4")
)
func m3u8ArgCheck() {
if *m3u8Url == "" && !*serverMode {
if len(os.Args) < 2 {
fmt.Fprint(os.Stderr, "You have to pass a m3u8 url file using the right flag or enable the server mode.\n")
os.Exit(2)
return
} else {
// backup in case the user didn't use flags but passed params instead
*m3u8Url = os.Args[1]
if *outputFileName == "downloaded_video" && len(os.Args) > 2 {
*outputFileName = os.Args[2]
}
}
}
}
func main() {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s \n", os.Args[0])
flag.PrintDefaults()
}
flag.Parse()
m3u8ArgCheck()
m3u8.Debug = *debug
// Working dir
pathToUse, err := os.Getwd()
if err != nil {
panic(err)
}
if *m3u8Url != "" {
w := &sync.WaitGroup{}
stopChan := make(chan bool)
m3u8.LaunchWorkers(w, stopChan)
job := &m3u8.WJob{
Type: m3u8.ListDL,
URL: *m3u8Url,
SubsOnly: *subsOnly,
SkipConverter: !*mp4Conv,
DestPath: pathToUse,
Filename: *outputFileName}
m3u8.DlChan <- job
close(m3u8.DlChan)
w.Wait()
}
// server mode
if *serverMode {
server.Start(*serverPort, *dlRootDir, *httpProxy, *socksProxy)
}
}