ytapi

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2019 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Copyright David Thorpe 2015-2016 All Rights Reserved Please see file LICENSE for information on distribution, etc

Index

Constants

View Source
const (
	YouTubeMaxPagingResults         = 50
	YouTubeMaxLiveChatPagingResults = 200
)

Constants

View Source
const (
	OUTPUT_ASCII = iota
	OUTPUT_CSV
)
View Source
const (
	FLAG_STRING = iota
	FLAG_UINT
	FLAG_BOOL
	FLAG_ENUM
	FLAG_VIDEO
	FLAG_CHANNEL
	FLAG_PLAYLIST
	FLAG_LANGUAGE
	FLAG_REGION
	FLAG_STREAM
	FLAG_CONTENTOWNER
	FLAG_TIME
	FLAG_DURATION
)

Variables

View Source
var (
	FlagCredentials                = Flag{Name: "credentials", Description: "Folder containing credentials", Type: FLAG_STRING, Default: ".ytapi"}
	FlagDebug                      = Flag{Name: "debug", Description: "Show API requests and responses on stderr", Type: FLAG_BOOL, Default: "false"}
	FlagQuotaUser                  = Flag{Name: "quotauser", Description: "Set Quota User for API calls", Type: FLAG_STRING}
	FlagTraceToken                 = Flag{Name: "tracetoken", Description: "Set Trace Token for API calls", Type: FLAG_STRING}
	FlagServiceAccount             = Flag{Name: "serviceaccount", Description: "Obtain token using service account information", Type: FLAG_BOOL, Default: "false"}
	FlagScope                      = Flag{Name: "scope", Description: "Permissions granted during authentication", Type: FLAG_ENUM, Default: "data", Extra: "data|dataread|partner|audit|analytics|revenue|all"}
	FlagFields                     = Flag{Name: "fields", Description: "Comma-separated list of output fields", Type: FLAG_STRING}
	FlagInput                      = Flag{Name: "in", Description: "Input filename and/or format (csv)", Type: FLAG_STRING, Default: "csv"}
	FlagOutput                     = Flag{Name: "out", Description: "Output filename and/or format (txt, csv)", Type: FLAG_STRING, Default: "txt"}
	FlagFile                       = Flag{Name: "file", Description: "Filename", Type: FLAG_STRING}
	FlagContentOwner               = Flag{Name: "contentowner", Description: "Content Owner ID", Type: FLAG_CONTENTOWNER}
	FlagChannel                    = Flag{Name: "channel", Description: "Channel ID", Type: FLAG_CHANNEL}
	FlagMaxResults                 = Flag{Name: "maxresults", Description: "Maximum number of results to return", Type: FLAG_UINT, Default: "0"}
	FlagVideo                      = Flag{Name: "video", Description: "Video ID", Type: FLAG_VIDEO}
	FlagPlaylist                   = Flag{Name: "playlist", Description: "Playlist ID", Type: FLAG_PLAYLIST}
	FlagStream                     = Flag{Name: "stream", Description: "Stream ID or Key", Type: FLAG_STREAM}
	FlagLanguage                   = Flag{Name: "language", Description: "Localized language", Type: FLAG_LANGUAGE}
	FlagRegion                     = Flag{Name: "region", Description: "Country region code", Type: FLAG_REGION}
	FlagTitle                      = Flag{Name: "title", Description: "Metadata title", Type: FLAG_STRING}
	FlagDescription                = Flag{Name: "description", Description: "Metadata description", Type: FLAG_STRING}
	FlagEmbeds                     = Flag{Name: "embeds", Description: "Embed player flag", Type: FLAG_BOOL}
	FlagLicense                    = Flag{Name: "license", Description: "Video License", Type: FLAG_ENUM, Extra: "youtube|creativeCommon"}
	FlagStatsViewable              = Flag{Name: "statsviewable", Description: "Extended video statistics are publicly viewable", Type: FLAG_BOOL}
	FlagPrivacyStatus              = Flag{Name: "status", Description: "Privacy status", Type: FLAG_ENUM, Extra: "private|public|unlisted"}
	FlagDate                       = Flag{Name: "date", Description: "Publish date and time", Type: FLAG_TIME}
	FlagBroadcastStatus            = Flag{Name: "status", Description: "Broadcast status", Type: FLAG_ENUM, Extra: "all|upcoming|active|completed"}
	FlagBroadcastTransition        = Flag{Name: "status", Description: "Broadcast transition", Type: FLAG_ENUM, Extra: "complete|live|testing"}
	FlagStartTime                  = Flag{Name: "start", Description: "Scheduled start time", Type: FLAG_TIME}
	FlagEndTime                    = Flag{Name: "end", Description: "Scheduled end time", Type: FLAG_TIME}
	FlagDvr                        = Flag{Name: "dvr", Description: "Enable DVR", Type: FLAG_BOOL}
	FlagContentEncryption          = Flag{Name: "encryption", Description: "Enable content encryption", Type: FLAG_BOOL}
	FlagEmbed                      = Flag{Name: "embed", Description: "Enable embedding", Type: FLAG_BOOL}
	FlagRecordFromStart            = Flag{Name: "record", Description: "Enable recording", Type: FLAG_BOOL}
	FlagStartWithSlate             = Flag{Name: "slate", Description: "Start with slate", Type: FLAG_BOOL}
	FlagClosedCaptions             = Flag{Name: "captions", Description: "Enable closed captions", Type: FLAG_BOOL}
	FlagMonitorStream              = Flag{Name: "monitor", Description: "Enable stream monitoring", Type: FLAG_BOOL}
	FlagBroadcastDelay             = Flag{Name: "delay", Description: "Broadcast delay (ms)", Type: FLAG_UINT}
	FlagLowLatency                 = Flag{Name: "lowlatency", Description: "Enable low latency", Type: FLAG_BOOL}
	FlagProjection                 = Flag{Name: "projection", Description: "Projection format", Type: FLAG_ENUM, Extra: "360|rectangular"}
	FlagCuepointOffset             = Flag{Name: "offset", Description: "Offset time (ms)", Type: FLAG_UINT}
	FlagCuepointDuration           = Flag{Name: "duration", Description: "Duration", Type: FLAG_DURATION}
	FlagCuepointTime               = Flag{Name: "time", Description: "Walltime", Type: FLAG_TIME}
	FlagCuepointPodDuration        = Flag{Name: "podduration", Description: "Ad Pod Duration", Type: FLAG_DURATION}
	FlagVideoFilter                = Flag{Name: "filter", Description: "Video filter", Type: FLAG_ENUM, Extra: "chart|like|dislike|likes|favorites|uploads|watchhistory|watchlater", Default: "uploads"}
	FlagVideoCategory              = Flag{Name: "category", Description: "Video Category", Type: FLAG_UINT}
	FlagVideoRating                = Flag{Name: "rating", Description: "Video Rating", Type: FLAG_ENUM, Extra: "like|dislike|none"}
	FlagCommentThread              = Flag{Name: "thread", Description: "Comment Thread", Type: FLAG_STRING}
	FlagCommentText                = Flag{Name: "text", Description: "Comment Text", Type: FLAG_STRING}
	FlagCommentFormat              = Flag{Name: "format", Description: "Comment Format", Type: FLAG_ENUM, Extra: "plainText|html", Default: "plainText"}
	FlagCommentOrder               = Flag{Name: "order", Description: "Comment order", Type: FLAG_ENUM, Extra: "time|relevance"}
	FlagCommentModerationStatus    = Flag{Name: "status", Description: "Comment moderation status", Type: FLAG_ENUM, Extra: "heldForReview|likelySpam|published"}
	FlagCommentModerationStatus2   = Flag{Name: "status", Description: "Comment moderation status", Type: FLAG_ENUM, Extra: "heldForReview|published|rejected"}
	FlagCommentBanAuthor           = Flag{Name: "ban", Description: "Ban comment author", Type: FLAG_BOOL}
	FlagChat                       = Flag{Name: "chat", Description: "Live Chat or Broadcast ID", Type: FLAG_STRING}
	FlagChatMessage                = Flag{Name: "message", Description: "Live Chat Message", Type: FLAG_STRING}
	FlagChatText                   = Flag{Name: "text", Description: "Chat Text", Type: FLAG_STRING}
	FlagActivityHome               = Flag{Name: "home", Description: "Display Homepage Activity Feed", Type: FLAG_BOOL}
	FlagPlaylistPosition           = Flag{Name: "position", Description: "Playlist position", Type: FLAG_UINT}
	FlagPlaylistNote               = Flag{Name: "note", Description: "Playlist note", Type: FLAG_STRING}
	FlagSectionType                = Flag{Name: "type", Description: "Channel Section type", Type: FLAG_ENUM, Extra: "allPlaylists|completedEvents|likedPlaylists|likes|liveEvents|multipleChannels|multiplePlaylists|popularUploads|postedPlaylists|postedVideos|recentActivity|recentPosts|recentUploads|singlePlaylist|subscriptions|upcomingEvents"}
	FlagSectionStyle               = Flag{Name: "style", Description: "Channel Section style", Type: FLAG_ENUM, Extra: "horizontalRow|verticalList", Default: "horizontalRow"}
	FlagSectionPosition            = Flag{Name: "position", Description: "Channel Section position", Type: FLAG_UINT}
	FlagSearchQuery                = Flag{Name: "q", Description: "Search query", Type: FLAG_STRING}
	FlagSearchOrder                = Flag{Name: "order", Description: "Search order", Type: FLAG_ENUM, Extra: "date|rating|relevance|title|viewcount"}
	FlagSearchChannelOrder         = Flag{Name: "order", Description: "Search order", Type: FLAG_ENUM, Extra: "date|rating|relevance|title|viewcount|videocount"}
	FlagSearchVideo                = Flag{Name: "video", Description: "Related video", Type: FLAG_VIDEO}
	FlagSearchSafe                 = Flag{Name: "safesearch", Description: "Restricted content filter", Type: FLAG_ENUM, Extra: "none|moderate|strict"}
	FlagSearchBroadcastStatus      = Flag{Name: "status", Description: "Broadcast status", Type: FLAG_ENUM, Extra: "completed|live|upcoming"}
	FlagCaption                    = Flag{Name: "caption", Description: "Caption ID", Type: FLAG_STRING}
	FlagCaptionSync                = Flag{Name: "sync", Description: "Automatically synchronize the caption file with the audio track of the video", Type: FLAG_BOOL}
	FlagCaptionDraft               = Flag{Name: "draft", Description: "Status of the caption track", Type: FLAG_BOOL}
	FlagCaptionFormat              = Flag{Name: "format", Description: "Format of the caption track", Type: FLAG_ENUM, Extra: "sbv|scc|srt|ttml|vtt"}
	FlagCaptionName                = Flag{Name: "name", Description: "Name of the caption track", Type: FLAG_STRING}
	FlagPolicy                     = Flag{Name: "policy", Description: "Policy ID", Type: FLAG_STRING}
	FlagPolicyOrder                = Flag{Name: "order", Description: "Policy list order", Type: FLAG_ENUM, Extra: "timeUpdatedAsc|timeUpdatedDesc"}
	FlagClaim                      = Flag{Name: "claim", Description: "Claim ID", Type: FLAG_VIDEO}
	FlagClaimType                  = Flag{Name: "type", Description: "Claim Type: Defaults to audiovisual", Type: FLAG_ENUM, Extra: "audio|visual|audiovisual", Default: "audiovisual"}
	FlagClaimStatus                = Flag{Name: "status", Description: "Claim Status", Type: FLAG_ENUM, Extra: "active|inactive"}
	FlagClaimBlockOutsideOwnership = Flag{Name: "blockoutsideownership", Description: "Block viewing outside ownership regions", Type: FLAG_BOOL}
	FlagAsset                      = Flag{Name: "asset", Description: "Asset ID", Type: FLAG_STRING}
	FlagAssetFilter                = Flag{Name: "filter", Description: "Retrieve computed asset information or my asset information", Type: FLAG_ENUM, Extra: "none|effective|mine", Default: "none"}
	FlagUploader                   = Flag{Name: "uploader", Description: "Content Owner Uploader Name", Type: FLAG_STRING}
	FlagStreamResolution           = Flag{Name: "resolution", Description: "Stream Resolution", Type: FLAG_ENUM, Extra: "2160p_hfr|2160p|1440p_hfr|1440p|1080p_hfr|1080p|720p_hfr|720p|480p|360p|240p", Default: "1080p"}
	FlagStreamType                 = Flag{Name: "type", Description: "Stream Ingestion Type", Type: FLAG_ENUM, Extra: "rtmp|dash", Default: "rtmp"}
	FlagStreamReusable             = Flag{Name: "reusable", Description: "Stream Reusable", Type: FLAG_BOOL}
	FlagAnalyticsPeriod            = Flag{Name: "period", Description: "Time period", Type: FLAG_STRING, Default: "last28Days"}
	FlagAnalyticsMetrics           = Flag{Name: "metrics", Description: "Analytics Metrics", Type: FLAG_STRING}
	FlagAnalyticsDimensions        = Flag{Name: "dimensions", Description: "Analytics Dimensions", Type: FLAG_STRING}
	FlagAnalyticsFilter            = Flag{Name: "filter", Description: "Analytics Filters", Type: FLAG_STRING}
	FlagAnalyticsSort              = Flag{Name: "sort", Description: "Data sort order", Type: FLAG_STRING}
	FlagAnalyticsCurrency          = Flag{Name: "currency", Description: "Reporting Currency", Type: FLAG_STRING}
	FlagAnalyticsIncludeSystem     = Flag{Name: "system", Description: "Include system managed reports", Type: FLAG_BOOL}
)

