youtube

package
v1.25.9 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2021 License: OSL-3.0 Imports: 12 Imported by: 3

README

YouTube

Is maxres1 always available? No:

Is sd1 always available? No:

If hq1 always available? Yes:

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

Clients

Need Android:

client MeJVWBSsPAY
Android pass
Embed fail
Mweb fail
TV fail

Need Embed:

client QWlNyzzwgcc
Android fail
Embed pass
Mweb fail
TV fail

Need Mweb:

client aN76CmldknI publishDate
Android fail
Embed fail
Mweb pass
TV fail

Cover art

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

References:

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

other repos

Documentation

Overview

YouTube

Index

Constants

This section is empty.

Variables

View Source
var (
	WebP = PictureFormat{0, "vi_webp", "webp"}
	JPG  = PictureFormat{1, "vi", "jpg"}
)
View Source
var (
	Key     = Auth{"X-Goog-Api-Key", "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8"}
	Verbose = false
)
View Source
var (
	Android = Client{Name: "ANDROID", Version: "16.05"}
	Embed   = Client{Name: "ANDROID", Screen: "EMBED", Version: "16.05"}
	Mweb    = Client{Name: "MWEB", Version: "2.19700101"}
)
View Source
var Pictures = PictureSlice{
	{120, 90, 68, "default", JPG},
	{120, 90, 90, "1", JPG},
	{120, 90, 90, "2", JPG},
	{120, 90, 90, "3", JPG},
	{120, 90, 68, "default", WebP},
	{120, 90, 90, "1", WebP},
	{120, 90, 90, "2", WebP},
	{120, 90, 90, "3", WebP},
	{320, 180, 180, "mqdefault", JPG},
	{320, 180, 320, "mq1", JPG},
	{320, 180, 320, "mq2", JPG},
	{320, 180, 320, "mq3", JPG},
	{320, 180, 180, "mqdefault", WebP},
	{320, 180, 320, "mq1", WebP},
	{320, 180, 320, "mq2", WebP},
	{320, 180, 320, "mq3", WebP},
	{480, 360, 270, "0", JPG},
	{480, 360, 270, "hqdefault", JPG},
	{480, 360, 360, "hq1", JPG},
	{480, 360, 360, "hq2", JPG},
	{480, 360, 360, "hq3", JPG},
	{480, 360, 270, "0", WebP},
	{480, 360, 270, "hqdefault", WebP},
	{480, 360, 360, "hq1", WebP},
	{480, 360, 360, "hq2", WebP},
	{480, 360, 360, "hq3", WebP},
	{640, 480, 360, "sddefault", JPG},
	{640, 480, 480, "sd1", JPG},
	{640, 480, 480, "sd2", JPG},
	{640, 480, 480, "sd3", JPG},
	{640, 480, 360, "sddefault", WebP},
	{640, 480, 480, "sd1", WebP},
	{640, 480, 480, "sd2", WebP},
	{640, 480, 480, "sd3", WebP},
	{1280, 720, 720, "hq720", JPG},
	{1280, 720, 720, "maxres1", JPG},
	{1280, 720, 720, "maxres2", JPG},
	{1280, 720, 720, "maxres3", JPG},
	{1280, 720, 720, "maxresdefault", JPG},
	{1280, 720, 720, "hq720", WebP},
	{1280, 720, 720, "maxres1", WebP},
	{1280, 720, 720, "maxres2", WebP},
	{1280, 720, 720, "maxres3", WebP},
	{1280, 720, 720, "maxresdefault", WebP},
}

Functions

func ValidID added in v1.24.9

func ValidID(id string) error

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
	Refresh_Token string
}

func (*Exchange) Refresh added in v1.20.3

func (x *Exchange) Refresh() error

type Format

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

func (Format) Ext added in v1.17.8

func (f Format) Ext() string

func (Format) Write

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

type FormatSlice added in v1.17.8

type FormatSlice []Format

func (FormatSlice) Filter added in v1.17.8

func (f FormatSlice) Filter(keep func(Format) bool) FormatSlice

func (FormatSlice) Sort added in v1.17.8

func (f FormatSlice) Sort(less ...func(a, b Format) bool)

type Item added in v1.24.9

type Item struct {
	CompactVideoRenderer *struct {
		LengthText Text
		Title      Text
		VideoID    string
	}
}

func (Item) Duration added in v1.24.9

func (i Item) Duration() (time.Duration, error)

func (Item) Title added in v1.24.9

func (i Item) Title() 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 Picture added in v1.21.9

type Picture struct {
	Width     int
	Height    int
	SubHeight int
	Base      string
	Format    PictureFormat
}

func (Picture) Address added in v1.21.9

func (p Picture) Address(id string) string

type PictureFormat added in v1.21.9

type PictureFormat struct {
	Size int
	Dir  string
	Ext  string
}

type PictureSlice added in v1.21.9

type PictureSlice []Picture

func (PictureSlice) Filter added in v1.21.9

func (p PictureSlice) Filter(keep func(Picture) bool) PictureSlice

func (PictureSlice) Sort added in v1.21.9

func (p PictureSlice) Sort(less ...func(a, b Picture) bool)

type Player added in v1.13.0

type Player struct {
	Microformat struct {
		PlayerMicroformatRenderer struct {
			AvailableCountries []string
			PublishDate        string
		}
	}
	PlayabilityStatus struct {
		Reason string
		Status string
	}
	StreamingData struct {
		AdaptiveFormats FormatSlice
		// just including this so I can bail if video is Dash Manifest
		DashManifestURL string
	}
	VideoDetails struct {
		Author           string
		ShortDescription string
		Title            string
		ViewCount        int `json:"viewCount,string"`
	}
}

func NewPlayer added in v1.13.0

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

func (Player) Author added in v1.13.0

func (p Player) Author() string

func (Player) Countries added in v1.13.0

func (p Player) Countries() []string

func (Player) Date added in v1.24.9

func (p Player) Date() string

func (Player) Description added in v1.13.0

func (p Player) Description() string

func (Player) Title added in v1.13.0

func (p Player) Title() string

func (Player) Views added in v1.24.9

func (p Player) Views() int
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

type Text added in v1.24.9

type Text struct {
	Runs []struct {
		Text string
	}
}

Jump to

Keyboard shortcuts

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