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()
|
proxyURL.RawQuery = q.Encode()
|
||||||
|
|
||||||
|
if strings.HasSuffix(proxyURL.Path, "maxres.jpg") {
|
||||||
|
proxyURL.Path = getBestThumbnail(proxyURL.Path)
|
||||||
|
}
|
||||||
|
|
||||||
request, err := http.NewRequest("GET", proxyURL.String(), nil)
|
request, err := http.NewRequest("GET", proxyURL.String(), nil)
|
||||||
|
|
||||||
copyHeaders(req.Header, request.Header)
|
copyHeaders(req.Header, request.Header)
|
||||||
|
@ -104,6 +108,22 @@ func getHost(path string) (host string) {
|
||||||
return host
|
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() {
|
func main() {
|
||||||
http.HandleFunc("/videoplayback", genericHTTPProxy)
|
http.HandleFunc("/videoplayback", genericHTTPProxy)
|
||||||
http.HandleFunc("/vi/", genericHTTPProxy)
|
http.HandleFunc("/vi/", genericHTTPProxy)
|
||||||
|
|
Loading…
Add table
Reference in a new issue