Documentation
¶
Overview ¶
Package youtube implement youtube download package in go.
Index ¶
- Variables
- func SanitizeFilename(fileName string) string
- func SetLogOutput(w io.Writer)
- type Itag
- type PlayerResponseData
- type Stream
- type StreamInfo
- type Youtube
- func (y Youtube) Close(r io.ReadCloser, op string)
- func (y *Youtube) DecodeURL(url string) error
- func (y *Youtube) GetStreamInfo() *StreamInfo
- func (y *Youtube) StartDownload(outputDir, outputFile, quality string, itagNo int) error
- func (y *Youtube) StartDownloadWithHighQuality(outputDir string, outputFile string, quality string) error
- func (y *Youtube) Write(p []byte) (n int, err error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrEmptyStreamList = errors.New("empty Stream list") ErrItagNotFound = errors.New("invalid itag value, please specify correct value") ErrCipherNotFound = errors.New("cipher not found") ErrInvalidCharactersInVideoId = errors.New("invalid characters in video id") ErrVideoIdMinLength = errors.New("the video id must be at least 10 characters long") ErrReadOnClosedResBody = errors.New("http: read on closed response body") )
Functions ¶
func SanitizeFilename ¶
Types ¶
type PlayerResponseData ¶
type PlayerResponseData struct { PlayabilityStatus struct { Status string `json:"status"` Reason string `json:"reason"` PlayableInEmbed bool `json:"playableInEmbed"` ContextParams string `json:"contextParams"` } `json:"playabilityStatus"` StreamingData struct { ExpiresInSeconds string `json:"expiresInSeconds"` Formats []struct { Stream Bitrate int `json:"bitrate"` Width int `json:"width"` Height int `json:"height"` LastModified string `json:"lastModified"` ContentLength string `json:"contentLength,omitempty"` QualityLabel string `json:"qualityLabel"` ProjectionType string `json:"projectionType"` AverageBitrate int `json:"averageBitrate,omitempty"` AudioQuality string `json:"audioQuality"` ApproxDurationMs string `json:"approxDurationMs"` AudioSampleRate string `json:"audioSampleRate"` AudioChannels int `json:"audioChannels"` } `json:"formats"` AdaptiveFormats []struct { Stream Bitrate int `json:"bitrate"` Width int `json:"width,omitempty"` Height int `json:"height,omitempty"` InitRange struct { Start string `json:"start"` End string `json:"end"` } `json:"initRange"` IndexRange struct { Start string `json:"start"` End string `json:"end"` } `json:"indexRange"` LastModified string `json:"lastModified"` ContentLength string `json:"contentLength"` Fps int `json:"fps,omitempty"` QualityLabel string `json:"qualityLabel,omitempty"` ProjectionType string `json:"projectionType"` AverageBitrate int `json:"averageBitrate"` ApproxDurationMs string `json:"approxDurationMs"` ColorInfo struct { Primaries string `json:"primaries"` TransferCharacteristics string `json:"transferCharacteristics"` MatrixCoefficients string `json:"matrixCoefficients"` } `json:"colorInfo,omitempty"` HighReplication bool `json:"highReplication,omitempty"` AudioQuality string `json:"audioQuality,omitempty"` AudioSampleRate string `json:"audioSampleRate,omitempty"` AudioChannels int `json:"audioChannels,omitempty"` } `json:"adaptiveFormats"` } `json:"streamingData"` PlaybackTracking struct { VideostatsPlaybackURL struct { BaseURL string `json:"baseUrl"` } `json:"videostatsPlaybackUrl"` VideostatsDelayplayURL struct { BaseURL string `json:"baseUrl"` } `json:"videostatsDelayplayUrl"` VideostatsWatchtimeURL struct { BaseURL string `json:"baseUrl"` } `json:"videostatsWatchtimeUrl"` PtrackingURL struct { BaseURL string `json:"baseUrl"` } `json:"ptrackingUrl"` QoeURL struct { BaseURL string `json:"baseUrl"` } `json:"qoeUrl"` SetAwesomeURL struct { BaseURL string `json:"baseUrl"` ElapsedMediaTimeSeconds int `json:"elapsedMediaTimeSeconds"` } `json:"setAwesomeUrl"` AtrURL struct { BaseURL string `json:"baseUrl"` ElapsedMediaTimeSeconds int `json:"elapsedMediaTimeSeconds"` } `json:"atrUrl"` } `json:"playbackTracking"` Captions struct { PlayerCaptionsRenderer struct { BaseURL string `json:"baseUrl"` Visibility string `json:"visibility"` } `json:"playerCaptionsRenderer"` PlayerCaptionsTracklistRenderer struct { CaptionTracks []struct { BaseURL string `json:"baseUrl"` Name struct { SimpleText string `json:"simpleText"` } `json:"name"` VssID string `json:"vssId"` LanguageCode string `json:"languageCode"` Kind string `json:"kind"` IsTranslatable bool `json:"isTranslatable"` } `json:"captionTracks"` AudioTracks []struct { CaptionTrackIndices []int `json:"captionTrackIndices"` } `json:"audioTracks"` TranslationLanguages []struct { LanguageCode string `json:"languageCode"` LanguageName struct { SimpleText string `json:"simpleText"` } `json:"languageName"` } `json:"translationLanguages"` DefaultAudioTrackIndex int `json:"defaultAudioTrackIndex"` } `json:"playerCaptionsTracklistRenderer"` } `json:"captions"` VideoDetails struct { VideoID string `json:"videoId"` Title string `json:"title"` LengthSeconds string `json:"lengthSeconds"` ChannelID string `json:"channelId"` IsOwnerViewing bool `json:"isOwnerViewing"` ShortDescription string `json:"shortDescription"` IsCrawlable bool `json:"isCrawlable"` Thumbnail struct { Thumbnails []struct { URL string `json:"url"` Width int `json:"width"` Height int `json:"height"` } `json:"thumbnails"` } `json:"thumbnail"` AverageRating float64 `json:"averageRating"` AllowRatings bool `json:"allowRatings"` ViewCount string `json:"viewCount"` Author string `json:"author"` IsPrivate bool `json:"isPrivate"` IsUnpluggedCorpus bool `json:"isUnpluggedCorpus"` IsLiveContent bool `json:"isLiveContent"` } `json:"videoDetails"` PlayerConfig struct { AudioConfig struct { LoudnessDb float64 `json:"loudnessDb"` PerceptualLoudnessDb float64 `json:"perceptualLoudnessDb"` EnablePerFormatLoudness bool `json:"enablePerFormatLoudness"` } `json:"audioConfig"` StreamSelectionConfig struct { MaxBitrate string `json:"maxBitrate"` } `json:"streamSelectionConfig"` MediaCommonConfig struct { DynamicReadaheadConfig struct { MaxReadAheadMediaTimeMs int `json:"maxReadAheadMediaTimeMs"` MinReadAheadMediaTimeMs int `json:"minReadAheadMediaTimeMs"` ReadAheadGrowthRateMs int `json:"readAheadGrowthRateMs"` } `json:"dynamicReadaheadConfig"` } `json:"mediaCommonConfig"` } `json:"playerConfig"` Storyboards struct { PlayerStoryboardSpecRenderer struct { Spec string `json:"spec"` } `json:"playerStoryboardSpecRenderer"` } `json:"storyboards"` Microformat struct { PlayerMicroformatRenderer struct { Thumbnail struct { Thumbnails []struct { URL string `json:"url"` Width int `json:"width"` Height int `json:"height"` } `json:"thumbnails"` } `json:"thumbnail"` Embed struct { IframeURL string `json:"iframeUrl"` FlashURL string `json:"flashUrl"` Width int `json:"width"` Height int `json:"height"` FlashSecureURL string `json:"flashSecureUrl"` } `json:"embed"` Title struct { SimpleText string `json:"simpleText"` } `json:"title"` Description struct { SimpleText string `json:"simpleText"` } `json:"description"` LengthSeconds string `json:"lengthSeconds"` OwnerProfileURL string `json:"ownerProfileUrl"` ExternalChannelID string `json:"externalChannelId"` AvailableCountries []string `json:"availableCountries"` IsUnlisted bool `json:"isUnlisted"` HasYpcMetadata bool `json:"hasYpcMetadata"` ViewCount string `json:"viewCount"` Category string `json:"category"` PublishDate string `json:"publishDate"` OwnerChannelName string `json:"ownerChannelName"` UploadDate string `json:"uploadDate"` } `json:"playerMicroformatRenderer"` } `json:"microformat"` TrackingParams string `json:"trackingParams"` Attestation struct { PlayerAttestationRenderer struct { Challenge string `json:"challenge"` BotguardData struct { Program string `json:"program"` InterpreterURL string `json:"interpreterUrl"` } `json:"botguardData"` } `json:"playerAttestationRenderer"` } `json:"attestation"` Messages []struct { MealbarPromoRenderer struct { MessageTexts []struct { Runs []struct { Text string `json:"text"` } `json:"runs"` } `json:"messageTexts"` ActionButton struct { ButtonRenderer struct { Style string `json:"style"` Size string `json:"size"` Text struct { Runs []struct { Text string `json:"text"` } `json:"runs"` } `json:"text"` ServiceEndpoint struct { ClickTrackingParams string `json:"clickTrackingParams"` CommandMetadata struct { WebCommandMetadata struct { URL string `json:"url"` SendPost bool `json:"sendPost"` APIURL string `json:"apiUrl"` } `json:"webCommandMetadata"` } `json:"commandMetadata"` FeedbackEndpoint struct { FeedbackToken string `json:"feedbackToken"` UIActions struct { HideEnclosingContainer bool `json:"hideEnclosingContainer"` } `json:"uiActions"` } `json:"feedbackEndpoint"` } `json:"serviceEndpoint"` NavigationEndpoint struct { ClickTrackingParams string `json:"clickTrackingParams"` CommandMetadata struct { WebCommandMetadata struct { URL string `json:"url"` WebPageType string `json:"webPageType"` RootVe int `json:"rootVe"` } `json:"webCommandMetadata"` } `json:"commandMetadata"` BrowseEndpoint struct { BrowseID string `json:"browseId"` Params string `json:"params"` } `json:"browseEndpoint"` } `json:"navigationEndpoint"` TrackingParams string `json:"trackingParams"` } `json:"buttonRenderer"` } `json:"actionButton"` DismissButton struct { ButtonRenderer struct { Style string `json:"style"` Size string `json:"size"` Text struct { Runs []struct { Text string `json:"text"` } `json:"runs"` } `json:"text"` ServiceEndpoint struct { ClickTrackingParams string `json:"clickTrackingParams"` CommandMetadata struct { WebCommandMetadata struct { URL string `json:"url"` SendPost bool `json:"sendPost"` APIURL string `json:"apiUrl"` } `json:"webCommandMetadata"` } `json:"commandMetadata"` FeedbackEndpoint struct { FeedbackToken string `json:"feedbackToken"` UIActions struct { HideEnclosingContainer bool `json:"hideEnclosingContainer"` } `json:"uiActions"` } `json:"feedbackEndpoint"` } `json:"serviceEndpoint"` TrackingParams string `json:"trackingParams"` } `json:"buttonRenderer"` } `json:"dismissButton"` TriggerCondition string `json:"triggerCondition"` Style string `json:"style"` TrackingParams string `json:"trackingParams"` ImpressionEndpoints []struct { ClickTrackingParams string `json:"clickTrackingParams"` CommandMetadata struct { WebCommandMetadata struct { URL string `json:"url"` SendPost bool `json:"sendPost"` APIURL string `json:"apiUrl"` } `json:"webCommandMetadata"` } `json:"commandMetadata"` FeedbackEndpoint struct { FeedbackToken string `json:"feedbackToken"` UIActions struct { HideEnclosingContainer bool `json:"hideEnclosingContainer"` } `json:"uiActions"` } `json:"feedbackEndpoint"` } `json:"impressionEndpoints"` IsVisible bool `json:"isVisible"` MessageTitle struct { Runs []struct { Text string `json:"text"` } `json:"runs"` } `json:"messageTitle"` } `json:"mealbarPromoRenderer"` } `json:"messages"` }
type StreamInfo ¶
type Youtube ¶
type Youtube struct { DebugMode bool StreamList []Stream VideoID string DownloadPercent chan int64 Socks5Proxy string Title string Author string // Disable SSL certificate verification InsecureSkipVerify bool // contains filtered or unexported fields }
Youtube implements the downloader to download youtube videos.
func NewYoutube ¶
NewYoutube :Initialize youtube package object.
Example ¶
ExampleDownload : Example code for how to use this package for download video.
package main import ( "flag" "fmt" "log" "os/user" "github.com/eimlav/youtube" ) func main() { flag.Parse() log.Println(flag.Args()) usr, _ := user.Current() currentDir := fmt.Sprintf("%v/Movies/youtubedr", usr.HomeDir) log.Println("download to dir=", currentDir) y := youtube.NewYoutube(true, false) arg := flag.Arg(0) if err := y.DecodeURL(arg); err != nil { fmt.Println("err:", err) } if err := y.StartDownload(currentDir, "dl.mp4", "", 0); err != nil { fmt.Println("err:", err) } }
Output:
func (*Youtube) GetStreamInfo ¶
func (y *Youtube) GetStreamInfo() *StreamInfo
func (*Youtube) StartDownload ¶
StartDownload : Starting download video by arguments.
Click to show internal directories.
Click to hide internal directories.