Skip to content
Open
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
68 changes: 34 additions & 34 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,47 +171,47 @@

// client info for the innertube API
type ClientInfo struct {
name string
key string
version string
userAgent string
androidVersion int
deviceModel string
Name string
Key string
Version string
UserAgent string
AndroidVersion int
DeviceModel string
}

var (
// WebClient, better to use Android client but go ahead.
WebClient = ClientInfo{
name: "WEB",
version: "2.20220801.00.00",
key: "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8",
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
Name: "WEB",
Version: "2.20220801.00.00",
Key: "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8",
UserAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
}

// AndroidClient, download go brrrrrr.
AndroidClient = ClientInfo{
name: "ANDROID",
version: "20.10.38",
key: "AIzaSyA8eiZmM1FaDVjRy-df2KTyQ_vz_yYM39w",
userAgent: "com.google.android.youtube/20.10.38 (Linux; U; Android 11) gzip",
Name: "ANDROID",
Version: "20.10.38",
Key: "AIzaSyA8eiZmM1FaDVjRy-df2KTyQ_vz_yYM39w",
UserAgent: "com.google.android.youtube/20.10.38 (Linux; U; Android 11) gzip",
// androidVersion removed to avoid PoToken requirement (android_sdkless variant)
}

// IOSClient Client based brrrr.
IOSClient = ClientInfo{
name: "IOS",
version: "19.45.4",
key: "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8",
userAgent: "com.google.ios.youtube/19.45.4 (iPhone16,2; U; CPU iOS 18_1_0 like Mac OS X;)",
deviceModel: "iPhone16,2",
Name: "IOS",
Version: "19.45.4",
Key: "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8",
UserAgent: "com.google.ios.youtube/19.45.4 (iPhone16,2; U; CPU iOS 18_1_0 like Mac OS X;)",
DeviceModel: "iPhone16,2",
}

// EmbeddedClient, not really tested.
EmbeddedClient = ClientInfo{
name: "WEB_EMBEDDED_PLAYER",
version: "1.19700101",
key: "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8", // seems like same key works for both clients
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
Name: "WEB_EMBEDDED_PLAYER",
Version: "1.19700101",
Key: "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8", // seems like same key works for both clients
UserAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
}
)

Expand All @@ -230,7 +230,7 @@
},
}

return c.httpPostBodyBytes(ctx, "https://www.youtube.com/youtubei/v1/player?key="+c.client.key, data)
return c.httpPostBodyBytes(ctx, "https://www.youtube.com/youtubei/v1/player?key="+c.client.Key, data)
}

func (c *Client) transcriptDataByInnertube(ctx context.Context, id string, lang string) ([]byte, error) {
Expand All @@ -239,7 +239,7 @@
Params: transcriptVideoID(id, lang),
}

return c.httpPostBodyBytes(ctx, "https://www.youtube.com/youtubei/v1/get_transcript?key="+c.client.key, data)
return c.httpPostBodyBytes(ctx, "https://www.youtube.com/youtubei/v1/get_transcript?key="+c.client.Key, data)
}

func randString(alphabet string, sz int) string {
Expand All @@ -254,17 +254,17 @@
func randomVisitorData(countryCode string) string {
var pbE2 ProtoBuilder

pbE2.String(2, "")

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 `pbE2.String` 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.23.x)

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

Check failure on line 258 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)

Check failure on line 258 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)

var pbE ProtoBuilder
pbE.String(1, countryCode)

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 `pbE.String` 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.23.x)

Error return value of `pbE.String` is not checked (errcheck)
pbE.Bytes(2, pbE2.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.x)

Error return value of `pbE.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.23.x)

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

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

Check failure on line 265 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)

Check failure on line 265 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)
pb.Varint(5, time.Now().Unix()-int64(rand.Intn(600000)))

Check failure on line 266 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)

Check failure on line 266 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)
pb.Bytes(6, pbE.ToBytes())

Check failure on line 267 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)

Check failure on line 267 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)

return pb.ToURLEncodedBase64()
}
Expand All @@ -275,11 +275,11 @@
HL: "en",
GL: "US",
TimeZone: "UTC",
DeviceModel: clientInfo.deviceModel,
ClientName: clientInfo.name,
ClientVersion: clientInfo.version,
AndroidSDKVersion: clientInfo.androidVersion,
UserAgent: clientInfo.userAgent,
DeviceModel: clientInfo.DeviceModel,
ClientName: clientInfo.Name,
ClientVersion: clientInfo.Version,
AndroidSDKVersion: clientInfo.AndroidVersion,
UserAgent: clientInfo.UserAgent,
VisitorData: randomVisitorData("US"),
},
}
Expand Down Expand Up @@ -340,7 +340,7 @@
}

data := prepareInnertubePlaylistData(id, false, *c.client)
body, err := c.httpPostBodyBytes(ctx, "https://www.youtube.com/youtubei/v1/browse?key="+c.client.key, data)
body, err := c.httpPostBodyBytes(ctx, "https://www.youtube.com/youtubei/v1/browse?key="+c.client.Key, data)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -499,7 +499,7 @@
c.assureClient()

if format.URL != "" {
if c.client.androidVersion > 0 {
if c.client.AndroidVersion > 0 {
return format.URL, nil
}

Expand Down Expand Up @@ -528,7 +528,7 @@
client = http.DefaultClient
}

req.Header.Set("User-Agent", c.client.userAgent)
req.Header.Set("User-Agent", c.client.UserAgent)
req.Header.Set("Origin", "https://youtube.com")
req.Header.Set("Sec-Fetch-Mode", "navigate")

Expand Down Expand Up @@ -606,7 +606,7 @@
}

req.Header.Set("X-Youtube-Client-Name", "3")
req.Header.Set("X-Youtube-Client-Version", c.client.version)
req.Header.Set("X-Youtube-Client-Version", c.client.Version)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")

Expand Down
2 changes: 1 addition & 1 deletion playlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (p *Playlist) parsePlaylistInfo(ctx context.Context, client *Client, body [
for continuation != "" {
data := prepareInnertubePlaylistData(continuation, true, *client.client)

body, err := client.httpPostBodyBytes(ctx, "https://www.youtube.com/youtubei/v1/browse?key="+client.client.key, data)
body, err := client.httpPostBodyBytes(ctx, "https://www.youtube.com/youtubei/v1/browse?key="+client.client.Key, data)
if err != nil {
return err
}
Expand Down
Loading