summaryrefslogtreecommitdiff
path: root/grimtube.go
diff options
context:
space:
mode:
Diffstat (limited to 'grimtube.go')
-rw-r--r--grimtube.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/grimtube.go b/grimtube.go
index 9f8061b..1cfccc0 100644
--- a/grimtube.go
+++ b/grimtube.go
@@ -9,6 +9,8 @@ import (
"log"
"strconv"
"path"
+ "os/exec"
+ "strings"
"git.sr.ht/~ark/ytparser"
)
@@ -46,6 +48,27 @@ func serve(w http.ResponseWriter, templatePath string, data interface{}) {
}
}
+func stream(w http.ResponseWriter, r *http.Request) {
+ values := r.URL.Query()
+ if !values.Has("url") {
+ w.WriteHeader(http.StatusBadRequest)
+ return
+ }
+ out, err := exec.Command("yt-dlp", "--print", "url", "-f", "22,18", values.Get("url")).Output()
+ if err != nil {
+ log.Println(err)
+ w.WriteHeader(http.StatusInternalServerError)
+ return
+ }
+ sout := string(out)
+ data := struct {
+ Url string
+ }{
+ strings.Trim(sout, "\n"),
+ }
+ serve(w, "templates/syncstream.html", data)
+}
+
func index(w http.ResponseWriter, r *http.Request) {
term := ""
page := 0
@@ -180,6 +203,7 @@ func main() {
http.HandleFunc("/", index)
http.HandleFunc("/search", search)
http.HandleFunc("/embed", embed)
+ http.HandleFunc("/stream", loadurls)
log.Printf("Listening on port %d\n", *port)
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), nil))