youtube

package
v1.19.1 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2021 License: OSL-3.0 Imports: 7 Imported by: 3

README

YouTube

Client

Best choice for publishDate and search is player, MWEB:

date 3 search true size 387527 {MWEB 2.19700101}
date 3 search true size 574903 {WEB_REMIX 0.1}
date 3 search true size 974833 {WEB 2.20210223.09.00}

Best choice for decrypted media is player, ANDROID:

decrypt 2 [XeojXq6ySs4 3gdfNdilGFE] size 171899 {ANDROID 16.07.34}

Best choice for age gate is player, WEB_EMBEDDED_PLAYER:

decrypt 2 [HtVdAasjOgU 3gdfNdilGFE] size 199781 {WEB_EMBEDDED_PLAYER}

publishDate

An alternative to publishDate is:

"text": "Published on Nov 5, 2020"

which you can get doing a next request with IOS_KIDS. Uncompressed size is 115 KB. For publishDate, doing a player request with MWEB, you get uncompressed size of 57 KB.

youtubei

Since ANDROID is smaller, we want to pull as much from it as possible. Here is what we need to check:

StreamingData struct {
   AdaptiveFormats []struct {
      Bitrate         int64  // pass
      ContentLength   int64  // pass
      Height          int    // pass
      Itag            int    // pass
      MimeType        string // pass
      URL             string // pass
   }
}
VideoDetails struct {
   Author           string // pass
   ShortDescription string // pass
   Title            string // pass
   ViewCount        int    // pass
}
Microformat struct {
   PlayerMicroformatRenderer struct {
      AvailableCountries []string // fail
      PublishDate        string   // fail
   }
}

watch

desktop:

curl -o index.html https://www.youtube.com/watch?v=UpNXI3_ctAc

Next:

<script nonce="GWQS4dROIhbOWa4QpveqWw">var ytInitialPlayerResponse = {"respons...
...ta":false,"viewCount":"11059","category":"Music","publishDate":"2020-10-02"...
...1"}},"adSlotLoggingData":{"serializedSlotAdServingDataEntry":""}}}]};</script>

Next:

<script nonce="GWQS4dROIhbOWa4QpveqWw">var ytInitialPlayerResponse = {"respons...
...u0026sp=sig\u0026url=https://r4---sn-q4flrner.googlevideo.com/videoplayback...
...1"}},"adSlotLoggingData":{"serializedSlotAdServingDataEntry":""}}}]};</script>

mobile good:

Never Gonna Reach Me
curl -o index.html -A iPad https://m.youtube.com/watch?v=UpNXI3_ctAc

mobile bad:

Goon Gumpas
curl -o index.html -A iPad https://m.youtube.com/watch?v=NMYIVsdGfoo

Free proxy list

https://proxy.webshare.io/register

Documentation

Index

Constants

View Source
const (
	WidthAutoHeightBlack = 0
	WidthAuto            = 1
	WidthBlack           = 2
	HeightCrop           = 3
)
View Source
const (
	JPG  = 1
	WebP = 0
)

Variables

View Source
var (
	Android  = Client{"ANDROID", "15.01"}
	Mweb     = Client{"MWEB", "2.19700101"}
	WebEmbed = Client{"WEB_EMBEDDED_PLAYER", "1.19700101"}
)
View Source
var AdaptiveImages = Images{
	{90, WidthAutoHeightBlack, JPG, "default"},
	{90, WidthAutoHeightBlack, WebP, "default"},
	{90, WidthBlack, JPG, "1"},
	{90, WidthBlack, JPG, "2"},
	{90, WidthBlack, JPG, "3"},
	{90, WidthBlack, WebP, "1"},
	{90, WidthBlack, WebP, "2"},
	{90, WidthBlack, WebP, "3"},
	{180, HeightCrop, JPG, "mq1"},
	{180, HeightCrop, JPG, "mq2"},
	{180, HeightCrop, JPG, "mq3"},
	{180, HeightCrop, WebP, "mq1"},
	{180, HeightCrop, WebP, "mq2"},
	{180, HeightCrop, WebP, "mq3"},
	{180, WidthAuto, JPG, "mqdefault"},
	{180, WidthAuto, WebP, "mqdefault"},
	{360, WidthAutoHeightBlack, JPG, "0"},
	{360, WidthAutoHeightBlack, JPG, "hqdefault"},
	{360, WidthAutoHeightBlack, WebP, "0"},
	{360, WidthAutoHeightBlack, WebP, "hqdefault"},
	{360, WidthBlack, JPG, "hq1"},
	{360, WidthBlack, JPG, "hq2"},
	{360, WidthBlack, JPG, "hq3"},
	{360, WidthBlack, WebP, "hq1"},
	{360, WidthBlack, WebP, "hq2"},
	{360, WidthBlack, WebP, "hq3"},
	{480, WidthAutoHeightBlack, JPG, "sddefault"},
	{480, WidthAutoHeightBlack, WebP, "sddefault"},
	{480, WidthBlack, JPG, "sd1"},
	{480, WidthBlack, JPG, "sd2"},
	{480, WidthBlack, JPG, "sd3"},
	{480, WidthBlack, WebP, "sd1"},
	{480, WidthBlack, WebP, "sd2"},
	{480, WidthBlack, WebP, "sd3"},
	{720, WidthAuto, JPG, "hq720"},
	{720, WidthAuto, JPG, "maxresdefault"},
	{720, WidthAuto, WebP, "hq720"},
	{720, WidthAuto, WebP, "maxresdefault"},
	{720, WidthBlack, JPG, "maxres1"},
	{720, WidthBlack, JPG, "maxres2"},
	{720, WidthBlack, JPG, "maxres3"},
	{720, WidthBlack, WebP, "maxres1"},
	{720, WidthBlack, WebP, "maxres2"},
	{720, WidthBlack, WebP, "maxres3"},
}

Functions

This section is empty.

Types

type Client added in v1.16.9

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

func (Client) Player added in v1.18.8

func (c Client) Player(id string) (*Player, error)

type CompactVideoRenderer added in v1.16.9

type CompactVideoRenderer struct {
	VideoID string
}

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 Formats added in v1.17.9

type Formats []Format

func (Formats) Filter added in v1.17.9

func (s Formats) Filter(keep func(Format) bool) Formats

func (Formats) Sort added in v1.17.9

func (s Formats) Sort(less ...func(a, b Format) bool)

type Image added in v1.15.8

type Image struct {
	Height int
	Frame  int
	Format int
	Base   string
}

func (Image) Address added in v1.15.9

func (i Image) Address(id string) string

type Images added in v1.15.8

type Images []Image

func (Images) Filter added in v1.17.9

func (s Images) Filter(keep func(Image) bool) Images

func (Images) Sort added in v1.17.9

func (s Images) Sort(less ...func(a, b Image) bool)

type Microformat added in v1.13.6

type Microformat struct {
	PlayerMicroformatRenderer `json:"playerMicroformatRenderer"`
}

type Player added in v1.13.0

type Player struct {
	Microformat       `json:"microformat"`
	PlayabilityStatus struct {
		Reason string
	}
	StreamingData `json:"streamingData"`
	VideoDetails  `json:"videoDetails"`
}

type PlayerMicroformatRenderer added in v1.13.6

type PlayerMicroformatRenderer struct {
	AvailableCountries []string
	PublishDate        string
}
type Search struct {
	Contents struct {
		SectionListRenderer struct {
			Contents []struct {
				ItemSectionRenderer struct {
					Contents []struct {
						CompactVideoRenderer CompactVideoRenderer
					}
				}
			}
		}
	}
}

func NewSearch added in v1.11.2

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

func (Search) Videos added in v1.18.2

func (r Search) Videos() []CompactVideoRenderer

type StreamingData added in v1.17.9

type StreamingData struct {
	AdaptiveFormats Formats
}

type VideoDetails added in v1.13.6

type VideoDetails struct {
	Author           string
	ShortDescription string
	Title            string
	ViewCount        int `json:"viewCount,string"`
}

Jump to

Keyboard shortcuts

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