Skip to content

Commit 511c973

Browse files
committed
🐛 Set MaxResults and skip readonly fields
resolve issue #181
1 parent 13d7445 commit 511c973

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

cmd/video/update.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func init() {
7777
},
7878
}, cobramcp.GenToolHandler(
7979
updateTool, func(input video.Video, writer io.Writer) error {
80+
input.MaxResults = 1
8081
return input.Update(writer)
8182
},
8283
),
@@ -119,6 +120,7 @@ var updateCmd = &cobra.Command{
119120
video.WithCategory(categoryId),
120121
video.WithPrivacy(privacy),
121122
video.WithEmbeddable(embeddable),
123+
video.WithMaxResults(1),
122124
video.WithOutput(output),
123125
)
124126
utils.HandleCmdError(input.Update(cmd.OutOrStdout()), cmd)

pkg/video/video.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,32 @@ func (v *Video) Update(writer io.Writer) error {
267267
return errGetVideo
268268
}
269269

270-
video := videos[0]
270+
original := videos[0]
271+
272+
// Build a new video with only writable fields to avoid sending
273+
// read-only fields (thumbnails, channelId, etc.) that cause
274+
// invalidVideoMetadata errors.
275+
video := &youtube.Video{
276+
Id: original.Id,
277+
Snippet: &youtube.VideoSnippet{},
278+
Status: &youtube.VideoStatus{},
279+
}
280+
if original.Snippet != nil {
281+
video.Snippet.Title = original.Snippet.Title
282+
video.Snippet.Description = original.Snippet.Description
283+
video.Snippet.Tags = original.Snippet.Tags
284+
video.Snippet.CategoryId = original.Snippet.CategoryId
285+
video.Snippet.DefaultLanguage = original.Snippet.DefaultLanguage
286+
}
287+
if original.Status != nil {
288+
video.Status.Embeddable = original.Status.Embeddable
289+
video.Status.License = original.Status.License
290+
video.Status.PrivacyStatus = original.Status.PrivacyStatus
291+
video.Status.PublicStatsViewable = original.Status.PublicStatsViewable
292+
video.Status.PublishAt = original.Status.PublishAt
293+
video.Status.SelfDeclaredMadeForKids = original.Status.SelfDeclaredMadeForKids
294+
}
295+
271296
if v.Title != "" {
272297
video.Snippet.Title = v.Title
273298
}
@@ -282,7 +307,6 @@ func (v *Video) Update(writer io.Writer) error {
282307
}
283308
if v.Language != "" {
284309
video.Snippet.DefaultLanguage = v.Language
285-
video.Snippet.DefaultAudioLanguage = v.Language
286310
}
287311
if v.License != "" {
288312
video.Status.License = v.License

0 commit comments

Comments
 (0)