Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add options for channel selection and BehalfOf #190

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 51 additions & 39 deletions cmd/youtubeuploader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,36 @@ import (

const inputTimeLayout = "15:04"

// In cmd/youtubeuploader/main.go

var (
// Existing flags...
// Other flags...
)
var (
filename = flag.String("filename", "", "video filename. Can be a URL. Read from stdin with '-'")
thumbnail = flag.String("thumbnail", "", "thumbnail filename. Can be a URL")
caption = flag.String("caption", "", "caption filename. Can be a URL")
title = flag.String("title", "", "video title")
description = flag.String("description", "uploaded by youtubeuploader", "video description")
language = flag.String("language", "en", "video language")
categoryId = flag.String("categoryId", "", "video category Id")
tags = flag.String("tags", "", "comma separated list of video tags")
privacy = flag.String("privacy", "private", "video privacy status")
quiet = flag.Bool("quiet", false, "suppress progress indicator")
rateLimit = flag.Int("ratelimit", 0, "rate limit upload in Kbps. No limit by default")
metaJSON = flag.String("metaJSON", "", "JSON file containing title,description,tags etc (optional)")
metaJSONout = flag.String("metaJSONout", "", "filename to write uploaded video metadata into (optional)")
limitBetween = flag.String("limitBetween", "", "only rate limit between these times e.g. 10:00-14:00 (local time zone)")
oAuthPort = flag.Int("oAuthPort", 8080, "TCP port to listen on when requesting an oAuth token")
showAppVersion = flag.Bool("version", false, "show version")
chunksize = flag.Int("chunksize", googleapi.DefaultUploadChunkSize, "size (in bytes) of each upload chunk. A zero value will cause all data to be uploaded in a single request")
notifySubscribers = flag.Bool("notify", true, "notify channel subscribers of new video. Specify '-notify=false' to disable.")
debug = flag.Bool("debug", false, "turn on verbose log output")
sendFileName = flag.Bool("sendFilename", true, "send original file name to YouTube")
filename = flag.String("filename", "", "video filename. Can be a URL. Read from stdin with '-'")
thumbnail = flag.String("thumbnail", "", "thumbnail filename. Can be a URL")
caption = flag.String("caption", "", "caption filename. Can be a URL")
title = flag.String("title", "", "video title")
description = flag.String("description", "uploaded by youtubeuploader", "video description")
language = flag.String("language", "en", "video language")
categoryId = flag.String("categoryId", "", "video category Id")
tags = flag.String("tags", "", "comma separated list of video tags")
privacy = flag.String("privacy", "private", "video privacy status")
quiet = flag.Bool("quiet", false, "suppress progress indicator")
rateLimit = flag.Int("ratelimit", 0, "rate limit upload in Kbps. No limit by default")
metaJSON = flag.String("metaJSON", "", "JSON file containing title,description,tags etc (optional)")
metaJSONout = flag.String("metaJSONout", "", "filename to write uploaded video metadata into (optional)")
limitBetween = flag.String("limitBetween", "", "only rate limit between these times e.g. 10:00-14:00 (local time zone)")
oAuthPort = flag.Int("oAuthPort", 8080, "TCP port to listen on when requesting an oAuth token")
showAppVersion = flag.Bool("version", false, "show version")
chunksize = flag.Int("chunksize", googleapi.DefaultUploadChunkSize, "size (in bytes) of each upload chunk. A zero value will cause all data to be uploaded in a single request")
notifySubscribers = flag.Bool("notify", true, "notify channel subscribers of new video. Specify '-notify=false' to disable.")
debug = flag.Bool("debug", false, "turn on verbose log output")
sendFileName = flag.Bool("sendFilename", true, "send original file name to YouTube")
channelId = flag.String("channelId", "", "Channel ID for which the video is being uploaded")
onBehalfOfContentOwner = flag.String("onBehalfOfContentOwner", "", "Content owner for which the video is being uploaded")
onBehalfOfContentOwnerChannel = flag.String("onBehalfOfContentOwnerChannel", "", "Content owner's channel for which the video is being uploaded")

// this is set by compile-time to match git tag
appVersion string = "unknown"
Expand All @@ -64,25 +73,28 @@ func main() {

flag.Parse()
config := yt.Config{
Filename: *filename,
Thumbnail: *thumbnail,
Caption: *caption,
Title: *title,
Description: *description,
Language: *language,
CategoryId: *categoryId,
Tags: *tags,
Privacy: *privacy,
Quiet: *quiet,
RateLimit: *rateLimit,
MetaJSON: *metaJSON,
MetaJSONOut: *metaJSONout,
LimitBetween: *limitBetween,
OAuthPort: *oAuthPort,
ShowAppVersion: *showAppVersion,
Chunksize: *chunksize,
NotifySubscribers: *notifySubscribers,
SendFileName: *sendFileName,
Filename: *filename,
Thumbnail: *thumbnail,
Caption: *caption,
Title: *title,
Description: *description,
Language: *language,
CategoryId: *categoryId,
Tags: *tags,
Privacy: *privacy,
Quiet: *quiet,
RateLimit: *rateLimit,
MetaJSON: *metaJSON,
MetaJSONOut: *metaJSONout,
LimitBetween: *limitBetween,
OAuthPort: *oAuthPort,
ShowAppVersion: *showAppVersion,
Chunksize: *chunksize,
NotifySubscribers: *notifySubscribers,
SendFileName: *sendFileName,
ChannelId: *channelId,
OnBehalfOfContentOwner: *onBehalfOfContentOwner,
OnBehalfOfContentOwnerChannel: *onBehalfOfContentOwnerChannel,
}

config.Logger = utils.NewLogger(*debug)
Expand Down
41 changes: 22 additions & 19 deletions files.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,28 @@ const (
)

type Config struct {
Filename string
Thumbnail string
Caption string
Title string
Description string
Language string
CategoryId string
Tags string
Privacy string
Quiet bool
RateLimit int
MetaJSON string
MetaJSONOut string
LimitBetween string
OAuthPort int
ShowAppVersion bool
Chunksize int
NotifySubscribers bool
SendFileName bool
Filename string
Thumbnail string
Caption string
Title string
Description string
Language string
CategoryId string
Tags string
Privacy string
Quiet bool
RateLimit int
MetaJSON string
MetaJSONOut string
LimitBetween string
OAuthPort int
ShowAppVersion bool
Chunksize int
NotifySubscribers bool
SendFileName bool
ChannelId string
OnBehalfOfContentOwner string
OnBehalfOfContentOwnerChannel string

Logger utils.Logger
}
Expand Down
9 changes: 9 additions & 0 deletions run.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ func Run(ctx context.Context, transport *limiter.LimitTransport, config Config,
option = googleapi.ChunkSize(config.Chunksize)

call := service.Videos.Insert([]string{"snippet", "status", "recordingDetails"}, upload)

// Conditionally set OnBehalfOfContentOwner and OnBehalfOfContentOwnerChannel
if config.OnBehalfOfContentOwner != "" {
call = call.OnBehalfOfContentOwner(config.OnBehalfOfContentOwner)
}
if config.OnBehalfOfContentOwnerChannel != "" {
call = call.OnBehalfOfContentOwnerChannel(config.OnBehalfOfContentOwnerChannel)
}

if config.SendFileName && config.Filename != "-" {
filetitle := filepath.Base(config.Filename)
config.Logger.Debugf("Adding file name to request: %q\n", filetitle)
Expand Down