all repos — fixyoutube-go @ 48d10f3f94a07a0491c6dbd2bab6b28316162e66

A better way to embed YouTube videos everywhere (inspired by FixTweet).

make proxy recursive
Marco Andronaco andronacomarco@gmail.com
Mon, 01 Jan 2024 22:32:24 +0100
commit

48d10f3f94a07a0491c6dbd2bab6b28316162e66

parent

41c1328a62c74e053854ea764338190a57735988

1 files changed, 13 insertions(+), 4 deletions(-)

jump to
M invidious/invidious.goinvidious/invidious.go

@@ -163,8 +163,9 @@ http.Error(w, "Bad Request", http.StatusBadRequest)

return err } - idx := formatIndex % len(video.Formats) - url := video.Formats[len(video.Formats)-1-idx].Url + fmtAmount := len(video.Formats) + idx := formatIndex % fmtAmount + url := video.Formats[fmtAmount-1-idx].Url req, err := http.NewRequest(http.MethodGet, url, nil) if err != nil { log.Fatal(err)

@@ -188,8 +189,16 @@

w.Header().Set("content-type", "video/mp4") w.Header().Set("Status", "200") - i, err := io.Copy(w, resp.Body) - fmt.Println(i, err) + _, err = io.Copy(w, resp.Body) + if err == nil { // done + return nil + } + + newIndex := formatIndex + 1 + if newIndex < fmtAmount { + return c.ProxyVideo(w, videoId, newIndex) + } + return err }