youtube

package
v1.17.1 Latest Latest
Warning

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

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

README

YouTube

Client

Can we use one client for decrypted media, publishDate and search? No. Can we use two clients? Yes. Which two are best?

120597 MWEB {decrypt:false publishDate:true search:true size:56111} ANDROID
{decrypt:true publishDate:false search:true size:64486}

135304 ANDROID {decrypt:true publishDate:false search:true size:64486} WEB
{decrypt:false publishDate:true search:true size:70818}

295700 ANDROID {decrypt:true publishDate:false search:true size:64486}
WEB_REMIX {decrypt:false publishDate:true search:true size:231214}

Can we use MWEB for publishDate? Yes. Can we use MWEB for search? Yes. Can we use ANDROID for decrypted media? Yes.

itag 251

If we look at video 3gdfNdilGFE:

67201 WEB_CREATOR {decrypt:true publishDate:false search:true size:56980} WEB_REMIX {decrypt:false publishDate:true search:true size:10221}
80760 WEB_EMBEDDED_PLAYER {decrypt:true publishDate:false search:false size:70539} WEB_REMIX {decrypt:false publishDate:true search:true size:10221}
99252 ANDROID {decrypt:true publishDate:false search:true size:89031}
151916 MWEB {decrypt:true publishDate:true search:true size:62885}
564097 WEB {decrypt:true publishDate:true search:true size:561332}
690545 TVHTML5 {decrypt:true publishDate:false search:true size:680324} WEB_REMIX {decrypt:false publishDate:true search:true size:10221}

If we look at video XeojXq6ySs4:

110560 MWEB {decrypt:false publishDate:true search:true size:57396} ANDROID_MUSIC {decrypt:true publishDate:false search:true size:53164}
120580 MWEB {decrypt:false publishDate:true search:true size:57396} ANDROID {decrypt:true publishDate:false search:true size:63184}

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.

MWEB

https://github.com/thanhphongdo/youtube-noads/blob/master/server/apis/youtube.ts

Image

Given a video ID, return all the possible image links. Leave it up to end user to make sure links are valid for a given video. Also add a test to ensure all options are up to date.

https://github.com/yuliskov/MediaServiceCore/blob/master/youtubeapi/src/test/
resources/youtube-requests.http

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

Overview

YouTube

Index

Constants

View Source
const (
	JPG  = 1
	WebP = 0
)
View Source
const (
	WidthAutoHeightBlack = 0
	WidthAuto            = 10
	WidthBlack           = 20
	HeightCrop           = 30
)

Variables

View Source
var ClientAndroid = Client{"ANDROID", "15.01"}
View Source
var ClientMWeb = Client{"MWEB", "2.19700101"}
View Source
var Images = []Image{
	{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 Android added in v1.13.3

type Android struct {
	StreamingData struct {
		AdaptiveFormats []Format
	}
	VideoDetails `json:"videoDetails"`
}

func NewAndroid added in v1.13.3

func NewAndroid(id string) (*Android, error)

func (Android) NewFormat added in v1.13.3

func (a Android) NewFormat(itag int) (*Format, error)

type Client added in v1.16.9

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

type CompactVideoRenderer added in v1.16.9

type CompactVideoRenderer struct {
	VideoID string
}

type Context added in v1.14.7

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

type Format

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

func (Format) Write

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

type Image added in v1.15.8

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

func (Image) Address added in v1.15.9

func (i Image) Address(id string) string

type MWeb added in v1.16.9

type MWeb struct {
	Microformat  `json:"microformat"`
	VideoDetails `json:"videoDetails"`
}

func NewMWeb added in v1.16.9

func NewMWeb(id string) (*MWeb, error)

type Microformat added in v1.13.6

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

type PlayerMicroformatRenderer added in v1.13.6

type PlayerMicroformatRenderer struct {
	AvailableCountries []string
	PublishDate        string
}

type Result added in v1.14.7

type Result struct {
	Contents struct {
		SectionListRenderer struct {
			Contents []struct {
				ItemSectionRenderer struct {
					Contents []struct {
						CompactVideoRenderer `json:"compactVideoRenderer"`
					}
				}
			}
		}
	}
}

func (Result) Videos added in v1.16.9

func (r Result) Videos() []CompactVideoRenderer
type Search struct {
	Context `json:"context"`
	Query   string `json:"query"`
}

func NewSearch added in v1.11.2

func NewSearch(query string) Search

func (Search) Post added in v1.14.7

func (s Search) Post() (*Result, error)

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