Skip to content

Commit

Permalink
redirect if video has no url
Browse files Browse the repository at this point in the history
  • Loading branch information
birabittoh committed Jan 13, 2024
1 parent 566d291 commit 467b109
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion fixyoutube.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down

0 comments on commit 467b109

Please sign in to comment.