-
Notifications
You must be signed in to change notification settings - Fork 0
/
avrp.go
114 lines (97 loc) · 2.4 KB
/
avrp.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package main
import (
"bufio"
"errors"
"flag"
"fmt"
"io/fs"
"log"
"os"
"github.com/mysterion/avrp/internal/dist"
"github.com/mysterion/avrp/internal/server"
"github.com/mysterion/avrp/internal/thumbnails"
"github.com/mysterion/avrp/internal/utils"
)
func isPathValid(path string) bool {
_, err := os.Stat(path)
return !errors.Is(err, fs.ErrNotExist)
}
func getUserInput(prompt string) string {
fmt.Println(prompt + ": ")
scanner := bufio.NewScanner(os.Stdin)
scanner.Scan()
return scanner.Text()
}
func askForPath() string {
for {
path := getUserInput("Please enter path to serve")
if isPathValid(path) {
return path
} else {
fmt.Println("Invalid Path")
}
}
}
func main() {
log.SetFlags(log.Lshortfile | log.LstdFlags)
var servDir string
var sha string
var update bool
var reset bool
var port int
var getFfmpeg bool
var noThumb bool
flag.BoolVar(&utils.DEV, "dev", false, "starts in dev mode, serves 'index.html' from current directory")
flag.BoolVar(&update, "update", false, "checks & downloads the latest version(commit) of 'aframe-vr-player'")
flag.StringVar(&sha, "sha", "latest", "Optional - download a specific commit of aframe-vr-player")
flag.StringVar(&servDir, "dir", "", "path to video files")
flag.BoolVar(&reset, "reset", false, "removes all configs, thumbnails & 'aframe-vr-player' files")
flag.IntVar(&port, "port", 5000, "port to serve on (default 5000)")
flag.BoolVar(&getFfmpeg, "get-ffmpeg", false, "downloads ffmpeg")
flag.BoolVar(&noThumb, "no-thumb", false, "disable/enable thumbnail generation")
flag.Parse()
utils.Init()
// commands 👇
if getFfmpeg {
utils.Panic(thumbnails.DownloadFfmpeg())
return
}
if noThumb {
if thumbnails.NoThumb() {
thumbnails.NoThumbFileRemove()
log.Println("thumbnail generation enabled👍")
} else {
thumbnails.NoThumbFileCreate()
log.Println("thumbnail generation disabled👎")
}
return
}
if reset {
err := os.RemoveAll(utils.ConfigDir)
if err != nil {
log.Panicln(err)
} else {
log.Printf("Success! removed dir : %s\n", utils.ConfigDir)
}
return
}
if update {
dist.Update(sha)
return
}
// commands 👆
// running for the first time
if !dist.Valid() && !utils.DEV {
dist.Update("latest")
}
if len(servDir) == 0 {
servDir = askForPath()
} else {
if !isPathValid(servDir) {
servDir = askForPath()
}
}
thumbnails.Init()
server.Init(servDir)
server.Start(port)
}