8000 Add x-goog-visitor-id by corny · Pull Request #360 · kkdai/youtube · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add x-goog-visitor-id #360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,17 +249,17 @@
func randomVisitorData(countryCode string) string {
var pbE2 ProtoBuilder

pbE2.String(2, "")

Check failure on line 252 in client.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go (ubuntu-24.04, 1.23.x)

Error return value of `pbE2.String` is not checked (errcheck)

Check failure on line 252 in client.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go (ubuntu-24.04, 1.x)

Error return value of `pbE2.String` is not checked (errcheck)
pbE2.Varint(4, int64(rand.Intn(255)+1))

Check failure on line 253 in client.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go (ubuntu-24.04, 1.23.x)

Error return value of `pbE2.Varint` is not checked (errcheck)

Check failure on line 253 in client.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go (ubuntu-24.04, 1.x)

Error return value of `pbE2.Varint` is not checked (errcheck)

var pbE ProtoBuilder
pbE.String(1, countryCode)

Check failure on line 256 in client.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go (ubuntu-24.04, 1.23.x)

Error return value of `pbE.String` is not checked (errcheck)

Check failure on line 256 in client.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go (ubuntu-24.04, 1.x)

Error return value of `pbE.Str 8000 ing` is not checked (errcheck)
pbE.Bytes(2, pbE2.ToBytes())

Check failure on line 257 in client.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go (ubuntu-24.04, 1.23.x)

Error return value of `pbE.Bytes` is not checked (errcheck)

Check failure on line 257 in client.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go (ubuntu-24.04, 1.x)

Error return value of `pbE.Bytes` is not checked (errcheck)

var pb ProtoBuilder
pb.String(1, randString(ContentPlaybackNonceAlphabet, 11))

Check failure on line 260 in client.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go (ubuntu-24.04, 1.23.x)

Error return value of `pb.String` is not checked (errcheck)

Check failure on line 260 in client.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go (ubuntu-24.04, 1.x)

Error return value of `pb.String` is not checked (errcheck)
pb.Varint(5, time.Now().Unix()-int64(rand.Intn(600000)))

Check failure on line 261 in client.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go (ubuntu-24.04, 1.23.x)

Error return value of `pb.Varint` is not checked (errcheck)

Check failure on line 261 in client.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go (ubuntu-24.04, 1.x)

Error return value of `pb.Varint` is not checked (errcheck)
pb.Bytes(6, pbE.ToBytes())

Check failure on line 262 in client.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go (ubuntu-24.04, 1.23.x)

Error return value of `pb.Bytes` is not checked (errcheck)

Check failure on line 262 in client.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go (ubuntu-24.04, 1.x)

Error return value of `pb.Bytes` is not checked (errcheck)

return pb.ToURLEncodedBase64()
}
Expand Down Expand Up @@ -605,6 +605,12 @@
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")

if xgoogvisitorid, err := getVisitorId(); err != nil {
return nil, err
} else {
req.Header.Set("x-goog-visitor-id", xgoogvisitorid)
}

resp, err := c.httpDo(req)
if err != nil {
return nil, err
Expand All @@ -618,6 +624,58 @@
return resp, nil
}

var VisitorIdMaxAge = 10 * time.Hour
var VisitorId struct {
Id string
Ctime time.Time
}

func getVisitorId() (string, error) {
if VisitorId.Id != "" && time.Since(VisitorId.Ctime) < VisitorIdMaxAge {
return VisitorId.Id, nil
}

const sep = "\nytcfg.set("

var req http.Request
req.Header = http.Header{}
req.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.4 Safari/605.1.15")
req.URL = &url.URL{}
req.URL.Host = "www.youtube.com"
req.URL.Scheme = "https"
resp, err := http.DefaultClient.Do(&req)
if err != nil {
return "", err
}
defer resp.Body.Close()
data, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}
_, data1, found := strings.Cut(string(data), sep)
if !found {
return "", err
}
var value struct {
InnertubeContext struct {
Client struct {
VisitorData string
}
} `json:"INNERTUBE_CONTEXT"`
}
if err := json.NewDecoder(strings.NewReader(data1)).Decode(&value); err != nil {
return "", err
}

