Adds a list of current work to the page
parent
19ec9225f5
commit
716605b3de
|
|
@ -28,6 +28,7 @@ import (
|
|||
"os/exec"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const template = `
|
||||
|
|
@ -40,6 +41,7 @@ const template = `
|
|||
<label>URL: <input name="URL" type="text""></label>
|
||||
<input type="submit" value="Download">
|
||||
</form>
|
||||
<p>currentWork</p>
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
|
|
@ -49,6 +51,8 @@ type ops struct {
|
|||
Res chan string
|
||||
}
|
||||
|
||||
var currentWork map[int]string
|
||||
|
||||
var config struct {
|
||||
saveLocation string
|
||||
}
|
||||
|
|
@ -66,7 +70,12 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
|
|||
}()
|
||||
} else {
|
||||
}
|
||||
io.WriteString(w, template)
|
||||
var insert string
|
||||
for _, url := range currentWork {
|
||||
insert += "<br>" + url
|
||||
}
|
||||
temp := strings.Replace(template, "currentWork", insert, 1)
|
||||
io.WriteString(w, temp)
|
||||
}
|
||||
|
||||
func downloadVid(r *http.Request) {
|
||||
|
|
@ -81,15 +90,20 @@ func operationHandler() {
|
|||
os.MkdirAll(dir, 0755)
|
||||
cmd := exec.Command("youtube-dl", o.URL)
|
||||
cmd.Dir = dir + "/"
|
||||
log.Println(dir + "/")
|
||||
currentWork[i] = o.URL
|
||||
cmd.Run()
|
||||
|
||||
log.Print("Finished: " + o.URL)
|
||||
|
||||
delete(currentWork, i)
|
||||
|
||||
files, err := ioutil.ReadDir(dir + "/")
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
log.Print("Moving: " + file.Name())
|
||||
err := os.Rename(dir+"/"+file.Name(), file.Name())
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
|
|
@ -115,6 +129,8 @@ func main() {
|
|||
}
|
||||
log.Println("Downloading files to: " + config.saveLocation)
|
||||
|
||||
currentWork = make(map[int]string)
|
||||
|
||||
os.MkdirAll(path.Join(config.saveLocation, ".viddown"), 0755)
|
||||
|
||||
go operationHandler()
|
||||
|
|
|
|||
Loading…
Reference in New Issue