youtube

package
v1.13.5 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: 4

README

YouTube

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

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 Android added in v1.13.3

type Android struct {
	StreamingData struct {
		AdaptiveFormats []Format
	}
	VideoDetails struct {
		Author string
		Title  string
	}
}

func NewAndroid added in v1.13.3

func NewAndroid(id string) (Android, error)

func (Android) Author added in v1.13.5

func (a Android) Author() string

func (Android) Formats added in v1.13.3

func (a Android) Formats() []Format

func (Android) NewFormat added in v1.13.3

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

func (Android) Title added in v1.13.5

func (a Android) Title() string

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 PrimaryContents added in v1.13.5

type PrimaryContents struct {
	SectionListRenderer struct {
		Contents []struct {
			ItemSectionRenderer struct {
				Contents []struct {
					VideoRenderer VideoRenderer
				}
			}
		}
	}
}
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
}

type Web added in v1.13.3

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

func NewWeb added in v1.13.3

func NewWeb(id string) (Web, error)

func (Web) Author added in v1.13.3

func (w Web) Author() string

func (Web) Countries added in v1.13.3

func (w Web) Countries() []string

func (Web) Description added in v1.13.3

func (w Web) Description() string

func (Web) PublishDate added in v1.13.3

func (w Web) PublishDate() string

func (Web) Title added in v1.13.3

func (w Web) Title() string

func (Web) ViewCount added in v1.13.3

func (w Web) ViewCount() int

Jump to

Keyboard shortcuts

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