Command-line flags

View Source
var (

	// Global flags which are defined for every invocation of the tool
	GlobalFlags = []*Flag{
		&FlagDebug, &FlagQuotaUser, &FlagTraceToken, &FlagCredentials,
		&FlagContentOwner, &FlagChannel,
		&FlagFields, &FlagOutput, &FlagInput,
	}

	// Variety of error conditions
	ErrorEmptyArgs        = errors.New("No Arguments")
	ErrorUsage            = errors.New("Display usage information")
	ErrorWriteDefaults    = errors.New("Write Defaults to file")
	ErrorWriteCredentials = errors.New("Write Credentials")
	ErrorRemoveAuthToken  = errors.New("Remove OAuth token")
	ErrorServiceAccount   = errors.New("Invalid service account or missing content owner")
)

////////////////////////////////////////////////////////////////////////////// Global variables

View Source
var (
	RegExStreamKey        = regexp.MustCompile("^([a-zA-Z0-9]{4})-([a-zA-Z0-9]{4})-([a-zA-Z0-9]{4})-([a-zA-Z0-9]{4})$")
	RegExStreamIdentifier = regexp.MustCompile("^([a-zA-Z0-9\\-]{38})$")
	RegExVideoIdentifier  = regexp.MustCompile("^([a-zA-Z0-9\\-\\_]{11})$")
)
View Source
var (
	ErrFieldMismatch = errors.New("Number of fields does not match")
)

