all repos — fixyoutube-go @ a98db242719bb1b183676dd9eca524cbf3000361

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

bug fix
Marco Andronaco andronacomarco@gmail.com
Sat, 13 Jan 2024 13:06:00 +0100
commit

a98db242719bb1b183676dd9eca524cbf3000361

parent

d9344f281e4e23360836847844572d3c9242741e

2 files changed, 16 insertions(+), 10 deletions(-)

jump to
M fixyoutube.gofixyoutube.go

@@ -133,27 +133,25 @@ }

fmtAmount := len(video.Formats) - var httpStatus = http.StatusNotFound - + s := http.StatusNotFound for i := fmtAmount - 1; i >= 0; i-- { url := video.Formats[i].Url + logger.Debug(url) b, l, httpStatus := invidiousClient.ProxyVideo(url) - switch httpStatus { - case http.StatusOK: + if httpStatus == http.StatusOK { h := w.Header() h.Set("Status", "200") h.Set("Content-Type", "video/mp4") h.Set("Content-Length", strconv.FormatInt(l, 10)) io.Copy(w, b) return - case http.StatusBadRequest: - continue - default: - i = -1 } + s = httpStatus + logger.Debug("Format ", i, "failed with status code ", s) } - logger.Error("proxyHandler() failed. Code: ", httpStatus) - http.Error(w, "Something went wrong.", httpStatus) + + logger.Error("proxyHandler() failed. Final code: ", s) + http.Error(w, "Something went wrong.", s) } }
M invidious/proxy.goinvidious/proxy.go

@@ -19,6 +19,14 @@ logger.Error(err) // request failed

return nil, 0, http.StatusGone } + if resp.StatusCode != http.StatusOK { + return nil, 0, resp.StatusCode + } + + if resp.ContentLength == 0 { + return nil, 0, http.StatusNoContent + } + if resp.ContentLength > maxSizeBytes { logger.Debug("Content-Length exceeds max size.") return nil, 0, http.StatusBadRequest