Skip to content

Commit

Permalink
Add playistID cli flag
Browse files Browse the repository at this point in the history
  • Loading branch information
porjo committed Nov 20, 2024
1 parent 9757aa1 commit ac4a898
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 31 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ Usage:
notify channel subscribers of new video. Specify '-notify=false' to disable. (default true)
-oAuthPort int
TCP port to listen on when requesting an oAuth token (default 8080)
-playlistID value
playlistID to add the video to. Can be used multiple times
-privacy string
video privacy status (default "private")
-quiet
Expand Down
63 changes: 39 additions & 24 deletions cmd/youtubeuploader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,36 +32,50 @@ import (

const inputTimeLayout = "15:04"

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")
type arrayFlags []string

// this is set by compile-time to match git tag
appVersion string = "unknown"
)
// String is an implementation of the flag.Value interface
func (i *arrayFlags) String() string {
return fmt.Sprintf("%v", *i)
}

// Set is an implementation of the flag.Value interface
func (i *arrayFlags) Set(value string) error {
*i = append(*i, value)
return nil
}

func main() {

var err error

var playlistIDs arrayFlags

flag.Var(&playlistIDs, "playlistID", "playlist ID to add the video to. Can be used multiple times")
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")

// this is set by compile-time to match git tag
appVersion := "unknown"

flag.Parse()
config := yt.Config{
Filename: *filename,
Expand All @@ -83,6 +97,7 @@ func main() {
Chunksize: *chunksize,
NotifySubscribers: *notifySubscribers,
SendFileName: *sendFileName,
PlaylistIDs: playlistIDs,
}

config.Logger = utils.NewLogger(*debug)
Expand Down
12 changes: 7 additions & 5 deletions files.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"io"
"net/http"
"os"
"slices"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -54,6 +55,7 @@ type Config struct {
MetaJSON string
MetaJSONOut string
LimitBetween string
PlaylistIDs []string
OAuthPort int
ShowAppVersion bool
Chunksize int
Expand All @@ -69,11 +71,6 @@ type Date struct {
time.Time
}

func LoadConfig() (*VideoMeta, error) {

return nil, nil
}

func LoadVideoMeta(config Config, video *youtube.Video) (*VideoMeta, error) {
videoMeta := &VideoMeta{}

Expand Down Expand Up @@ -181,6 +178,11 @@ func LoadVideoMeta(config Config, video *youtube.Video) (*VideoMeta, error) {
video.Snippet.DefaultAudioLanguage = config.Language
}

// combine cli flag playistIDs and metaJSON playlistIDs. Remove any duplicates
playlistIDs := slices.Concat(config.PlaylistIDs, videoMeta.PlaylistIDs)
slices.Sort(playlistIDs)
videoMeta.PlaylistIDs = slices.Compact(playlistIDs)

return videoMeta, nil
}

Expand Down
2 changes: 0 additions & 2 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ type VideoMeta struct {
// recording details
RecordingDate Date `json:"recordingDate,omitempty"`

// PlaylistID is deprecated in favour of PlaylistIDs
PlaylistID string `json:"playlistId,omitempty"`
PlaylistIDs []string `json:"playlistIds,omitempty"`
PlaylistTitles []string `json:"playlistTitles,omitempty"`

Expand Down
1 change: 1 addition & 0 deletions test/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func TestMain(m *testing.M) {
//config.Logger = utils.NewLogger(true)
config.Logger = utils.NewLogger(false)
config.Filename = "test.mp4"
config.PlaylistIDs = []string{"xxxx", "yyyy"}

ret := m.Run()

Expand Down

0 comments on commit ac4a898

Please sign in to comment.