all repos — fixyoutube-go @ 413c0924f6aaecb20ff7b8e3e4e0a7b7f42dbd7d

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

code cleanup and bug fix
Bi-Rabittoh andronacomarco@gmail.com
Mon, 15 Jan 2024 22:20:16 +0100
commit

413c0924f6aaecb20ff7b8e3e4e0a7b7f42dbd7d

parent

ca53f1b94dd67a7a9153a0ca0af1ba95c240da1f

4 files changed, 12 insertions(+), 22 deletions(-)

jump to
M fixyoutube.gofixyoutube.go

@@ -131,17 +131,21 @@ vars := mux.Vars(r)

videoId := vars["videoId"] vb, s := invidiousClient.ProxyVideoId(videoId) - if !vb.ValidateLength() { + if s != http.StatusOK { logger.Error("proxyHandler() failed. Final code: ", s) http.Error(w, "Something went wrong.", s) return } + if !vb.ValidateLength() { + logger.Error("Buffer length is inconsistent.") + http.Error(w, "Something went wrong.", http.StatusInternalServerError) + return + } h := w.Header() h.Set("Status", "200") h.Set("Content-Type", "video/mp4") h.Set("Content-Length", strconv.FormatInt(vb.Length, 10)) io.Copy(w, vb.Buffer) - return } }
M invidious/api.goinvidious/api.go

@@ -68,13 +68,9 @@

return res, http.StatusOK } -func (c *Client) isNotTimedOut(instance string) bool { - return !c.timeouts.Has(instance) -} - func (c *Client) NewInstance() error { if c.Instance != "" { - err := fmt.Errorf("Generic error") + err := fmt.Errorf("generic error") c.timeouts.Set(c.Instance, &err) }

@@ -109,5 +105,5 @@ return nil

} } - return fmt.Errorf("Cannot find a valid instance.") + return fmt.Errorf("cannot find a valid instance") }
M invidious/invidious.goinvidious/invidious.go

@@ -4,7 +4,6 @@ import (

"bytes" "net/http" "regexp" - "strconv" "time" "github.com/BiRabittoh/fixyoutube-go/volatile"

@@ -53,20 +52,12 @@ }

return } -func parseOrZero(number string) int { - res, err := strconv.Atoi(number) - if err != nil { - return 0 - } - return res -} - func NewVideoBuffer(b *bytes.Buffer, l int64) *VideoBuffer { - duplicate := new(bytes.Buffer) - duplicate.Write(b.Bytes()) + d := new(bytes.Buffer) + d.Write(b.Bytes()) return &VideoBuffer{ - Buffer: duplicate, + Buffer: d, Length: l, } }

@@ -98,7 +89,6 @@

switch httpErr { case http.StatusOK: logger.Info("Retrieved by API.") - break case http.StatusNotFound: logger.Debug("Video does not exist or can't be retrieved.") return nil, err
M invidious/proxy.goinvidious/proxy.go

@@ -38,7 +38,7 @@ }

defer resp.Body.Close() b := new(bytes.Buffer) - l, err := io.Copy(b, resp.Body) + l, _ := io.Copy(b, resp.Body) if l != resp.ContentLength { logger.Debug("Content-Length is inconsistent.") return nil, http.StatusBadRequest