Added several flags to configure the program
parent
df57d7a57e
commit
f20308f7ce
|
|
@ -13,5 +13,9 @@ A Makefile is in progress but currently does not add the version.
|
||||||
|
|
||||||
# Run
|
# Run
|
||||||
|
|
||||||
The default port is 8080. Env VIDDOWNLOC is where videos are saved to.
|
The default port is 8080.
|
||||||
|
|
||||||
|
For help:
|
||||||
|
|
||||||
|
viddown -h
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,4 @@ RUN apt-get clean
|
||||||
|
|
||||||
COPY viddown /usr/bin/viddown
|
COPY viddown /usr/bin/viddown
|
||||||
|
|
||||||
ENV VIDDOWNLOC /srv/
|
CMD ["/usr/bin/viddown", "-o", "/srv"]
|
||||||
|
|
||||||
CMD ["/usr/bin/viddown"]
|
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"flag"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
|
@ -80,6 +81,10 @@ var currentWork map[int]string
|
||||||
var config struct {
|
var config struct {
|
||||||
// Where files should be saved
|
// Where files should be saved
|
||||||
saveLocation string
|
saveLocation string
|
||||||
|
// Where to find youtube-dl program, must be full name
|
||||||
|
youtubedll string
|
||||||
|
// The port the server listens on
|
||||||
|
port int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Global channel to send operation requests to
|
// Global channel to send operation requests to
|
||||||
|
|
@ -134,7 +139,7 @@ func operationHandler() {
|
||||||
os.MkdirAll(dir, 0755)
|
os.MkdirAll(dir, 0755)
|
||||||
|
|
||||||
// Build the download command
|
// Build the download command
|
||||||
cmd := exec.Command("youtube-dl", o.URL)
|
cmd := exec.Command(config.youtubedll, o.URL)
|
||||||
cmd.Dir = dir + "/"
|
cmd.Dir = dir + "/"
|
||||||
currentWork[i] = o.URL // Adds the URL to list of current work
|
currentWork[i] = o.URL // Adds the URL to list of current work
|
||||||
output, err := cmd.CombinedOutput()
|
output, err := cmd.CombinedOutput()
|
||||||
|
|
@ -171,15 +176,18 @@ func operationHandler() {
|
||||||
log.Fatal("Exited operationsHandler")
|
log.Fatal("Exited operationsHandler")
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
// handleConfigs configures the program at start, handling any flags or env variables
|
||||||
// Set the location to save videos
|
func handleConfigs() {
|
||||||
if os.Getenv("VIDDOWNLOC") == "" {
|
flag.StringVar(&config.saveLocation, "o", "./", "The output location for videos")
|
||||||
config.saveLocation = "./"
|
flag.StringVar(&config.youtubedll, "y", "youtube-dl", "The full location of youtube-dl")
|
||||||
} else {
|
flag.IntVar(&config.port, "p", 8080, "The port the server listens on")
|
||||||
config.saveLocation = os.Getenv("VIDDOWNLOC")
|
flag.Parse()
|
||||||
}
|
|
||||||
log.Println("Downloading files to: " + config.saveLocation)
|
log.Println("Downloading files to: " + config.saveLocation)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
handleConfigs()
|
||||||
// initialize currentWork with a blank map
|
// initialize currentWork with a blank map
|
||||||
currentWork = make(map[int]string)
|
currentWork = make(map[int]string)
|
||||||
|
|
||||||
|
|
@ -192,6 +200,6 @@ func main() {
|
||||||
// Start the http server
|
// Start the http server
|
||||||
handler := http.HandlerFunc(handleRequest)
|
handler := http.HandlerFunc(handleRequest)
|
||||||
http.Handle("/", handler)
|
http.Handle("/", handler)
|
||||||
log.Printf("Starting server on 8080")
|
log.Printf("Starting server on " + strconv.Itoa(config.port))
|
||||||
http.ListenAndServe(":8080", nil)
|
http.ListenAndServe(":"+strconv.Itoa(config.port), nil)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue