youtube

package
v1.55.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2022 License: OSL-3.0 Imports: 14 Imported by: 4

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 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 HTTP_Client = http.Default_Client
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 Sort_By = 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 Upload_Date = map[string]uint64{
	"Last hour":  1,
	"Today":      2,
	"This week":  3,
	"This month": 4,
	"This year":  5,
}

Functions

func Video_ID added in v1.54.5

func Video_ID(raw_addr string) (string, error)

Types

type Filter added in v1.37.1

type Filter struct {
	protobuf.Message
}

func New_Filter added in v1.54.6

func New_Filter() 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) Upload_Date added in v1.54.6

func (f Filter) Upload_Date(val uint64)

type Format

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

func (Format) Encode added in v1.54.6

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

func (Format) MarshalText added in v1.54.7

func (f Format) MarshalText() ([]byte, 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) Video added in v1.52.5

func (f Formats) Video(height int) (*Format, bool)
type Header struct {
	Access_Token  string
	Error         string
	Refresh_Token string
}

func Open_Header added in v1.54.8

func Open_Header(name string) (*Header, error)

func (Header) Create added in v1.54.8

func (h Header) Create(name string) error

func (*Header) Refresh added in v1.54.8

func (h *Header) Refresh() 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 {
		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) Header added in v1.54.8

func (o OAuth) Header() (*Header, 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 New_Params added in v1.54.6

func New_Params() Params

func (Params) Filter added in v1.37.1

func (p Params) Filter(val Filter)

func (Params) Sort_By added in v1.54.6

func (p Params) Sort_By(val uint64)

type Player added in v1.13.0

type Player struct {
	VideoDetails struct {
		Author           string
		LengthSeconds    int64 `json:"lengthSeconds,string"`
		ShortDescription string
		Title            string
		VideoId          string
		ViewCount        int64 `json:"viewCount,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) Duration added in v1.52.5

func (p Player) Duration() time.Duration

func (Player) MarshalText added in v1.54.7

func (p Player) MarshalText() ([]byte, error)

func (Player) PublishDate added in v1.13.0

func (p Player) PublishDate() string

func (Player) Time added in v1.52.5

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

type Request added in v1.14.1

type Request struct {
	Header *Header
	// contains filtered or unexported fields
}

func Android added in v1.13.3

func Android() Request

func Android_Content added in v1.54.5

func Android_Content() Request

func Android_Embed added in v1.54.5

func Android_Embed() Request

func Android_Racy added in v1.54.5

func Android_Racy() Request

func Mobile_Web added in v1.55.0

func Mobile_Web() Request

func (Request) Player added in v1.54.8

func (r Request) Player(id string) (*Player, error)

func (Request) Search added in v1.55.0

func (r Request) Search(query string) (*Search, 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

Jump to

Keyboard shortcuts

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