youtube

package
v1.49.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2022 License: OSL-3.0 Imports: 15 Imported by: 4

README

YouTube

Client ANDROID

googleplay -a com.google.android.youtube

https://github.com/89z/googleplay

I was able to get YouTube working with Android API 24, using this method [1]. Doing that, I was able to test non-stock versions of YouTube. It seems anything starting with version 14.01.51 (2019) is doing this HTTP/3 or whatever voodoo. Anything older wont work at all, even without proxy, failing with error 400.

  1. https://android.stackexchange.com/a/245551

Client MWEB

GET / HTTP/1.1
Host: m.youtube.com
User-Agent: iPad

Needed to get publishDate:

aN76CmldknI

Client TVHTML5

GET /tv HTTP/1.1
Host: www.youtube.com
User-Agent: Mozilla/5.0 (ChromiumStylePlatform) Cobalt/Version

Client WEB

GET / HTTP/1.1
Host: www.youtube.com

Client WEB_CREATOR

GET /?approve_browser_access=true HTTP/1.1
Host: studio.youtube.com
Authorization: Bearer ya29.a0ARrdaM-2nXUrxlFNOx3hZAUNICfCwmhHKHenQkebpQFGNoYdE...

Client WEB_EMBEDDED_PLAYER

GET /embed/MIchMEqVwvg HTTP/1.1
Host: www.youtube.com

Client WEB_KIDS

GET / HTTP/1.1
Host: www.youtubekids.com
User-Agent: Firefox/44

Client WEB_REMIX

GET / HTTP/1.1
Host: music.youtube.com
User-Agent: Firefox/44

Device OAuth

How to get X-Goog-Api-Key

Make a request like this:

GET / HTTP/2
Host: www.youtube.com

in the response you should see something like this:

"INNERTUBE_API_KEY":"AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8"

https://cloud.google.com/apis/docs/system-parameters

How to get client_id and client_secret

Set User-Agent to [1]:

Mozilla/5.0 (ChromiumStylePlatform) Cobalt/Version

Then visit:

https://www.youtube.com/tv

Next open your browser menu, and click Web Developer, Network or similar. Then go back to the page, and click "Sign in", then "Sign in with a web browser". On the next page, dont bother with any of the instructions, just go back to Developer Tools, and after about five seconds you should see a JSON request like this:

POST /o/oauth2/token HTTP/1.1
Host: www.youtube.com

{"client_id":"861556708454-d6dlm3lh05idd8npek18k6be8ba3oc68.apps.googleusercontent.com",
"client_secret":"SboVhoG9s0rNafixCSGGKXAT",
"code":"AH-1Ng14qVvEj76OeM_h14Mgklgyhchbyc67MhULhCKPY6K-0DTYJqaKng2ULVFTmTzU...",
"grant_type":"http://oauth.net/grant_type/device/1.0"}

Needed for videos like this:

Cr381pDsSsA
  1. https://github.com/youtube/cobalt/blob/master/src/cobalt/browser/user_agent_string.cc

Image

Is maxres1 always available? No:

Is sd1 always available? No:

If hq1 always available? Yes:

http://i.ytimg.com/vi/hq2KgzKETBw/hq1.jpg

Why does this exist?

January 28 2022.

I use it myself.

https://youtube.com/watch?v=Ts1Tcgj6nbc

Documentation

Index

Constants

View Source
const (
	// UPLOAD DATE
	UploadDateLastHour  = 1
	UploadDateToday     = 2
	UploadDateThisWeek  = 3
	UploadDateThisMonth = 4
	UploadDateThisYear  = 5
	// TYPE
	TypeVideo    = 1
	TypeChannel  = 2
	TypePlaylist = 3
	TypeMovie    = 4
	// DURATION
	DurationUnderFourMinutes    = 1
	DurationOverTwentyMinutes   = 2
	DurationFourToTwentyMinutes = 3
	// SORT BY
	SortByRelevance  = 0
	SortByRating     = 1
	SortByUploadDate = 2
	SortByViewCount  = 3
)

Variables

View Source
var Android = Context{
	Client: Client{Name: "ANDROID", Version: "17.09.33"},
}
View Source
var Embed = Context{
	Client:     Client{Name: "ANDROID", Screen: "EMBED", Version: "17.09.33"},
	ThirdParty: &ThirdParty{EmbedURL: origin},
}

HsUATh_Nc2U

