summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--grimtube.go24
-rw-r--r--templates/search.html4
-rw-r--r--templates/syncstream.html6
3 files changed, 32 insertions, 2 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))
diff --git a/templates/search.html b/templates/search.html
index 6a9ce28..70c3490 100644
--- a/templates/search.html
+++ b/templates/search.html
@@ -26,10 +26,10 @@
{{range .Items}}
<tr>
<td>
- <a href="/embed?id={{.Id}}&url={{.Url}}"><img width=240 src="{{.ThumbUrl}}"></a>
+ <a href="/stream?url={{.Url}}"><img width=240 src="{{.ThumbUrl}}"></a>
</td>
<td>
- <a href="/embed?id={{.Id}}&url={{.Url}}">{{.Title}}</a>
+ <a href="/stream?url={{.Url}}">{{.Title}}</a>
<br/>
<a href="{{.ChannelUrl}}">{{.ChannelTitle}}</a> | <a href="{{.AtomUrl}}">Atom feed</a>
<br/>
diff --git a/templates/syncstream.html b/templates/syncstream.html
new file mode 100644
index 0000000..6a8ec1d
--- /dev/null
+++ b/templates/syncstream.html
@@ -0,0 +1,6 @@
+{{define "title"}}Search{{end}}
+{{define "content"}}
+ <video id="video" controls>
+ <source src="{{.Url}}">
+ </video>
+{{end}}