diff --git a/main.go b/main.go index 9c045ca..b1d6890 100644 --- a/main.go +++ b/main.go @@ -42,6 +42,13 @@ var h2client = &http.Client{ // user agent to use var ua = "Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101" +var allowed_hosts = []string{ + "youtube.com", + "googlevideo.com", + "ytimg.com", + "ggpht.com", +} + type requesthandler struct{} func (*requesthandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { @@ -63,6 +70,29 @@ func (*requesthandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } + parts := strings.Split(strings.ToLower(host), ".") + + if len(parts) < 2 { + io.WriteString(w, "Invalid hostname.") + return + } + + domain := parts[len(parts)-2] + "." + parts[len(parts)-1] + + disallowed := true + + for _, value := range allowed_hosts { + if domain == value { + disallowed = false + break + } + } + + if disallowed { + io.WriteString(w, "Non YouTube domains are not supported.") + return + } + path := req.URL.EscapedPath() path = strings.Replace(path, "/ggpht", "", 1)