Adds a list of current work to the page

testing
Justin Reichardt 2022-11-09 17:56:37 -06:00
parent 19ec9225f5
commit 716605b3de
1 changed files with 18 additions and 2 deletions

View File

@ -28,6 +28,7 @@ import (
"os/exec" "os/exec"
"path" "path"
"strconv" "strconv"
"strings"
) )
const template = ` const template = `
@ -40,6 +41,7 @@ const template = `
<label>URL: <input name="URL" type="text""></label> <label>URL: <input name="URL" type="text""></label>
<input type="submit" value="Download"> <input type="submit" value="Download">
</form> </form>
<p>currentWork</p>
</body> </body>
</html> </html>
` `
@ -49,6 +51,8 @@ type ops struct {
Res chan string Res chan string
} }
var currentWork map[int]string
var config struct { var config struct {
saveLocation string saveLocation string
} }
@ -66,7 +70,12 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
}() }()
} else { } 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) { func downloadVid(r *http.Request) {
@ -81,15 +90,20 @@ func operationHandler() {
os.MkdirAll(dir, 0755) os.MkdirAll(dir, 0755)
cmd := exec.Command("youtube-dl", o.URL) cmd := exec.Command("youtube-dl", o.URL)
cmd.Dir = dir + "/" cmd.Dir = dir + "/"
log.Println(dir + "/") currentWork[i] = o.URL
cmd.Run() cmd.Run()
log.Print("Finished: " + o.URL)
delete(currentWork, i)
files, err := ioutil.ReadDir(dir + "/") files, err := ioutil.ReadDir(dir + "/")
if err != nil { if err != nil {
log.Print(err) log.Print(err)
} }
for _, file := range files { for _, file := range files {
log.Print("Moving: " + file.Name())
err := os.Rename(dir+"/"+file.Name(), file.Name()) err := os.Rename(dir+"/"+file.Name(), file.Name())
if err != nil { if err != nil {
log.Print(err) log.Print(err)
@ -115,6 +129,8 @@ func main() {
} }
log.Println("Downloading files to: " + config.saveLocation) log.Println("Downloading files to: " + config.saveLocation)
currentWork = make(map[int]string)
os.MkdirAll(path.Join(config.saveLocation, ".viddown"), 0755) os.MkdirAll(path.Join(config.saveLocation, ".viddown"), 0755)
go operationHandler() go operationHandler()