all repos — fixyoutube-go @ 467b10906293eb85238d02c16a7fb0b434363987

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

redirect if video has no url
Marco Andronaco andronacomarco@gmail.com
Sat, 13 Jan 2024 15:27:30 +0100
commit

467b10906293eb85238d02c16a7fb0b434363987

parent

566d29167b4dcd64442c4b91805551c4e4e23dfa

1 files changed, 7 insertions(+), 1 deletions(-)

jump to
M fixyoutube.gofixyoutube.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 }