if VisitorId.Id, err = url.PathUnescape(value.InnertubeContext.Client.VisitorData); err != nil {
return "", err
}

VisitorId.Ctime = time.Now()

return VisitorId.Id, nil
}

// httpPostBodyBytes reads the whole HTTP body and returns it
func (c *Client) httpPostBodyBytes(ctx context.Context, url string, body interface{}) ([]byte, error) {
resp, err := c.httpPost(ctx, url, body)
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ toolchain go1.23.3

require (
github.com/bitly/go-simplejson v0.5.1
github.com/dop251/goja v0.0.0-20250125213203-5ef83b82af17
github.com/dop251/goja v0.0.0-20250309171923-bcd7cc6bf64c
github.com/mitchellh/go-homedir v1.1.0
github.com/olekukonko/tablewriter v0.0.5
github.com/spf13/cobra v1.9.1
Expand All @@ -24,7 +24,7 @@ require (
github.com/dlclark/regexp2 v1.11.5 // indirect
github.com/fsnotify/fsnotify v1.8.0 // indirect
github.com/go-sourcemap/sourcemap v2.1.4+incompatible // indirect
github.com/google/pprof v0.0.0-20250208200701-d0013a598941 // indirect
github.com/google/pprof v0.0.0-20250501235452-c0086092b71a // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/magiconair/properties v1.8.9 // indirect
Expand All @@ -42,8 +42,8 @@ require (
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20250218142911-aa4b98e5adaa // indirect
golang.org/x/sys v0.30.0 // indirect
golang.org/x/text v0.22.0 // indirect
golang.org/x/sys v0.32.0 // indirect
golang.org/x/text v0.24.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dlclark/regexp2 v1.11.5 h1:Q/sSnsKerHeCkc/jSTNq1oCm7KiVgUMZRDUoRu0JQZQ=
github.com/dlclark/regexp2 v1.11.5/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/dop251/goja v0.0.0-20250125213203-5ef83b82af17 h1:spJaibPy2sZNwo6Q0HjBVufq7hBUj5jN 8000 FOKRoogCBow=
github.com/dop251/goja v0.0.0-20250125213203-5ef83b82af17/go.mod h1:MxLav0peU43GgvwVgNbLAj1s/bSGboKkhuULvq/7hx4=
github.com/dop251/goja v0.0.0-20250309171923-bcd7cc6bf64c h1:mxWGS0YyquJ/ikZOjSrRjjFIbUqIP9ojyYQ+QZTU3Rg=
github.com/dop251/goja v0.0.0-20250309171923-bcd7cc6bf64c/go.mod h1:MxLav0peU43GgvwVgNbLAj1s/bSGboKkhuULvq/7hx4=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M=
Expand All @@ -23,8 +23,8 @@ github.com/go-sourcemap/sourcemap v2.1.4+incompatible h1:a+iTbH5auLKxaNwQFg0B+TC
github.com/go-sourcemap/sourcemap v2.1.4+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/pprof v0.0.0-20250208200701-d0013a598941 h1:43XjGa6toxLpeksjcxs1jIoIyr+vUfOqY2c6HB4bpoc=
github.com/google/pprof v0.0.0-20250208200701-d0013a598941/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
github.com/google/pprof v0.0.0-20250501235452-c0086092b71a h1:rDA3FfmxwXR+BVKKdz55WwMJ1pD2hJQNW31d+l3mPk4=
github.com/google/pprof v0.0.0-20250501235452-c0086092b71a/go.mod h1:5hDyRhoBCxViHszMt12TnOpEI4VVi+U8Gm9iphldiMA=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
Expand Down Expand Up @@ -83,10 +83,10 @@ golang.org/x/exp v0.0.0-20250218142911-aa4b98e5adaa/go.mod h1:BHOTPb3L19zxehTsLo
golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8=
golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=
golang.org/x/sys v0.0.0-20201218084310-7d0127a74742/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0=
golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
Loading
0