youtube

package
v1.13.9 Latest Latest
Warning

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

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

README

YouTube

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.

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 (
	PlayerAPI = "https://www.youtube.com/youtubei/v1/player"
)
View Source
const VersionAndroid = "15.01"
View Source
const VersionWeb = "1.19700101"

Variables

This section is empty.

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

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 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