youtube

package
v1.44.4 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2022 License: OSL-3.0 Imports: 13 Imported by: 3

README

YouTube

Clients

ANDROID is needed for this:

MeJVWBSsPAY

EMBED is needed for this:

QWlNyzzwgcc

MWEB is needed to get publishDate:

aN76CmldknI

OAuth is required:

Cr381pDsSsA

Get ANDROID client:

GET /fdfe/details?doc=com.google.android.youtube HTTP/1.1
Host: android.clients.google.com
Authorization: Bearer ya29.a0ARrdaM8lMFRwIzLPFAl9VPONVvM3ByCV_CKqMGzOmff6fnqSL...
X-DFE-Device-ID: 3f48fb5589c...

Get MWEB client:

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

Get TVHTML5 client:

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

Get WEB client:

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

Get WEB_CREATOR client:

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

Get WEB_EMBEDDED_PLAYER client:

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

Get WEB_KIDS client:

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

Get WEB_REMIX client:

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"}
  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

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 = Client{Name: "ANDROID", Version: "16.43.34"}
	Embed   = Client{Name: "ANDROID", Screen: "EMBED", Version: "16.43.34"}
	Mweb    = Client{Name: "MWEB", Version: "2.20211109.01.00"}
)
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 Key = Auth{"X-Goog-Api-Key", "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8"}

Functions

This section is empty.

Types

type Auth added in v1.20.3

type Auth struct {
	Key   string
	Value string
}

type Client added in v1.16.9

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

type Exchange added in v1.20.3

type Exchange struct {
	Access_Token  string
	Error         string
	Refresh_Token string
}

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)

func (*Filter) Duration added in v1.37.1

func (f *Filter) Duration(val uint64)

func (*Filter) FourK added in v1.37.1

func (f *Filter) FourK(val uint64)

func (*Filter) HD added in v1.37.1

func (f *Filter) HD(val uint64)

func (*Filter) HDR added in v1.37.1

func (f *Filter) HDR(val uint64)

func (*Filter) Live added in v1.37.1

func (f *Filter) Live(val uint64)

func (*Filter) Location added in v1.37.1

func (f *Filter) Location(val uint64)

func (*Filter) Purchased added in v1.37.1

func (f *Filter) Purchased(val uint64)

func (*Filter) Subtitles added in v1.37.1

func (f *Filter) Subtitles(val uint64)

func (*Filter) ThreeD added in v1.37.1

func (f *Filter) ThreeD(val uint64)

func (*Filter) ThreeSixty added in v1.37.1

func (f *Filter) ThreeSixty(val uint64)

func (*Filter) Type added in v1.37.1

func (f *Filter) Type(val uint64)

func (*Filter) UploadDate added in v1.37.1

func (f *Filter) UploadDate(val uint64)

func (*Filter) VR180 added in v1.37.1

func (f *Filter) VR180(val uint64)

type Format

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

func (Format) String added in v1.41.9

func (f Format) String() string

func (Format) Write

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

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 {
		LengthText text
		Title      text
		VideoID    string
	}
}

func (Item) VideoID added in v1.24.9

func (i Item) 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)

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)

func (*Params) SortBy added in v1.37.1

func (p *Params) SortBy(val uint64)

type PlayabilityStatus added in v1.40.3

type PlayabilityStatus struct {
	Status string // LOGIN_REQUIRED
	Reason string // Sign in to confirm your age
}

func (PlayabilityStatus) Error added in v1.40.3

func (p PlayabilityStatus) Error() string

type Player added in v1.13.0

type Player struct {
	Microformat struct {
		PlayerMicroformatRenderer struct {
			AvailableCountries []string
			PublishDate        string // 2013-06-11
		}
	}
	PlayabilityStatus PlayabilityStatus
	StreamingData     struct {
		AdaptiveFormats []Format
		// just including this so I can bail if video is Dash Manifest
		DashManifestURL string
		Formats         []Format
	}
	VideoDetails struct {
		Author           string
		ShortDescription string
		Title            string
		VideoID          string
		ViewCount        float64 `json:"viewCount,string"`
	}
}

func NewPlayer added in v1.13.0

func NewPlayer(id string, head Auth, body Client) (*Player, error)

youtube.com/watch?v=hi8ryzFqrAE

func (Player) Date added in v1.24.9

func (p Player) Date() (time.Time, error)
type Search struct {
	Contents struct {
		SectionListRenderer struct {
			Contents []struct {
				ItemSectionRenderer *struct {
					Contents []Item
				}
			}
		}
	}
}

func NewSearch added in v1.11.2

func NewSearch(query string) (*Search, error)

func (Search) Items added in v1.24.9

func (s Search) Items() []Item

Jump to

Keyboard shortcuts

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