Skip to content

Commit

Permalink
feat(client): add iOS client and fix video download issue
Browse files Browse the repository at this point in the history
- Introduced a new iOS client configuration (`IOSClient`) with device
model, user agent, and updated version key.
- Updated `innertubeClient` and `clientInfo` to include `deviceModel`
for better compatibility.
- Changed the default client from `AndroidClient` to `IOSClient`.
- Commented out `playerParams` in the video data request, addressing
video download issues.
- Minor code cleanup to improve readability.
  • Loading branch information
ruizlenato authored and corny committed Dec 20, 2024
1 parent 49f6504 commit 9f98965
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import (
"errors"
"fmt"
"io"
"log/slog"
"math/rand"
"net/http"
"net/url"
"strconv"
"sync/atomic"

"log/slog"
)

const (
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -168,6 +166,7 @@ type clientInfo struct {
version string
userAgent string
androidVersion int
deviceModel string
}

var (
Expand All @@ -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",
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 9f98965

Please sign in to comment.