Functions

func DoActivityList

func DoActivityList(call *youtube.ActivitiesListCall, table *Table, maxresults int64) error

func DoBroadcastsList

func DoBroadcastsList(call *youtube.LiveBroadcastsListCall, table *Table, maxresults int64) error

func DoChannelsList

func DoChannelsList(call *youtube.ChannelsListCall, table *Table, maxresults int64) error

func DoChatMessagesList

func DoChatMessagesList(call *youtube.LiveChatMessagesListCall, table *Table, maxresults int64) error

func DoChatModeratorsList

func DoChatModeratorsList(call *youtube.LiveChatModeratorsListCall, table *Table, maxresults int64) error

func DoClaimsList

func DoClaimsList(call *youtubepartner.ClaimsListCall, table *Table, maxresults int64) error

func DoCommentThreadsList

func DoCommentThreadsList(call *youtube.CommentThreadsListCall, table *Table, maxresults int64) error

func DoCommentsList

func DoCommentsList(call *youtube.CommentsListCall, table *Table, maxresults int64) error

func DoPlaylistItemsList

func DoPlaylistItemsList(call *youtube.PlaylistItemsListCall, table *Table, maxresults int64) error

func DoPlaylistsList

func DoPlaylistsList(call *youtube.PlaylistsListCall, table *Table, maxresults int64) error

