diff --git a/client.go b/client.go index 0bc73eb..587bbb1 100644 --- a/client.go +++ b/client.go @@ -7,13 +7,12 @@ import ( "errors" "fmt" "io" + "log/slog" "math/rand" "net/http" "net/url" "strconv" "sync/atomic" - - "log/slog" ) const ( @@ -24,12 +23,10 @@ const ( playerParams = "CgIQBg==" ) -var ( - ErrNoFormat = errors.New("no video format provided") -) +var ErrNoFormat = errors.New("no video format provided") // DefaultClient type to use. No reason to change but you could if you wanted to. -var DefaultClient = AndroidClient +var DefaultClient = IOSClient // Client offers methods to download video metadata and video streams. type Client struct { @@ -159,6 +156,7 @@ type innertubeClient struct { UserAgent string `json:"userAgent,omitempty"` TimeZone string `json:"timeZone"` UTCOffset int `json:"utcOffsetMinutes"` + DeviceModel string `json:"deviceModel,omitempty"` } // client info for the innertube API @@ -168,6 +166,7 @@ type clientInfo struct { version string userAgent string androidVersion int + deviceModel string } var ( @@ -188,6 +187,15 @@ var ( androidVersion: 30, } + // 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", + } + // EmbeddedClient, not really tested. EmbeddedClient = clientInfo{ name: "WEB_EMBEDDED_PLAYER", @@ -203,7 +211,7 @@ func (c *Client) videoDataByInnertube(ctx context.Context, id string) ([]byte, e Context: prepareInnertubeContext(*c.client), ContentCheckOK: true, RacyCheckOk: true, - Params: playerParams, + // Params: playerParams, PlaybackContext: &playbackContext{ ContentPlaybackContext: contentPlaybackContext{ // SignatureTimestamp: sts, @@ -230,6 +238,7 @@ func prepareInnertubeContext(clientInfo clientInfo) inntertubeContext { HL: "en", GL: "US", TimeZone: "UTC", + DeviceModel: clientInfo.deviceModel, ClientName: clientInfo.name, ClientVersion: clientInfo.version, AndroidSDKVersion: clientInfo.androidVersion, @@ -427,7 +436,6 @@ func (c *Client) downloadChunked(ctx context.Context, req *http.Request, w *io.P return case data := <-chunks[i].data: _, err := io.Copy(w, bytes.NewBuffer(data)) - if err != nil { abort(err) }