youtube

package
v1.13.2 Latest Latest
Warning

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

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

README

YouTube

youtubei

This new method downloads 72.2 KB.

How much is the old method?

PS C:\> curl -I https://www.youtube.com/watch?v=UpNXI3_ctAc
content-length: 502,514

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

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.

Free proxy list

https://proxy.webshare.io/register

Documentation

Overview

YouTube

Index

Constants

View Source
const (
	PlayerAPI = "https://www.youtube.com/youtubei/v1/player"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Format

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

func (Format) Write

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

type Player added in v1.13.0

type Player struct {
	StreamingData struct {
		AdaptiveFormats []Format
	}
	Microformat struct {
		PlayerMicroformatRenderer struct {
			AvailableCountries []string
			PublishDate        string
		}
	}
	VideoDetails struct {
		Author           string
		ShortDescription string
		Title            string
		ViewCount        int `json:"viewCount,string"`
	}
}

func NewPlayer added in v1.13.0

func NewPlayer(id string) (Player, error)

func (Player) Author added in v1.13.0

func (p Player) Author() string

func (Player) Countries added in v1.13.0

func (p Player) Countries() []string

func (Player) Description added in v1.13.0

func (p Player) Description() string

func (Player) Formats added in v1.13.0

func (p Player) Formats() []Format

func (Player) NewFormat added in v1.13.0

func (p Player) NewFormat(itag int) (Format, error)

func (Player) PublishDate added in v1.13.0

func (p Player) PublishDate() string

func (Player) Title added in v1.13.0

func (p Player) Title() string

func (Player) ViewCount added in v1.13.0

func (p Player) ViewCount() int
type Search struct {
	Contents struct {
		TwoColumnSearchResultsRenderer struct {
			PrimaryContents primaryContents
		}
	}
}

func NewSearch added in v1.11.2

func NewSearch(query string) (Search, error)

func (Search) VideoRenderers added in v1.11.2

func (s Search) VideoRenderers() []VideoRenderer

type VideoRenderer added in v1.11.2

type VideoRenderer struct {
	VideoID string
}

Jump to

Keyboard shortcuts

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