View Source
var Images = []Image{
	{Width: 120, Height: 90, Base: "default.jpg"},
	{Width: 120, Height: 90, Base: "1.jpg"},
	{Width: 120, Height: 90, Base: "2.jpg"},
	{Width: 120, Height: 90, Base: "3.jpg"},
	{Width: 120, Height: 90, Base: "default.webp"},
	{Width: 120, Height: 90, Base: "1.webp"},
	{Width: 120, Height: 90, Base: "2.webp"},
	{Width: 120, Height: 90, Base: "3.webp"},
	{Width: 320, Height: 180, Base: "mq1.jpg", Crop: true},
	{Width: 320, Height: 180, Base: "mq2.jpg", Crop: true},
	{Width: 320, Height: 180, Base: "mq3.jpg", Crop: true},
	{Width: 320, Height: 180, Base: "mqdefault.jpg"},
	{Width: 320, Height: 180, Base: "mq1.webp", Crop: true},
	{Width: 320, Height: 180, Base: "mq2.webp", Crop: true},
	{Width: 320, Height: 180, Base: "mq3.webp", Crop: true},
	{Width: 320, Height: 180, Base: "mqdefault.webp"},
	{Width: 480, Height: 360, Base: "0.jpg"},
	{Width: 480, Height: 360, Base: "hqdefault.jpg"},
	{Width: 480, Height: 360, Base: "hq1.jpg"},
	{Width: 480, Height: 360, Base: "hq2.jpg"},
	{Width: 480, Height: 360, Base: "hq3.jpg"},
	{Width: 480, Height: 360, Base: "0.webp"},
	{Width: 480, Height: 360, Base: "hqdefault.webp"},
	{Width: 480, Height: 360, Base: "hq1.webp"},
	{Width: 480, Height: 360, Base: "hq2.webp"},
	{Width: 480, Height: 360, Base: "hq3.webp"},
	{Width: 640, Height: 480, Base: "sddefault.jpg"},
	{Width: 640, Height: 480, Base: "sd1.jpg"},
	{Width: 640, Height: 480, Base: "sd2.jpg"},
	{Width: 640, Height: 480, Base: "sd3.jpg"},
	{Width: 640, Height: 480, Base: "sddefault.webp"},
	{Width: 640, Height: 480, Base: "sd1.webp"},
	{Width: 640, Height: 480, Base: "sd2.webp"},
	{Width: 640, Height: 480, Base: "sd3.webp"},
	{Width: 1280, Height: 720, Base: "hq720.jpg"},
	{Width: 1280, Height: 720, Base: "maxresdefault.jpg"},
	{Width: 1280, Height: 720, Base: "maxres1.jpg"},
	{Width: 1280, Height: 720, Base: "maxres2.jpg"},
	{Width: 1280, Height: 720, Base: "maxres3.jpg"},
	{Width: 1280, Height: 720, Base: "hq720.webp"},
	{Width: 1280, Height: 720, Base: "maxresdefault.webp"},
	{Width: 1280, Height: 720, Base: "maxres1.webp"},
	{Width: 1280, Height: 720, Base: "maxres2.webp"},
	{Width: 1280, Height: 720, Base: "maxres3.webp"},
}
View Source
var LogLevel format.LogLevel
View Source
var Mweb = Context{
	Client: Client{Name: "MWEB", Version: "2.20211109.01.00"},
}

Functions

Types

type Client added in v1.16.9

type Client struct {
	Name    string `json:"clientName"`
	Screen  string `json:"clientScreen,omitempty"`
	Version string `json:"clientVersion"`
}

type Context added in v1.14.7

type Context struct {
	Client     Client      `json:"client"`
	ThirdParty *ThirdParty `json:"thirdParty,omitempty"`
}

func (Context) Player added in v1.48.8

func (c Context) Player(id string) (*Player, error)

func (Context) PlayerHeader added in v1.48.8

func (c Context) PlayerHeader(head http.Header, id string) (*Player, error)

func (Context) Search added in v1.48.8

func (c Context) Search(query string) (*Search, error)

type Exchange added in v1.20.3

type Exchange struct {
	Access_Token  string
	Error         string
	Refresh_Token string
}

func OpenExchange added in v1.44.5

func OpenExchange(name string) (*Exchange, error)

func (Exchange) Create added in v1.44.5

func (x Exchange) Create(name string) error

func (Exchange) Header added in v1.45.1

func (x Exchange) Header() http.Header

func (*Exchange) Refresh added in v1.20.3

func (x *Exchange) Refresh() error

type Filter added in v1.37.1

type Filter struct {
	protobuf.Message
}

func NewFilter added in v1.40.0

func NewFilter() Filter

func (Filter) CreativeCommons added in v1.37.1

func (f Filter) CreativeCommons(val uint64) Filter

