make prefix configurable

This commit is contained in:
Balakrishnan Balasubramanian 2022-06-14 21:09:30 -04:00
parent bc5fa6c666
commit 74d23a5ad8
2 changed files with 13 additions and 4 deletions

15
main.go
View File

@ -26,6 +26,7 @@ const port = 8080
var ( var (
ytdlCmd = []string{"youtube-dl"} ytdlCmd = []string{"youtube-dl"}
videosPath = "./vids" videosPath = "./vids"
videosUrl = "/vids"
cachePath = "./cache" cachePath = "./cache"
dbPath = "./db.json" dbPath = "./db.json"
approval bool = false approval bool = false
@ -37,19 +38,27 @@ func parse() {
ytcmd := ytdlCmd[0] ytcmd := ytdlCmd[0]
flag.StringVar(&ytcmd, "ytdlcmd", ytcmd, "youtube-dl command seperated by spaces") flag.StringVar(&ytcmd, "ytdlcmd", ytcmd, "youtube-dl command seperated by spaces")
flag.StringVar(&videosPath, "videospath", videosPath, "Path where videos are saved") flag.StringVar(&videosPath, "videospath", videosPath, "Path where videos are saved")
flag.StringVar(&videosUrl, "videosurl", videosUrl, "Prefix of the url, i.e. https://domain.com/<this var>/<video filename>")
flag.StringVar(&cachePath, "cachepath", cachePath, "Path where temporary download files are saved") flag.StringVar(&cachePath, "cachepath", cachePath, "Path where temporary download files are saved")
flag.StringVar(&dbPath, "datapath", dbPath, "Path where downloaded info is saved") flag.StringVar(&dbPath, "dbpath", dbPath, "Path where downloaded info is saved")
flag.BoolVar(&approval, "approval", approval, "Is approval required before allowing to watch") flag.BoolVar(&approval, "approval", approval, "Is approval required before allowing to watch")
flag.Parse() flag.Parse()
if ytcmd != ytdlCmd[0] { if ytcmd != ytdlCmd[0] {
ytdlCmd = strings.Fields(ytcmd) ytdlCmd = strings.Fields(ytcmd)
} }
os.MkdirAll(cachePath, 0755)
os.MkdirAll(videosPath, 0755)
os.MkdirAll(path.Dir(dbPath), 0755)
} }
func main() { func main() {
fmt.Println("vim-go") fmt.Println("vim-go")
parse() parse()
tmpl, err := template.New("page").Parse(page) tmpl := template.New("page")
tmpl = tmpl.Funcs(map[string]any{
"vids_prefix": func() string { return videosUrl },
})
tmpl, err := tmpl.Parse(page)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -83,7 +92,7 @@ func main() {
if _, ok := seen[yturl]; !ok { if _, ok := seen[yturl]; !ok {
seen[yturl] = struct{}{} seen[yturl] = struct{}{}
id := d.Add(db.Item{ id := d.Add(db.Item{
Date: time.Now().String(), Date: time.Now().Format("2006-01-02 15:04"),
URL: yturl, URL: yturl,
Title: "Loading", Title: "Loading",
Approved: false, Approved: false,

View File

@ -28,7 +28,7 @@
<td>{{ .Title }}</td> <td>{{ .Title }}</td>
<td> <td>
{{ if eq .Status "Done" }} {{ if eq .Status "Done" }}
<a href="./vids/{{ .FileName }}">Watch</a> <a href="{{ vids_prefix }}/{{ .FileName }}">Watch</a>
{{ else if eq .Status "InProgress" }} {{ else if eq .Status "InProgress" }}
{{ .Progress }} {{ .Progress }}
{{ else }} {{ else }}