youtube

package
v1.54.5 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2022 License: OSL-3.0 Imports: 15 Imported by: 3

README

YouTube

Android client

Must use Android API 31 or higher.

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

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

Why does this exist?

I use it myself:

https://www.youtube.com/watch?v=zv9NimPx3Es

April 8 2022

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Android = YouTube_I{
	Context: Context{
		Client: Client{"ANDROID", android_version},
	},
}

1

View Source
var Android_Content = YouTube_I{
	Context: Context{
		Client: Client{"ANDROID", android_version},
	},
	Racy_Check_OK:    true,
	Content_Check_OK: true,
}

4

View Source
var Android_Embed = YouTube_I{
	Context: Context{
		Client: Client{"ANDROID_EMBEDDED_PLAYER", android_version},
	},
}

2

View Source
var Android_Racy = YouTube_I{
	Context: Context{
		Client: Client{"ANDROID", android_version},
	},
	Racy_Check_OK: true,
}

3

View Source
var Duration = map[string]uint64{
	"Under 4 minutes": 1,
	"4 - 20 minutes":  3,
	"Over 20 minutes": 2,
}
View Source
var Features = map[string]protobuf.Number{
	"360°":             15,
	"3D":               7,
	"4K":               14,
	"Creative Commons": 6,
	"HD":               4,
	"HDR":              25,
	"Live":             8,
	"Location":         23,
	"Purchased":        9,
	"Subtitles/CC":     5,
	"VR180":            26,
}
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 Mweb = YouTube_I{
	Context: Context{
		Client: Client{"MWEB", "2.20220322.05.00"},
	},
}
View Source
var SortBy = map[string]uint64{
	"Relevance":   0,
	"Upload date": 2,
	"View count":  3,
	"Rating":      1,
}
View Source
var Type = map[string]uint64{
	"Video":    1,
	"Channel":  2,
	"Playlist": 3,
	"Movie":    4,
}
View Source
var UploadDate = map[string]uint64{
	"Last hour":  1,
	"Today":      2,
	"This week":  3,
	"This month": 4,
	"This year":  5,
}

Functions

Types

type Client added in v1.16.9

type Client struct {
	ClientName    string `json:"clientName"`
	ClientVersion string `json:"clientVersion"`
}

type Context added in v1.14.7

type Context struct {
	Client Client `json:"client"`
}

type Exchange added in v1.20.3

type Exchange struct {
	Access_Token  string
	Error         string
	Refresh_Token string
}

func Open_Exchange added in v1.54.5

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

func (Exchange) Create added in v1.44.5

func (x Exchange) Create(name string) error

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) Duration added in v1.37.1

func (f Filter) Duration(val uint64)

func (Filter) Features added in v1.49.8

func (f Filter) Features(num protobuf.Number)

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)

type Format

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

func (Format) Format added in v1.48.4

func (f Format) Format(s fmt.State, verb rune)

func (Format) WriteTo added in v1.51.7

func (f Format) WriteTo(w io.Writer) (int64, error)

type Formats added in v1.17.9

type Formats []Format

func (Formats) Audio added in v1.52.5

func (f Formats) Audio(quality string) (*Format, bool)

func (Formats) MediaType added in v1.50.5

func (f Formats) MediaType() error

func (Formats) Video added in v1.52.5

func (f Formats) Video(height int) (*Format, 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 New_OAuth added in v1.54.5

func New_OAuth() (*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) 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 Player added in v1.13.0

type Player struct {
	VideoDetails struct {
		VideoId          string
		LengthSeconds    int64 `json:"lengthSeconds,string"`
		ViewCount        int64 `json:"viewCount,string"`
		Author           string
		Title            string
		ShortDescription string
	}
	Microformat struct {
		PlayerMicroformatRenderer struct {
			PublishDate string
		}
	}
	StreamingData struct {
		AdaptiveFormats Formats
	}
	PlayabilityStatus Status
}

func (Player) Base added in v1.49.6

func (p Player) Base() string

func (Player) Date added in v1.24.9

func (p Player) Date() string

func (Player) Duration added in v1.52.5

func (p Player) Duration() time.Duration

func (Player) Format added in v1.50.1

func (p Player) Format(f fmt.State, verb rune)

func (Player) Time added in v1.52.5

func (p Player) Time() (time.Time, error)
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 Status added in v1.52.5

type Status struct {
	Status string
	Reason string
}

func (Status) String added in v1.52.5

func (s Status) String() string

type YouTube_I added in v1.54.5

type YouTube_I struct {
	Content_Check_OK bool    `json:"contentCheckOk,omitempty"`
	Context          Context `json:"context"`
	Query            string  `json:"query,omitempty"`
	Racy_Check_OK    bool    `json:"racyCheckOk,omitempty"`
	Video_ID         string  `json:"videoId,omitempty"`
	Params           []byte  `json:"params,omitempty"`
}

func (YouTube_I) Exchange added in v1.54.5

func (y YouTube_I) Exchange(id string, ex *Exchange) (*Player, error)

func (YouTube_I) Player added in v1.54.5

func (y YouTube_I) Player(id string) (*Player, error)

func (YouTube_I) Search added in v1.54.5

func (y YouTube_I) Search(query string) (*Search, error)

Jump to

Keyboard shortcuts

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