func (Filter) Duration added in v1.37.1

func (f Filter) Duration(val uint64) Filter

func (Filter) FourK added in v1.37.1

func (f Filter) FourK(val uint64) Filter

func (Filter) HD added in v1.37.1

func (f Filter) HD(val uint64) Filter

func (Filter) HDR added in v1.37.1

func (f Filter) HDR(val uint64) Filter

func (Filter) Live added in v1.37.1

func (f Filter) Live(val uint64) Filter

func (Filter) Location added in v1.37.1

func (f Filter) Location(val uint64) Filter

func (Filter) Purchased added in v1.37.1

func (f Filter) Purchased(val uint64) Filter

func (Filter) Subtitles added in v1.37.1

func (f Filter) Subtitles(val uint64) Filter

func (Filter) ThreeD added in v1.37.1

func (f Filter) ThreeD(val uint64) Filter

func (Filter) ThreeSixty added in v1.37.1

func (f Filter) ThreeSixty(val uint64) Filter

func (Filter) Type added in v1.37.1

func (f Filter) Type(val uint64) Filter

func (Filter) UploadDate added in v1.37.1

func (f Filter) UploadDate(val uint64) Filter

func (Filter) VR180 added in v1.37.1

func (f Filter) VR180(val uint64) Filter

type Format

type Format struct {
	AudioQuality  string
	Bitrate       int64
	ContentLength int64 `json:"contentLength,string"`
	Height        int
	Itag          int64
	MimeType      string
	QualityLabel  string
	URL           string
	Width         int
}

func (Format) Format added in v1.48.4

func (f Format) Format() (string, error)

func (Format) Name added in v1.48.5

func (f Format) Name(play *Player) (string, error)

func (Format) Write

func (f Format) Write(dst io.Writer) error

type Height added in v1.49.5

type Height struct {
	StreamingData
	Target int
}

func (Height) Less added in v1.49.5

func (h Height) Less(i, j int) bool

type Image added in v1.15.8

type Image struct {
	Width  int
	Height int
	Base   string
	Crop   bool
}

func (Image) Format added in v1.16.3

func (i Image) Format(id string) string

type Item added in v1.24.9

type Item struct {
	CompactVideoRenderer *struct {
		Title struct {
			Runs []struct {
				Text string
			}
		}
		VideoID string
	}
}

type OAuth added in v1.20.4

type OAuth struct {
	Device_Code      string
	User_Code        string
	Verification_URL string
}

func NewOAuth added in v1.20.4

func NewOAuth() (*OAuth, error)

func (OAuth) Exchange added in v1.20.4

func (o OAuth) Exchange() (*Exchange, error)

func (OAuth) String added in v1.44.5

func (o OAuth) String() string

type Params added in v1.27.5

type Params struct {
	protobuf.Message
}

func NewParams added in v1.40.0

func NewParams() Params

func (Params) Encode added in v1.37.1

func (p Params) Encode() string

func (Params) Filter added in v1.37.1

func (p Params) Filter(val Filter) Params

func (Params) SortBy added in v1.37.1

func (p Params) SortBy(val uint64) Params

type Player added in v1.13.0

type Player struct {
	StreamingData StreamingData
	Microformat   struct {
		PlayerMicroformatRenderer struct {
			PublishDate string // 2013-06-11
		}
	}
	PlayabilityStatus struct {
		Status string // "OK", "LOGIN_REQUIRED"
		Reason string // "", "Sign in to confirm your age"
	}
	VideoDetails struct {
		VideoID          string
		LengthSeconds    int64 `json:"lengthSeconds,string"`
		ViewCount        int64 `json:"viewCount,string"`
		Author           string
		Title            string
		ShortDescription string
	}
}

func (Player) Date added in v1.24.9

func (p Player) Date() (time.Time, error)

func (Player) Details added in v1.49.5

func (p Player) Details() string

func (Player) Status added in v1.49.5

func (p Player) Status() string
type Search struct {
	Contents struct {
		SectionListRenderer struct {
			Contents []struct {
				ItemSectionRenderer *struct {
					Contents []Item
				}
			}
		}
	}
}

func (Search) Items added in v1.24.9

func (s Search) Items() []Item

type StreamingData added in v1.17.9

type StreamingData struct {
	AdaptiveFormats []Format
}

func (StreamingData) Len added in v1.49.5

func (s StreamingData) Len() int

func (StreamingData) Swap added in v1.49.5

func (s StreamingData) Swap(i, j int)

type ThirdParty added in v1.48.8

type ThirdParty struct {
	EmbedURL string `json:"embedUrl"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL