redirect if video has no url
Marco Andronaco andronacomarco@gmail.com
Sat, 13 Jan 2024 15:27:30 +0100
1 files changed,
7 insertions(+),
1 deletions(-)
jump to
M
fixyoutube.go
→
fixyoutube.go
@@ -65,11 +65,11 @@ http.Error(w, "Done.", http.StatusOK)
} func videoHandler(videoId string, invidiousClient *invidious.Client, w http.ResponseWriter, r *http.Request) { + url := "https://www.youtube.com/watch?v=" + videoId userAgent := r.UserAgent() res := userAgentRegex.MatchString(userAgent) if !res { logger.Debug("Regex did not match. Redirecting. UA:", userAgent) - url := "https://www.youtube.com/watch?v=" + videoId http.Redirect(w, r, url, http.StatusMovedPermanently) return }@@ -84,6 +84,12 @@ video, err := invidiousClient.GetVideo(videoId, true)
if err != nil { logger.Info("Wrong video ID: ", videoId) http.Error(w, "Wrong video ID.", http.StatusNotFound) + return + } + + if video.Url == "" { + logger.Debug("No URL available. Redirecting.") + http.Redirect(w, r, url, http.StatusMovedPermanently) return }