Skip to content

Commit 8bb22e2

Browse files
committed
✨ New fields in video insert/update
issue #182
1 parent 511c973 commit 8bb22e2

File tree

5 files changed

+94
-23
lines changed

5 files changed

+94
-23
lines changed

cmd/video/insert.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,14 @@ var insertInSchema = &jsonschema.Schema{
5555
Type: "string", Description: privacyUsage,
5656
Enum: []any{"public", "private", "unlisted"},
5757
},
58-
"for_kids": {Type: "boolean", Description: fkUsage},
59-
"embeddable": {Type: "boolean", Description: embeddableUsage},
60-
"publish_at": {Type: "string", Description: paUsage},
61-
"stabilize": {Type: "boolean", Description: stabilizeUsage},
62-
"notify_subscribers": {Type: "boolean", Description: nsUsage},
63-
"public_stats_viewable": {Type: "boolean", Description: psvUsage},
58+
"for_kids": {Type: "boolean", Description: fkUsage},
59+
"embeddable": {Type: "boolean", Description: embeddableUsage},
60+
"contains_synthetic_media": {Type: "boolean", Description: csmUsage},
61+
"recording_date": {Type: "string", Description: rdUsage},
62+
"publish_at": {Type: "string", Description: paUsage},
63+
"stabilize": {Type: "boolean", Description: stabilizeUsage},
64+
"notify_subscribers": {Type: "boolean", Description: nsUsage},
65+
"public_stats_viewable": {Type: "boolean", Description: psvUsage},
6466

