Skip to content

Commit ac4a898

Browse files
committed
Add playistID cli flag
1 parent 9757aa1 commit ac4a898

File tree

5 files changed

+49
-31
lines changed

5 files changed

+49
-31
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ Usage:
8989
notify channel subscribers of new video. Specify '-notify=false' to disable. (default true)
9090
-oAuthPort int
9191
TCP port to listen on when requesting an oAuth token (default 8080)
92+
-playlistID value
93+
playlistID to add the video to. Can be used multiple times
9294
-privacy string
9395
video privacy status (default "private")
9496
-quiet

cmd/youtubeuploader/main.go

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,36 +32,50 @@ import (
3232

3333
const inputTimeLayout = "15:04"
3434

35-
var (
36-
filename = flag.String("filename", "", "video filename. Can be a URL. Read from stdin with '-'")
37-
thumbnail = flag.String("thumbnail", "", "thumbnail filename. Can be a URL")
38-
caption = flag.String("caption", "", "caption filename. Can be a URL")
39-
title = flag.String("title", "", "video title")
40-
description = flag.String("description", "uploaded by youtubeuploader", "video description")
41-
language = flag.String("language", "en", "video language")
42-
categoryId = flag.String("categoryId", "", "video category Id")
43-
tags = flag.String("tags", "", "comma separated list of video tags")
44-
privacy = flag.String("privacy", "private", "video privacy status")
45-
quiet = flag.Bool("quiet", false, "suppress progress indicator")
46-
rateLimit = flag.Int("ratelimit", 0, "rate limit upload in Kbps. No limit by default")
47-
metaJSON = flag.String("metaJSON", "", "JSON file containing title,description,tags etc (optional)")
48-
metaJSONout = flag.String("metaJSONout", "", "filename to write uploaded video metadata into (optional)")
49-
limitBetween = flag.String("limitBetween", "", "only rate limit between these times e.g. 10:00-14:00 (local time zone)")
50-
oAuthPort = flag.Int("oAuthPort", 8080, "TCP port to listen on when requesting an oAuth token")
51-
showAppVersion = flag.Bool("version", false, "show version")
52-
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")
53-
notifySubscribers = flag.Bool("notify", true, "notify channel subscribers of new video. Specify '-notify=false' to disable.")
54-
debug = flag.Bool("debug", false, "turn on verbose log output")
55-
sendFileName = flag.Bool("sendFilename", true, "send original file name to YouTube")
35+
type arrayFlags []string
5636

57-
// this is set by compile-time to match git tag
58-
appVersion string = "unknown"
59-
)
37+
// String is an implementation of the flag.Value interface
38+
func (i *arrayFlags) String() string {
39+
return fmt.Sprintf("%v", *i)
40+
}
41+
42+
// Set is an implementation of the flag.Value interface
43+
func (i *arrayFlags) Set(value string) error {
44+
*i = append(*i, value)
45+
return nil
46+
}
6047

6148
func main() {
6249

6350
var err error
6451

52+
var playlistIDs arrayFlags
53+
54+
flag.Var(&playlistIDs, "playlistID", "playlist ID to add the video to. Can be used multiple times")
55+
filename := flag.String("filename", "", "video filename. Can be a URL. Read from stdin with '-'")
56+
thumbnail := flag.String("thumbnail", "", "thumbnail filename. Can be a URL")
57+
caption := flag.String("caption", "", "caption filename. Can be a URL")
58+
title := flag.String("title", "", "video title")
59+
description := flag.String("description", "uploaded by youtubeuploader", "video description")
60+
language := flag.String("language", "en", "video language")
61+
categoryId := flag.String("categoryId", "", "video category Id")
62+
tags := flag.String("tags", "", "comma separated list of video tags")
63+
privacy := flag.String("privacy", "private", "video privacy status")
64+
quiet := flag.Bool("quiet", false, "suppress progress indicator")
65+
rateLimit := flag.Int("ratelimit", 0, "rate limit upload in Kbps. No limit by default")
66+
metaJSON := flag.String("metaJSON", "", "JSON file containing title,description,tags etc (optional)")
67+
metaJSONout := flag.String("metaJSONout", "", "filename to write uploaded video metadata into (optional)")
68+
limitBetween := flag.String("limitBetween", "", "only rate limit between these times e.g. 10:00-14:00 (local time zone)")
69+
oAuthPort := flag.Int("oAuthPort", 8080, "TCP port to listen on when requesting an oAuth token")
70+
showAppVersion := flag.Bool("version", false, "show version")
71+
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")
72+
notifySubscribers := flag.Bool("notify", true, "notify channel subscribers of new video. Specify '-notify:=false' to disable.")
73+
debug := flag.Bool("debug", false, "turn on verbose log output")
74+
sendFileName := flag.Bool("sendFilename", true, "send original file name to YouTube")
75+
76+
// this is set by compile-time to match git tag
77+
appVersion := "unknown"
78+
6579
flag.Parse()
6680
config := yt.Config{
6781
Filename: *filename,
@@ -83,6 +97,7 @@ func main() {
8397
Chunksize: *chunksize,
8498
NotifySubscribers: *notifySubscribers,
8599
SendFileName: *sendFileName,
100+
PlaylistIDs: playlistIDs,
86101
}
87102

88103
config.Logger = utils.NewLogger(*debug)

files.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"io"
2121
"net/http"
2222
"os"
23+
"slices"
2324
"strconv"
2425
"strings"
2526
"time"
@@ -54,6 +55,7 @@ type Config struct {
5455
MetaJSON string
5556
MetaJSONOut string
5657
LimitBetween string
58+
PlaylistIDs []string
5759
OAuthPort int
5860
ShowAppVersion bool
5961
Chunksize int
@@ -69,11 +71,6 @@ type Date struct {
6971
time.Time
7072
}
7173

72-
func LoadConfig() (*VideoMeta, error) {
73-
74-
return nil, nil
75-
}
76-
7774
func LoadVideoMeta(config Config, video *youtube.Video) (*VideoMeta, error) {
7875
videoMeta := &VideoMeta{}
7976

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

181+
// combine cli flag playistIDs and metaJSON playlistIDs. Remove any duplicates
182+
playlistIDs := slices.Concat(config.PlaylistIDs, videoMeta.PlaylistIDs)
183+
slices.Sort(playlistIDs)
184+
videoMeta.PlaylistIDs = slices.Compact(playlistIDs)
185+
184186
return videoMeta, nil
185187
}
186188

http.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ type VideoMeta struct {
4444
// recording details
4545
RecordingDate Date `json:"recordingDate,omitempty"`
4646

47-
// PlaylistID is deprecated in favour of PlaylistIDs
48-
PlaylistID string `json:"playlistId,omitempty"`
4947
PlaylistIDs []string `json:"playlistIds,omitempty"`
5048
PlaylistTitles []string `json:"playlistTitles,omitempty"`
5149

test/upload_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ func TestMain(m *testing.M) {
125125
//config.Logger = utils.NewLogger(true)
126126
config.Logger = utils.NewLogger(false)
127127
config.Filename = "test.mp4"
128+
config.PlaylistIDs = []string{"xxxx", "yyyy"}
128129

129130
ret := m.Run()
130131

0 commit comments

Comments
 (0)