func DoSearchList

func DoSearchList(call *youtube.SearchListCall, table *Table, maxresults int64) error

func DoStreamsList

func DoStreamsList(call *youtube.LiveStreamsListCall, table *Table, maxresults int64) error

func DoVideosList

func DoVideosList(call *youtube.VideosListCall, table *Table, maxresults int64) error

Types

type Command

type Command struct {
	Name           string
	Description    string
	ServiceAccount bool
	Optional       []*Flag
	Required       []*Flag
	Setup          func(*Values, *Table) error
	Execute        func(*ytservice.Service, *Values, *Table) error
}

Command structure defines a command

type Defaults

type Defaults struct {
	ContentOwner string `json:"contentowner,omitempty"`
	Channel      string `json:"channel,omitempty"`
}

Defaults structure defines values read from store

type Flag

type Flag struct {
	Name        string
	Description string
	Type        uint32
	Extra       string
	Default     string
	Path        string
	Array       bool
	// contains filtered or unexported fields
}

Flag structure defines a parameter type

func (*Flag) TypeString

func (this *Flag) TypeString() string

type FlagSet

type FlagSet struct {
	Values         *Values
	Input          *Input
	Output         *Table
	ClientSecrets  string
	ServiceAccount string
	AuthToken      string
	Defaults       string
	// contains filtered or unexported fields
}

