Add support for Invidious's maxres.jpg.
This commit is contained in:
parent
3680e840d1
commit
3ba265d0ea
1 changed files with 20 additions and 0 deletions
20
main.go
20
main.go
|
@ -47,6 +47,10 @@ func genericHTTPProxy(w http.ResponseWriter, req *http.Request) {
|
|||
|
||||
proxyURL.RawQuery = q.Encode()
|
||||
|
||||
if strings.HasSuffix(proxyURL.Path, "maxres.jpg") {
|
||||
proxyURL.Path = getBestThumbnail(proxyURL.Path)
|
||||
}
|
||||
|
||||
request, err := http.NewRequest("GET", proxyURL.String(), nil)
|
||||
|
||||
copyHeaders(req.Header, request.Header)
|
||||
|
@ -104,6 +108,22 @@ func getHost(path string) (host string) {
|
|||
return host
|
||||
}
|
||||
|
||||
func getBestThumbnail(path string) (newpath string) {
|
||||
|
||||
formats := [4]string{"maxresdefault.jpg", "sddefault.jpg", "hqdefault.jpg", "mqdefault.jpg"}
|
||||
|
||||
for _, format := range formats {
|
||||
newpath = strings.Replace(path, "maxres.jpg", format, 1)
|
||||
url := "https://i.ytimg.com" + newpath
|
||||
resp, _ := h2client.Head(url)
|
||||
if resp.StatusCode == 200 {
|
||||
return newpath
|
||||
}
|
||||
}
|
||||
|
||||
return strings.Replace(path, "maxres.jpg", "mqdefault.jpg", 1)
|
||||
}
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/videoplayback", genericHTTPProxy)
|
||||
http.HandleFunc("/vi/", genericHTTPProxy)
|
||||
|
|
Loading…
Reference in a new issue