youtube

package
v1.4.5 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: OSL-3.0 Imports: 13 Imported by: 0

README

YouTube

Android Studio

https://play.google.com/store/apps/details?id=com.google.android.youtube

Android API result
31 fail
32 pass

Then install system certificate.

adb shell am start -a android.intent.action.VIEW `
-d https://www.youtube.com/watch?v=k5dX9sjXYVk

Device OAuth

How to get client_id and client_secret

Set User-Agent to [1]:

Mozilla/5.0 (ChromiumStylePlatform) Cobalt/Version

Open MITM Proxy or your browser tools, then visit:

https://www.youtube.com/tv

and click "Sign in". On the next page, dont bother with any of the instructions, just go back to the captured requests, and after about five seconds you should see a JSON request like this:

POST /o/oauth2/token HTTP/1.1
Host: www.youtube.com

{
  "client_id": "861556708454-d6dlm3lh05idd8npek18k6be8ba3oc68.apps.googleusercontent.com",
  "client_secret": "SboVhoG9s0rNafixCSGGKXAT",
  "code": "AH-1Ng14qVvEj76OeM_h14Mgklgyhchbyc67MhULhCKPY6K-0DTYJqaKng2ULVFTmTzU...",
  "grant_type": "http://oauth.net/grant_type/device/1.0"
}
  1. https://github.com/youtube/cobalt/blob/master/src/cobalt/browser/user_agent_string.cc

Image

Is maxres1 always available? No:

Is sd1 always available? No:

If hq1 always available? Yes:

http://i.ytimg.com/vi/hq2KgzKETBw/hq1.jpg

name

episode:

aria-label="In The Heat Of The Night S2 E3 • The Family Secret 47 minutes"

https://youtube.com/watch?v=2ZcDwdXEVyI

film:

aria-label="Gattaca by Drama • 1997 1 hour, 46 minutes" title="Gattaca">

https://youtube.com/watch?v=R9lZ8i8El4I

video:

aria-label="Sleepygirl 11 by Yagya (IS) - Topic 9,746 views 5 years ago 6 minutes, 15 seconds"

https://youtube.com/watch?v=7KLCti7tOXE

Documentation

Index

Constants

View Source
const ModeLine = `` /* 307-byte string literal not displayed */

Variables

View Source
var Images = []Image{
	{Width: 120, Height: 90, Name: "default.jpg"},
	{Width: 120, Height: 90, Name: "1.jpg"},
	{Width: 120, Height: 90, Name: "2.jpg"},
	{Width: 120, Height: 90, Name: "3.jpg"},
	{Width: 120, Height: 90, Name: "default.webp"},
	{Width: 120, Height: 90, Name: "1.webp"},
	{Width: 120, Height: 90, Name: "2.webp"},
	{Width: 120, Height: 90, Name: "3.webp"},
	{Width: 320, Height: 180, Name: "mq1.jpg"},
	{Width: 320, Height: 180, Name: "mq2.jpg"},
	{Width: 320, Height: 180, Name: "mq3.jpg"},
	{Width: 320, Height: 180, Name: "mqdefault.jpg"},
	{Width: 320, Height: 180, Name: "mq1.webp"},
	{Width: 320, Height: 180, Name: "mq2.webp"},
	{Width: 320, Height: 180, Name: "mq3.webp"},
	{Width: 320, Height: 180, Name: "mqdefault.webp"},
	{Width: 480, Height: 360, Name: "0.jpg"},
	{Width: 480, Height: 360, Name: "hqdefault.jpg"},
	{Width: 480, Height: 360, Name: "hq1.jpg"},
	{Width: 480, Height: 360, Name: "hq2.jpg"},
	{Width: 480, Height: 360, Name: "hq3.jpg"},
	{Width: 480, Height: 360, Name: "0.webp"},
	{Width: 480, Height: 360, Name: "hqdefault.webp"},
	{Width: 480, Height: 360, Name: "hq1.webp"},
	{Width: 480, Height: 360, Name: "hq2.webp"},
	{Width: 480, Height: 360, Name: "hq3.webp"},
	{Width: 640, Height: 480, Name: "sddefault.jpg"},
	{Width: 640, Height: 480, Name: "sd1.jpg"},
	{Width: 640, Height: 480, Name: "sd2.jpg"},
	{Width: 640, Height: 480, Name: "sd3.jpg"},
	{Width: 640, Height: 480, Name: "sddefault.webp"},
	{Width: 640, Height: 480, Name: "sd1.webp"},
	{Width: 640, Height: 480, Name: "sd2.webp"},
	{Width: 640, Height: 480, Name: "sd3.webp"},
	{Width: 1280, Height: 720, Name: "hq720.jpg"},
	{Width: 1280, Height: 720, Name: "maxresdefault.jpg"},
	{Width: 1280, Height: 720, Name: "maxres1.jpg"},
	{Width: 1280, Height: 720, Name: "maxres2.jpg"},
	{Width: 1280, Height: 720, Name: "maxres3.jpg"},
	{Width: 1280, Height: 720, Name: "hq720.webp"},
	{Width: 1280, Height: 720, Name: "maxresdefault.webp"},
	{Width: 1280, Height: 720, Name: "maxres1.webp"},
	{Width: 1280, Height: 720, Name: "maxres2.webp"},
	{Width: 1280, Height: 720, Name: "maxres3.webp"},
}

Functions

This section is empty.

Types

type DeviceCode

type DeviceCode struct {
	Device_Code      string
	User_Code        string
	Verification_URL string
}

func (*DeviceCode) Post

func (d *DeviceCode) Post() error

func (DeviceCode) String

func (d DeviceCode) String() string

func (DeviceCode) Token

func (d DeviceCode) Token() (*Token, error)

type Format

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

func (Format) Ext

func (f Format) Ext() (string, error)

func (Format) Ranges

func (f Format) Ranges() []string

func (Format) Rate

func (f Format) Rate() encoding.Rate

func (Format) Size

func (f Format) Size() encoding.Size

type Image

type Image struct {
	Height  int
	Name    string
	VideoId string
	Width   int
}

func (Image) String

func (i Image) String() string

type MetadataRowContainer

type MetadataRowContainer struct {
	MetadataRowContainerRenderer struct {
		Rows []struct {
			MetadataRowRenderer struct {
				Title    Run  // Show
				Contents Runs // In The Heat Of The Night
			}
		}
	}
}

type Player

type Player struct {
	Microformat struct {
		PlayerMicroformatRenderer struct {
			PublishDate string
		}
	}
	PlayabilityStatus struct {
		Status string
		Reason string
	}
	StreamingData struct {
		AdaptiveFormats []Format
	}
	VideoDetails struct {
		Author           string
		LengthSeconds    int64 `json:",string"`
		ShortDescription string
		Title            string
		VideoId          string
		ViewCount        int64 `json:",string"`
	}
}

func (Player) Author

func (p Player) Author() string

func (*Player) Post

func (p *Player) Post(r Request, t *Token) error

func (Player) Time

func (p Player) Time() (time.Time, error)

func (Player) Title

func (p Player) Title() string

type Request

type Request struct {
	ContentCheckOk bool `json:"contentCheckOk,omitempty"`
	Context        struct {
		Client struct {
			AndroidSdkVersion int    `json:"androidSdkVersion"`
			ClientName        string `json:"clientName"`
			ClientVersion     string `json:"clientVersion"`
			// need this to get the correct:
			// This video requires payment to watch
			// instead of the invalid:
			// This video can only be played on newer versions of Android or other
			// supported devices.
			OsVersion string `json:"osVersion"`
		} `json:"client"`
	} `json:"context"`
	RacyCheckOk bool   `json:"racyCheckOk,omitempty"`
	VideoId     string `json:"videoId"`
}

func (*Request) Android

func (r *Request) Android()

func (*Request) AndroidCheck

func (r *Request) AndroidCheck()

func (*Request) AndroidEmbed

func (r *Request) AndroidEmbed()

func (*Request) Set

func (r *Request) Set(s string) error

func (Request) String

func (r Request) String() string

func (*Request) Web

func (r *Request) Web()

type Run

type Run struct {
	Runs []struct {
		Text string
	}
	SimpleText string
}

func (Run) String

func (r Run) String() string

type Runs

type Runs []Run

func (Runs) String

func (r Runs) String() string

type Token

type Token struct {
	Raw   []byte
	Token struct {
		Access_Token  string
		Refresh_Token string
	}
}

func (*Token) Refresh

func (t *Token) Refresh() error

func (*Token) Unmarshal

func (t *Token) Unmarshal() error

type WatchNext

type WatchNext []struct {
	VideoPrimaryInfoRenderer *struct {
		Title Run // The Family Secret
	}
	VideoSecondaryInfoRenderer *struct {
		MetadataRowContainer MetadataRowContainer
		Owner                struct {
			VideoOwnerRenderer struct {
				Title Run
			}
		}
	}
}

func (WatchNext) Episode

func (w WatchNext) Episode() (string, bool)

func (WatchNext) Owner

func (w WatchNext) Owner() (string, bool)

func (*WatchNext) Post

func (w *WatchNext) Post(r Request) error

/youtubei/v1/player is missing the name of the series. use with WEB client.

func (WatchNext) Season

func (w WatchNext) Season() (string, bool)

func (WatchNext) Show

func (w WatchNext) Show() (string, bool)

func (WatchNext) Title

func (w WatchNext) Title() (string, bool)

func (WatchNext) Year

func (w WatchNext) Year() (string, bool)

Jump to

Keyboard shortcuts

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