bug fix
Marco Andronaco andronacomarco@gmail.com
Sat, 13 Jan 2024 13:06:00 +0100
2 files changed,
16 insertions(+),
10 deletions(-)
M
fixyoutube.go
→
fixyoutube.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.go
→
invidious/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