youtube

package
v1.16.6 Latest Latest
Warning

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

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

README

YouTube

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://stackoverflow.com/questions/2068344

So, we are looking for this:

/watch?v=XFkzRNyygfk

First result:

<script nonce="TCh7gubawSzSBgq1Zg3rSA">var ytInitialData = {"responseContext"...
...ead creep cover","radiohead fake plastic trees","radiohead kid a"]};</script>

Everything after var ytInitialData = and before ; is valid JSON. The search results are here:

contents	
   twoColumnSearchResultsRenderer	
      primaryContents	
         sectionListRenderer	
            contents	
               0	
                  itemSectionRenderer	
                     contents

careful, first result might be an advertisement.

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
)
View Source
const VersionAndroid = "15.01"
View Source
const VersionWeb = "1.19700101"

Variables

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 Context added in v1.14.7

type Context struct {
	Client struct {
		ClientName    string `json:"clientName"`
		ClientVersion string `json:"clientVersion"`
	} `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) Abs added in v1.16.6

func (i Image) Abs(id string) string

func (Image) Rel added in v1.16.6

func (i Image) Rel(id string) string

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 {
		TwoColumnSearchResultsRenderer `json:"twoColumnSearchResultsRenderer"`
	}
}

func (Result) VideoRenderers added in v1.14.7

func (r Result) VideoRenderers() []VideoRenderer
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 TwoColumnSearchResultsRenderer added in v1.13.7

type TwoColumnSearchResultsRenderer struct {
	PrimaryContents struct {
		SectionListRenderer struct {
			Contents []struct {
				ItemSectionRenderer struct {
					Contents []struct {
						VideoRenderer `json:"videoRenderer"`
					}
				}
			}
		}
	}
}

type VideoDetails added in v1.13.6

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

type VideoRenderer added in v1.11.2

type VideoRenderer struct {
	VideoID string
}

type Web added in v1.13.3

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

func NewWeb added in v1.13.3

func NewWeb(id string) (*Web, error)

Jump to

Keyboard shortcuts

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