FlagSet structure defines the main object for execution of a set of instructions

func NewFlagSet

func NewFlagSet() *FlagSet

NewFlagSet returns a new set of flags

func (*FlagSet) AddFlag

func (this *FlagSet) AddFlag(flag *Flag) error

AddFlag adds a flag to the flagset

func (*FlagSet) AddFlags

func (this *FlagSet) AddFlags(flags []*Flag) error

func (*FlagSet) CloseOutput

func (this *FlagSet) CloseOutput() error

func (*FlagSet) DisplayOutput

func (this *FlagSet) DisplayOutput() error

func (*FlagSet) ExecuteCommand

func (this *FlagSet) ExecuteCommand(command *Command, service *ytservice.Service) error

func (*FlagSet) GetCommandFromName

func (this *FlagSet) GetCommandFromName(name string) (*Command, error)

func (*FlagSet) OpenOutput

func (this *FlagSet) OpenOutput() error

func (*FlagSet) Parse

func (this *FlagSet) Parse() (*Command, error)

func (*FlagSet) ReadDefaults

func (this *FlagSet) ReadDefaults() error

func (*FlagSet) ReadInput

func (this *FlagSet) ReadInput() error

func (*FlagSet) RegisterCommands

func (this *FlagSet) RegisterCommands(funcs []*RegisterFunction) error

func (*FlagSet) RemoveAuthToken

func (this *FlagSet) RemoveAuthToken() error

func (*FlagSet) SetFields

func (this *FlagSet) SetFields(fields []string) error

func (*FlagSet) SetupCommand

func (this *FlagSet) SetupCommand(command *Command) error

func (*FlagSet) UsageCommand

func (this *FlagSet) UsageCommand(command *Command)

Output a list of flags for a command.

func (*FlagSet) UsageCommandList

func (this *FlagSet) UsageCommandList()

Output a list of possible commands, grouped by section. Will not display commands which are only to be used for service accounts, if no service account is installed

func (*FlagSet) UsageFields

func (this *FlagSet) UsageFields()

func (*FlagSet) UsageGlobalFlags

func (this *FlagSet) UsageGlobalFlags()

func (*FlagSet) WriteClientSecret

func (this *FlagSet) WriteClientSecret(data64 string) error

func (*FlagSet) WriteDefaults

func (this *FlagSet) WriteDefaults() error

func (*FlagSet) WriteServiceAccount

func (this *FlagSet) WriteServiceAccount(data64 string) error

type Input

type Input struct {
	// contains filtered or unexported fields
}

func NewInput

func NewInput() *Input

NewInput returns a new table object

func (*Input) Close

func (this *Input) Close()

Close closes the input file handle

func (*Input) ReadAll

func (this *Input) ReadAll() error

ReadAll will read everything

func (*Input) SetDataSource

func (this *Input) SetDataSource(handle io.ReadCloser, format InputFormat)

SetDataSource sets Incoming data source

type InputFormat

type InputFormat int
const (
	INPUT_CSV InputFormat = iota
)

type RegisterFunction

type RegisterFunction struct {
	Title    string
	Callback func() []*Command
}

