youtube

package
v1.37.1 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 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

Need Embed:

client QWlNyzzwgcc
Android fail
Embed pass
Mweb fail

Need Mweb:

client aN76CmldknI publishDate
Android fail
Embed fail
Mweb pass

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"}
  1. https://github.com/youtube/cobalt/blob/master/src/cobalt/browser/user_agent_string.cc

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.05"}
	Embed   = Client{Name: "ANDROID", Screen: "EMBED", Version: "16.05"}
	Mweb    = Client{Name: "MWEB", Version: "2.19700101"}
)
View Source
var Key = Auth{"X-Goog-Api-Key", "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8"}
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},
}
View Source
var Verbose = mech.Verbose

Functions

func Valid added in v1.33.2

func Valid(id string) bool

youtube.com/watch?v=hi8ryzFqrAE

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 {
	UploadDate      int  `json:"1,omitempty"`
	Type            int  `json:"2,omitempty"`
	Duration        int  `json:"3,omitempty"`
	HD              bool `json:"4,omitempty"`
	Subtitles       bool `json:"5,omitempty"`
	CreativeCommons bool `json:"6,omitempty"`
	ThreeD          bool `json:"7,omitempty"`
	Live            bool `json:"8,omitempty"`
	Purchased       bool `json:"9,omitempty"`
	FourK           bool `json:"14,omitempty"`
	ThreeSixty      bool `json:"15,omitempty"`
	Location        bool `json:"23,omitempty"`
	HDR             bool `json:"25,omitempty"`
	VR180           bool `json:"26,omitempty"`
}

type Format

type Format struct {
	Bitrate       bitrate
	ContentLength contentLength `json:"contentLength,string"`
	Height        int
	Itag          int
	MimeType      string
	URL           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) 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 {
	SortBy int     `json:"1,omitempty"`
	Filter *Filter `json:"2,omitempty"`
}

func (Params) Encode added in v1.37.1

func (p Params) Encode() (string, 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 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        float64 `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
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