From 467b10906293eb85238d02c16a7fb0b434363987 Mon Sep 17 00:00:00 2001 From: Marco Andronaco Date: Sat, 13 Jan 2024 15:27:30 +0100 Subject: [PATCH] redirect if video has no url --- fixyoutube.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fixyoutube.go b/fixyoutube.go index 65405e4..e67a62e 100644 --- a/fixyoutube.go +++ b/fixyoutube.go @@ -65,11 +65,11 @@ func clearHandler(w http.ResponseWriter, r *http.Request) { } 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 } @@ -87,6 +87,12 @@ func videoHandler(videoId string, invidiousClient *invidious.Client, w http.Resp return } + if video.Url == "" { + logger.Debug("No URL available. Redirecting.") + http.Redirect(w, r, url, http.StatusMovedPermanently) + return + } + buf := &bytes.Buffer{} err = videoTemplate.Execute(buf, video) if err != nil {