RegisterFunction defines a registration function

type Section

type Section struct {
	Title    string
	Commands []*Command
}

Section structure defines a group of commands

type Table

type Table struct {
	// contains filtered or unexported fields
}

func NewTable

func NewTable() *Table

Returns a new table object

func (*Table) AddFieldOrPart

func (this *Table) AddFieldOrPart(key string) error

Add a column or part

func (*Table) Append

func (this *Table) Append(items interface{}) error

Append items to the table

func (*Table) DataOutput

func (this *Table) DataOutput() error

func (*Table) FieldsForPart

func (this *Table) FieldsForPart(part string) []*Flag

Return fields for a particular part

func (*Table) Info

func (this *Table) Info(message string)

Info outputs message to the output stream

func (*Table) NewRow

func (this *Table) NewRow() *Values

Creates a new row object and appends it to the table

func (*Table) NumberOfColumns

func (this *Table) NumberOfColumns() int

Return number of columns

func (*Table) NumberOfRows

func (this *Table) NumberOfRows() int

Return number of rows

func (*Table) Parts

func (this *Table) Parts(all bool) []string

Return parts which are used in the column output, or if 'all' is set to true, return all parts registered in order

func (*Table) RegisterPart

func (this *Table) RegisterPart(part string, fields []*Flag)

Register a part & fields

func (*Table) RemoveFieldOrPart

func (this *Table) RemoveFieldOrPart(key string) error

Remove a field or part from the output columns

func (*Table) SetColumns

func (this *Table) SetColumns(columns []string) error

Set the default output columns

func (*Table) SetDataFormat

func (this *Table) SetDataFormat(handle io.Writer, format int)

Set output format

type Value

type Value struct {
	// contains filtered or unexported fields
}

Value structure defines a generic value

func NewValue

func NewValue(flag *Flag, value reflect.Value) (*Value, error)

func NewValueWithString

func NewValueWithString(flag *Flag, value string) (*Value, error)

func (*Value) Bool

func (this *Value) Bool() bool

func (*Value) Duration

func (this *Value) Duration() time.Duration

func (*Value) IsBoolFlag

func (this *Value) IsBoolFlag() bool

func (*Value) IsSet

func (this *Value) IsSet() bool

func (*Value) Set

func (this *Value) Set(value string) error

Set conforms Value to the flag interface

func (*Value) SetBool

func (this *Value) SetBool(value bool) error

func (*Value) SetFloat

func (this *Value) SetFloat(value float64) error

func (*Value) SetInt

func (this *Value) SetInt(value int64) error

func (*Value) SetString

func (this *Value) SetString(value string) error

func (*Value) SetUint

func (this *Value) SetUint(value uint64) error

func (*Value) String

func (this *Value) String() string

func (*Value) Time

func (this *Value) Time() time.Time

func (*Value) Uint64

func (this *Value) Uint64() uint64

type Values

type Values struct {
	// contains filtered or unexported fields
}

Values structure defines a set of values

func NewValues

func NewValues() *Values

func (*Values) Get

func (this *Values) Get(flag *Flag) *Value

func (*Values) GetBool

func (this *Values) GetBool(flag *Flag) bool

func (*Values) GetDuration

func (this *Values) GetDuration(flag *Flag) time.Duration

func (*Values) GetInt

func (this *Values) GetInt(flag *Flag) int64

func (*Values) GetString

func (this *Values) GetString(flag *Flag) string

func (*Values) GetTime

func (this *Values) GetTime(flag *Flag) time.Time

func (*Values) GetTimeInISOFormat

func (this *Values) GetTimeInISOFormat(flag *Flag) string

func (*Values) GetUint

func (this *Values) GetUint(flag *Flag) uint64

func (*Values) IsKindOf

func (this *Values) IsKindOf(flag *Flag, kind int) bool

func (*Values) IsSet

func (this *Values) IsSet(flag *Flag) bool

func (*Values) Set

func (this *Values) Set(value *Value) *Value

func (*Values) SetDefault

func (this *Values) SetDefault(flag *Flag, value string) error

func (*Values) SetFields

func (this *Values) SetFields(fieldmap map[string]*Flag) []string

Jump to

Keyboard shortcuts

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