diff --git a/httppaths.go b/httppaths.go index 8dac3fe..b984668 100644 --- a/httppaths.go +++ b/httppaths.go @@ -33,10 +33,24 @@ func videoplayback(w http.ResponseWriter, req *http.Request) { // Prevent the process of already expired playbacks // since they will return 403 from googlevideo servers. if (expire - time.Now().Unix()) <= 0 { - w.WriteHeader(403) + w.WriteHeader(400) + io.WriteString(w, "Expire query string undefined or videoplayback URL has expired.") return } + // https://github.com/iv-org/invidious-companion/blob/306f2d5f12440275e3202a52e8555eb88d9a34be/src/routes/videoPlaybackProxy.ts#L41-L45 + c := q.Get("c") + if c == "" { + w.WriteHeader(400) + io.WriteString(w, "'c' query string undefined.") + return + } + + // https://github.com/iv-org/invidious-companion/blob/306f2d5f12440275e3202a52e8555eb88d9a34be/src/routes/videoPlaybackProxy.ts#L56-L58 + if strings.Contains(c, "WEB") { + q.Add("alr", "yes") + } + host := q.Get("host") q.Del("host") @@ -59,6 +73,8 @@ func videoplayback(w http.ResponseWriter, req *http.Request) { host = "rr" + mvi + "---" + mn[0] + ".googlevideo.com" } + // https://github.com/iv-org/invidious-companion/blob/306f2d5f12440275e3202a52e8555eb88d9a34be/src/routes/videoPlaybackProxy.ts#L56-L58 + parts := strings.Split(strings.ToLower(host), ".") if len(parts) < 2 { @@ -95,11 +111,22 @@ func videoplayback(w http.ResponseWriter, req *http.Request) { body := []byte{0x78, 0} // protobuf body request, err := http.NewRequest("POST", proxyURL.String(), bytes.NewReader(body)) - copyHeaders(req.Header, request.Header, false) - request.Header.Set("User-Agent", ua) if err != nil { log.Panic(err) } + copyHeaders(req.Header, request.Header, false) + + // https://github.com/iv-org/invidious-companion/blob/306f2d5f12440275e3202a52e8555eb88d9a34be/src/routes/videoPlaybackProxy.ts#L74-L83 + switch c { + case "ANDROID": + request.Header.Set("User-Agent", "com.google.android.youtube/1537338816 (Linux; U; Android 13; en_US; ; Build/TQ2A.230505.002; Cronet/113.0.5672.24)") + case "IOS": + request.Header.Set("User-Agent", "com.google.ios.youtube/19.32.8 (iPhone14,5; U; CPU iOS 17_6 like Mac OS X;)") + case "WEB": + request.Header.Set("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36") + default: + request.Header.Set("User-Agent", ua) + } resp, err := client.Do(request) if err != nil {