6567
"on_behalf_of_content_owner": {
6668
Type: "string",
@@ -113,6 +115,10 @@ func init() {
113115
insertCmd.Flags().BoolVarP(
114116
embeddable, "embeddable", "E", true, embeddableUsage,
115117
)
118+
insertCmd.Flags().BoolVarP(
119+
containsSyntheticMedia, "containsSyntheticMedia", "M", false, csmUsage,
120+
)
121+
insertCmd.Flags().StringVarP(&recordingDate, "recordingDate", "D", "", rdUsage)
116122
insertCmd.Flags().StringVarP(&publishAt, "publishAt", "U", "", paUsage)
117123
insertCmd.Flags().BoolVarP(stabilize, "stabilize", "S", true, stabilizeUsage)
118124
insertCmd.Flags().BoolVarP(
@@ -156,6 +162,8 @@ var insertCmd = &cobra.Command{
156162
video.WithPrivacy(privacy),
157163
video.WithForKids(forKids),
158164
video.WithEmbeddable(embeddable),
165+
video.WithContainsSyntheticMedia(containsSyntheticMedia),
166+
video.WithRecordingDate(recordingDate),
159167
video.WithPublishAt(publishAt),
160168
video.WithStabilize(stabilize),
161169
video.WithNotifySubscribers(notifySubscribers),

cmd/video/update.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ var updateInSchema = &jsonschema.Schema{
5757
Type: "string", Description: privacyUsage,
5858
Enum: []any{"public", "private", "unlisted"},
5959
},
60-
"embeddable": {Type: "boolean", Description: embeddableUsage},
60+
"embeddable": {Type: "boolean", Description: embeddableUsage},
61+
"contains_synthetic_media": {Type: "boolean", Description: csmUsage},
62+
"recording_date": {Type: "string", Description: rdUsage},
6163
"output": {
6264
Type: "string", Enum: []any{"json", "yaml", "silent"},
6365
Description: pkg.SilentUsage, Default: json.RawMessage(`"yaml"`),
@@ -97,6 +99,10 @@ func init() {
9799
updateCmd.Flags().BoolVarP(
98100
embeddable, "embeddable", "E", true, embeddableUsage,
99101
)
102+
updateCmd.Flags().BoolVarP(
103+
containsSyntheticMedia, "containsSyntheticMedia", "M", false, csmUsage,
104+
)
105+
updateCmd.Flags().StringVarP(&recordingDate, "recordingDate", "D", "", rdUsage)
100106
updateCmd.Flags().StringVarP(&output, "output", "o", "", pkg.SilentUsage)
101107

102108
_ = updateCmd.MarkFlagRequired("id")
@@ -120,6 +126,8 @@ var updateCmd = &cobra.Command{
120126
video.WithCategory(categoryId),
121127
video.WithPrivacy(privacy),
122128
video.WithEmbeddable(embeddable),
129+
video.WithContainsSyntheticMedia(containsSyntheticMedia),
130+
video.WithRecordingDate(recordingDate),
123131
video.WithMaxResults(1),
124132
video.WithOutput(output),
125133
)

cmd/video/video.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ const (
3131
privacyUsage = "public|private|unlisted"
3232
fkUsage = "Whether the video is for kids"
3333
embeddableUsage = "Whether the video is embeddable"
34+
csmUsage = "Whether the video contains altered or synthetic media"
35+
rdUsage = "Date and time when the video was recorded"
3436
paUsage = "Datetime when the video is scheduled to publish"
3537
rcUsage = "Specific to the specified region"
3638
ridUsage = "ID of the reason for reporting abuse"
@@ -63,6 +65,7 @@ var (
6365
privacy string
6466
forKids = new(false)
6567
embeddable = new(false)
68+
recordingDate string
6669
publishAt string
6770
regionCode string
6871
reasonId string
@@ -76,6 +79,7 @@ var (
7679

7780
notifySubscribers = new(false)
7881
publicStatsViewable = new(false)
82+
containsSyntheticMedia = new(false)
7983
onBehalfOfContentOwner string
8084
onBehalfOfContentOwnerChannel string
8185
)
@@ -98,12 +102,13 @@ func init() {
98102

99103
func resetFlags(flagSet *pflag.FlagSet) {
100104
boolMap := map[string]**bool{
101-
"autoLevels": &autoLevels,
102-
"forKids": &forKids,
103-
"embeddable": &embeddable,
104-
"stabilize": &stabilize,
105-
"notifySubscribers": &notifySubscribers,
106-
"publicStatsViewable": &publicStatsViewable,
105+
"autoLevels": &autoLevels,
106+
"forKids": &forKids,
107+
"embeddable": &embeddable,
108+
"containsSyntheticMedia": &containsSyntheticMedia,
109+
"stabilize": &stabilize,
110+
"notifySubscribers": &notifySubscribers,
111+
"publicStatsViewable": &publicStatsViewable,
107112
}
108113

109114
utils.ResetBool(boolMap, flagSet)

pkg/video/video.go

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ type Video struct {
5656
MaxHeight int64 `yaml:"max_height" json:"max_height,omitempty"`
5757
MaxWidth int64 `yaml:"max_width" json:"max_width,omitempty"`
5858

59+
RecordingDate string `yaml:"recording_date" json:"recording_date,omitempty"`
60+
ContainsSyntheticMedia *bool `yaml:"contains_synthetic_media" json:"contains_synthetic_media,omitempty"`
5961
SecondaryReasonId string `yaml:"secondary_reason_id" json:"secondary_reason_id,omitempty"`
6062
NotifySubscribers *bool `yaml:"notify_subscribers" json:"notify_subscribers,omitempty"`
6163
PublicStatsViewable *bool `yaml:"public_stats_viewable" json:"public_stats_viewable,omitempty"`
@@ -186,7 +188,7 @@ func (v *Video) Insert(writer io.Writer) error {
186188
License: v.License,
187189
PublishAt: v.PublishAt,
188190
PrivacyStatus: v.Privacy,
189-
ForceSendFields: []string{"SelfDeclaredMadeForKids"},
191+
ForceSendFields: []string{"SelfDeclaredMadeForKids", "ContainsSyntheticMedia"},
190192
},
191193
}
192194

@@ -196,11 +198,22 @@ func (v *Video) Insert(writer io.Writer) error {
196198
if v.ForKids != nil {
197199
video.Status.SelfDeclaredMadeForKids = *v.ForKids
198200
}
201+
if v.ContainsSyntheticMedia != nil {
202+
video.Status.ContainsSyntheticMedia = *v.ContainsSyntheticMedia
203+
}
199204
if v.PublicStatsViewable != nil {
200205
video.Status.PublicStatsViewable = *v.PublicStatsViewable
201206
}
202207

203-
call := v.Service.Videos.Insert([]string{"snippet,status"}, video)
208+
insertParts := "snippet,status"
209+
if v.RecordingDate != "" {
210+
video.RecordingDetails = &youtube.VideoRecordingDetails{
211+
RecordingDate: v.RecordingDate,
212+
}
213+
insertParts += ",recordingDetails"
214+
}
215+
216+
call := v.Service.Videos.Insert([]string{insertParts}, video)
204217

205218
if v.AutoLevels != nil {
206219
call = call.AutoLevels(*v.AutoLevels)
@@ -291,6 +304,7 @@ func (v *Video) Update(writer io.Writer) error {
291304
video.Status.PublicStatsViewable = original.Status.PublicStatsViewable
292305
video.Status.PublishAt = original.Status.PublishAt
293306
video.Status.SelfDeclaredMadeForKids = original.Status.SelfDeclaredMadeForKids
307+
video.Status.ContainsSyntheticMedia = original.Status.ContainsSyntheticMedia
294308
}
295309

296310
if v.Title != "" {
@@ -320,8 +334,19 @@ func (v *Video) Update(writer io.Writer) error {
320334
if v.Embeddable != nil {
321335
video.Status.Embeddable = *v.Embeddable
322336
}
337+
if v.ContainsSyntheticMedia != nil {
338+
video.Status.ContainsSyntheticMedia = *v.ContainsSyntheticMedia
339+
}
323340

324-
call := v.Service.Videos.Update([]string{"snippet,status"}, video)
341+
updateParts := "snippet,status"
342+
if v.RecordingDate != "" {
343+
video.RecordingDetails = &youtube.VideoRecordingDetails{
344+
RecordingDate: v.RecordingDate,
345+
}
346+
updateParts += ",recordingDetails"
347+
}
348+
349+
call := v.Service.Videos.Update([]string{updateParts}, video)
325350
if v.OnBehalfOfContentOwner != "" {
326351
call = call.OnBehalfOfContentOwner(v.OnBehalfOfContentOwner)
327352
}
@@ -538,6 +563,14 @@ func WithEmbeddable(embeddable *bool) Option {
538563
}
539564
}
540565

566+
func WithContainsSyntheticMedia(containsSyntheticMedia *bool) Option {
567+
return func(v *Video) {
568+
if containsSyntheticMedia != nil {
569+
v.ContainsSyntheticMedia = containsSyntheticMedia
570+
}
571+
}
572+
}
573+
541574
func WithCategory(categoryId string) Option {
542575
return func(v *Video) {
543576
v.CategoryId = categoryId
@@ -570,6 +603,12 @@ func WithPublishAt(publishAt string) Option {
570603
}
571604
}
572605

606+
func WithRecordingDate(recordingDate string) Option {
607+
return func(v *Video) {
608+
v.RecordingDate = recordingDate
609+
}
610+
}
611+
573612
func WithRegionCode(regionCode string) Option {
574613
return func(v *Video) {
575614
v.RegionCode = regionCode

pkg/video/video_test.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ func TestNewVideo(t *testing.T) {
3131
forKidsFalse := false
3232
embeddableTrue := true
3333
embeddableFalse := false
34+
containsSyntheticMediaTrue := true
35+
containsSyntheticMediaFalse := false
3436
stabilizeTrue := true
3537
stabilizeFalse := false
3638
notifySubscribersTrue := true
@@ -68,6 +70,8 @@ func TestNewVideo(t *testing.T) {
6870
WithPrivacy("public"),
6971
WithForKids(&forKidsTrue),
7072
WithEmbeddable(&embeddableTrue),
73+
WithContainsSyntheticMedia(&containsSyntheticMediaTrue),
74+
WithRecordingDate("2024-06-15T10:00:00Z"),
7175
WithPublishAt("2024-12-31T23:59:59Z"),
7276
WithRegionCode("US"),
7377
WithReasonId("reason123"),
@@ -113,6 +117,8 @@ func TestNewVideo(t *testing.T) {
113117
Privacy: "public",
114118
ForKids: &forKidsTrue,
115119
Embeddable: &embeddableTrue,
120+
ContainsSyntheticMedia: &containsSyntheticMediaTrue,
121+
RecordingDate: "2024-06-15T10:00:00Z",
116122
PublishAt: "2024-12-31T23:59:59Z",
117123
RegionCode: "US",
118124
ReasonId: "reason123",
@@ -139,6 +145,7 @@ func TestNewVideo(t *testing.T) {
139145
WithAutoLevels(nil),
140146
WithForKids(nil),
141147
WithEmbeddable(nil),
148+
WithContainsSyntheticMedia(nil),
142149
WithStabilize(nil),
143150
WithNotifySubscribers(nil),
144151
WithPublicStatsViewable(nil),
@@ -153,19 +160,21 @@ func TestNewVideo(t *testing.T) {
153160
WithAutoLevels(&autoLevelsFalse),
154161
WithForKids(&forKidsFalse),
155162
WithEmbeddable(&embeddableFalse),
163+
WithContainsSyntheticMedia(&containsSyntheticMediaFalse),
156164
WithStabilize(&stabilizeFalse),
157165
WithNotifySubscribers(&notifySubscribersFalse),
158166
WithPublicStatsViewable(&publicStatsViewableFalse),
159167
},
160168
},
161169
want: &Video{
162-
Fields: &common.Fields{},
163-
AutoLevels: &autoLevelsFalse,
164-
ForKids: &forKidsFalse,
165-
Embeddable: &embeddableFalse,
166-
Stabilize: &stabilizeFalse,
167-
NotifySubscribers: &notifySubscribersFalse,
168-
PublicStatsViewable: &publicStatsViewableFalse,
170+
Fields: &common.Fields{},
171+
AutoLevels: &autoLevelsFalse,
172+
ForKids: &forKidsFalse,
173+
Embeddable: &embeddableFalse,
174+
ContainsSyntheticMedia: &containsSyntheticMediaFalse,
175+
Stabilize: &stabilizeFalse,
176+
NotifySubscribers: &notifySubscribersFalse,
177+
PublicStatsViewable: &publicStatsViewableFalse,
169178
},
170179
},
171180
{
@@ -209,6 +218,7 @@ func TestNewVideo(t *testing.T) {
209218
WithPlaylistId(""),
210219
WithCategory(""),
211220
WithPrivacy(""),
221+
WithRecordingDate(""),
212222
WithPublishAt(""),
213223
WithRegionCode(""),
214224
WithReasonId(""),
@@ -232,6 +242,7 @@ func TestNewVideo(t *testing.T) {
232242
PlaylistId: "",
233243
CategoryId: "",
234244
Privacy: "",
245+
RecordingDate: "",
235246
PublishAt: "",
236247
RegionCode: "",
237248
ReasonId: "",

0 commit comments

Comments
 (0)