diff --git a/cmd/activity/list.go b/cmd/activity/list.go index 22a8a23..6a5dd12 100644 --- a/cmd/activity/list.go +++ b/cmd/activity/list.go @@ -29,7 +29,7 @@ func init() { listCmd.Flags().StringVarP( &channelId, "channelId", "c", "", "ID of the channel", ) - listCmd.Flags().BoolVarP(&home, "home", "H", false, "true or false") + listCmd.Flags().BoolVarP(&home, "home", "H", true, "true or false") listCmd.Flags().Int64VarP( &maxResults, "maxResults", "x", 5, "Specifies the maximum number of items that should be returned", diff --git a/cmd/caption/delete.go b/cmd/caption/delete.go index 8dd74e5..62da4b3 100644 --- a/cmd/caption/delete.go +++ b/cmd/caption/delete.go @@ -11,7 +11,7 @@ var deleteCmd = &cobra.Command{ Long: "Delete caption of a video", Run: func(cmd *cobra.Command, args []string) { c := caption.NewCation( - caption.WithId(id), + caption.WithID(id), caption.WithOnBehalfOf(onBehalfOf), caption.WithOnBehalfOfContentOwner(onBehalfOfContentOwner), caption.WithService(nil), diff --git a/cmd/caption/download.go b/cmd/caption/download.go index a98d3be..ec73d72 100644 --- a/cmd/caption/download.go +++ b/cmd/caption/download.go @@ -11,7 +11,7 @@ var downloadCmd = &cobra.Command{ Long: "Download caption from a video", Run: func(cmd *cobra.Command, args []string) { c := caption.NewCation( - caption.WithId(id), + caption.WithID(id), caption.WithFile(file), caption.WithTfmt(tfmt), caption.WithTlang(tlang), diff --git a/cmd/caption/list.go b/cmd/caption/list.go index 71703e5..9843126 100644 --- a/cmd/caption/list.go +++ b/cmd/caption/list.go @@ -11,7 +11,7 @@ var listCmd = &cobra.Command{ Long: "List captions of a video", Run: func(cmd *cobra.Command, args []string) { c := caption.NewCation( - caption.WithId(id), + caption.WithID(id), caption.WithVideoId(videoId), caption.WithOnBehalfOf(onBehalfOf), caption.WithOnBehalfOfContentOwner(onBehalfOfContentOwner), diff --git a/cmd/channel/list.go b/cmd/channel/list.go index 9255f43..567c995 100644 --- a/cmd/channel/list.go +++ b/cmd/channel/list.go @@ -15,7 +15,7 @@ var listCmd = &cobra.Command{ channel.WithForHandle(forHandle), channel.WithForUsername(forUsername), channel.WithHl(hl), - channel.WithId(id), + channel.WithID(id), channel.WithChannelManagedByMe(managedByMe, true), channel.WithMaxResults(maxResults), channel.WithMine(mine, true), diff --git a/cmd/channel/update.go b/cmd/channel/update.go index 9fb5fe0..99386e7 100644 --- a/cmd/channel/update.go +++ b/cmd/channel/update.go @@ -11,7 +11,7 @@ var updateCmd = &cobra.Command{ Long: "Update channel's info, such as title, description, etc.", Run: func(cmd *cobra.Command, args []string) { c := channel.NewChannel( - channel.WithId(id), + channel.WithID(id), channel.WithCountry(country), channel.WithCustomUrl(customUrl), channel.WithDefaultLanguage(defaultLanguage), diff --git a/cmd/channelSection/delete.go b/cmd/channelSection/delete.go index bbe23b1..8ba3291 100644 --- a/cmd/channelSection/delete.go +++ b/cmd/channelSection/delete.go @@ -11,7 +11,7 @@ var deleteCmd = &cobra.Command{ Long: "Delete channel section", Run: func(cmd *cobra.Command, args []string) { cs := channelSection.NewChannelSection( - channelSection.WithId(id), + channelSection.WithID(id), channelSection.WithOnBehalfOfContentOwner(onBehalfOfContentOwner), channelSection.WithService(nil), ) diff --git a/cmd/channelSection/list.go b/cmd/channelSection/list.go index 1562119..e06212a 100644 --- a/cmd/channelSection/list.go +++ b/cmd/channelSection/list.go @@ -11,7 +11,7 @@ var listCmd = &cobra.Command{ Long: "List channel sections", Run: func(cmd *cobra.Command, args []string) { cs := channelSection.NewChannelSection( - channelSection.WithId(id), + channelSection.WithID(id), channelSection.WithChannelId(channelId), channelSection.WithHl(hl), channelSection.WithMine(mine, true), diff --git a/cmd/playlist/delete.go b/cmd/playlist/delete.go index 69a77f7..b9058a6 100644 --- a/cmd/playlist/delete.go +++ b/cmd/playlist/delete.go @@ -11,7 +11,7 @@ var deleteCmd = &cobra.Command{ Long: "Delete a playlist", Run: func(cmd *cobra.Command, args []string) { p := playlist.NewPlaylist( - playlist.WithId(id), + playlist.WithID(id), playlist.WithOnBehalfOfContentOwner(onBehalfOfContentOwner), playlist.WithService(nil), ) diff --git a/cmd/playlist/list.go b/cmd/playlist/list.go index be75a67..b7ef559 100644 --- a/cmd/playlist/list.go +++ b/cmd/playlist/list.go @@ -12,7 +12,7 @@ var listCmd = &cobra.Command{ Long: "List playlist's info, such as title, description, etc.", Run: func(cmd *cobra.Command, args []string) { p := playlist.NewPlaylist( - playlist.WithId(id), + playlist.WithID(id), playlist.WithChannelId(channelId), playlist.WithHl(hl), playlist.WithMaxResults(maxResults), diff --git a/cmd/playlist/update.go b/cmd/playlist/update.go index 8951bf9..c036a7a 100644 --- a/cmd/playlist/update.go +++ b/cmd/playlist/update.go @@ -11,7 +11,7 @@ var updateCmd = &cobra.Command{ Long: "Update an existing playlist, with the specified title, description, tags, etc.", Run: func(cmd *cobra.Command, args []string) { p := playlist.NewPlaylist( - playlist.WithId(id), + playlist.WithID(id), playlist.WithTitle(title), playlist.WithDescription(description), playlist.WithTags(tags), diff --git a/cmd/playlistItem/delete.go b/cmd/playlistItem/delete.go index e4553c1..49ca6de 100644 --- a/cmd/playlistItem/delete.go +++ b/cmd/playlistItem/delete.go @@ -11,7 +11,7 @@ var deleteCmd = &cobra.Command{ Long: "Delete a item from a playlist", Run: func(cmd *cobra.Command, args []string) { pi := playlistItem.NewPlaylistItem( - playlistItem.WithId(id), + playlistItem.WithID(id), playlistItem.WithOnBehalfOfContentOwner(onBehalfOfContentOwner), playlistItem.WithService(nil), ) diff --git a/cmd/playlistItem/list.go b/cmd/playlistItem/list.go index 5ad5cbf..6ede932 100644 --- a/cmd/playlistItem/list.go +++ b/cmd/playlistItem/list.go @@ -11,7 +11,7 @@ var listCmd = &cobra.Command{ Long: "List playlist items' info, such as title, description, etc.", Run: func(cmd *cobra.Command, args []string) { pi := playlistItem.NewPlaylistItem( - playlistItem.WithId(id), + playlistItem.WithID(id), playlistItem.WithPlaylistId(playlistId), playlistItem.WithMaxResults(maxResults), playlistItem.WithVideoId(videoId), diff --git a/cmd/playlistItem/update.go b/cmd/playlistItem/update.go index 8753ccc..6a7c9c6 100644 --- a/cmd/playlistItem/update.go +++ b/cmd/playlistItem/update.go @@ -11,7 +11,7 @@ var updateCmd = &cobra.Command{ Long: "Update playlist item's info, such as title, description, etc.", Run: func(cmd *cobra.Command, args []string) { pi := playlistItem.NewPlaylistItem( - playlistItem.WithId(id), + playlistItem.WithID(id), playlistItem.WithTitle(title), playlistItem.WithDescription(description), playlistItem.WithPrivacy(privacy), diff --git a/cmd/subscription/delete.go b/cmd/subscription/delete.go index 8aa2e26..a8ea81d 100644 --- a/cmd/subscription/delete.go +++ b/cmd/subscription/delete.go @@ -11,7 +11,7 @@ var deleteCmd = &cobra.Command{ Long: "Delete subscription", Run: func(cmd *cobra.Command, args []string) { s := subscription.NewSubscription( - subscription.WithId(id), subscription.WithService(nil), + subscription.WithID(id), subscription.WithService(nil), ) s.Delete() }, diff --git a/cmd/subscription/list.go b/cmd/subscription/list.go index 467b7ea..7209e96 100644 --- a/cmd/subscription/list.go +++ b/cmd/subscription/list.go @@ -11,7 +11,7 @@ var listCmd = &cobra.Command{ Long: "List subscriptions' info, such as id, title, etc.", Run: func(cmd *cobra.Command, args []string) { s := subscription.NewSubscription( - subscription.WithId(id), + subscription.WithID(id), subscription.WithChannelId(channelId), subscription.WithForChannelId(forChannelId), subscription.WithMaxResults(maxResults), diff --git a/cmd/video/delete.go b/cmd/video/delete.go index 1980480..7b7f672 100644 --- a/cmd/video/delete.go +++ b/cmd/video/delete.go @@ -10,7 +10,7 @@ var deleteCmd = &cobra.Command{ Short: "Delete a video on Youtube", Long: "Delete a video on Youtube", Run: func(cmd *cobra.Command, args []string) { - v := video.NewVideo(video.WithId(id)) + v := video.NewVideo(video.WithID(id)) v.Delete() }, } diff --git a/cmd/video/getRating.go b/cmd/video/getRating.go index 86f430e..f126ed9 100644 --- a/cmd/video/getRating.go +++ b/cmd/video/getRating.go @@ -12,7 +12,7 @@ var getRatingCmd = &cobra.Command{ Long: "Get the rating of a video, with the specified video ID", Run: func(cmd *cobra.Command, args []string) { v := video.NewVideo( - video.WithId(id), + video.WithID(id), video.WithOnBehalfOfContentOwner(onBehalfOfContentOwner), video.WithService(nil), ) diff --git a/cmd/video/list.go b/cmd/video/list.go index c686c98..2c38f10 100644 --- a/cmd/video/list.go +++ b/cmd/video/list.go @@ -12,7 +12,7 @@ var listCmd = &cobra.Command{ Long: "List video's info, such as title, description, etc.", Run: func(cmd *cobra.Command, args []string) { v := video.NewVideo( - video.WithId(id), + video.WithID(id), video.WithChart(chart), video.WithHl(hl), video.WithLocale(locale), diff --git a/cmd/video/rate.go b/cmd/video/rate.go index 81be106..47231e9 100644 --- a/cmd/video/rate.go +++ b/cmd/video/rate.go @@ -12,7 +12,7 @@ var rateCmd = &cobra.Command{ Long: "Rate a video on YouTube, with the specified rating", Run: func(cmd *cobra.Command, args []string) { v := video.NewVideo( - video.WithId(id), + video.WithID(id), video.WithRating(rating), video.WithService(nil), ) diff --git a/cmd/video/update.go b/cmd/video/update.go index 173b69a..5ec840c 100644 --- a/cmd/video/update.go +++ b/cmd/video/update.go @@ -11,7 +11,7 @@ var updateCmd = &cobra.Command{ Long: "Update a video on YouTube, with the specified title, description, tags, etc.", Run: func(cmd *cobra.Command, args []string) { v := video.NewVideo( - video.WithId(id), + video.WithID(id), video.WithTitle(title), video.WithDescription(description), video.WithTags(tags), diff --git a/cmd/videoCategory/list.go b/cmd/videoCategory/list.go index 9cba0d0..4a849a7 100644 --- a/cmd/videoCategory/list.go +++ b/cmd/videoCategory/list.go @@ -11,7 +11,7 @@ var listCmd = &cobra.Command{ Long: "List video categories' info, such as ID, title, assignable, etc.", Run: func(cmd *cobra.Command, args []string) { vc := videoCategory.NewVideoCategory( - videoCategory.WithId(id), + videoCategory.WithID(id), videoCategory.WithHl(hl), videoCategory.WithRegionCode(regionCode), videoCategory.WithService(nil), diff --git a/pkg/yutuber/activity/activity.go b/pkg/yutuber/activity/activity.go index 254f0ac..71c1d33 100644 --- a/pkg/yutuber/activity/activity.go +++ b/pkg/yutuber/activity/activity.go @@ -16,13 +16,13 @@ var ( ) type activity struct { - channelId string - home *bool - maxResults int64 - mine *bool - publishedAfter string - publishedBefore string - regionCode string + ChannelId string `yaml:"channel_id" json:"channel_id"` + Home *bool `yaml:"home" json:"home"` + MaxResults int64 `yaml:"max_results" json:"max_results"` + Mine *bool `yaml:"mine" json:"mine"` + PublishedAfter string `yaml:"published_after" json:"published_after"` + PublishedBefore string `yaml:"published_before" json:"published_before"` + RegionCode string `yaml:"region_code" json:"region_code"` } type Activity interface { @@ -44,34 +44,35 @@ func NewActivity(opts ...Option) Activity { func (a *activity) get(parts []string) []*youtube.Activity { call := service.Activities.List(parts) - if a.channelId != "" { - call = call.ChannelId(a.channelId) + if a.ChannelId != "" { + call = call.ChannelId(a.ChannelId) } - if a.home != nil { - call = call.Home(*a.home) + if a.Home != nil { + call = call.Home(*a.Home) } - if a.mine != nil { - call = call.Mine(*a.mine) + if a.Mine != nil { + call = call.Mine(*a.Mine) } - call.MaxResults(a.maxResults) + call.MaxResults(a.MaxResults) - if a.publishedAfter != "" { - call.PublishedAfter(a.publishedAfter) + if a.PublishedAfter != "" { + call.PublishedAfter(a.PublishedAfter) } - if a.publishedBefore != "" { - call.PublishedBefore(a.publishedBefore) + if a.PublishedBefore != "" { + call.PublishedBefore(a.PublishedBefore) } - if a.regionCode != "" { - call.RegionCode(a.regionCode) + if a.RegionCode != "" { + call.RegionCode(a.RegionCode) } res, err := call.Do() if err != nil { + utils.PrintJSON(a) log.Fatalln(errors.Join(errGetActivity, err)) } @@ -95,47 +96,47 @@ func (a *activity) List(parts []string, output string) { func WithChannelId(channelId string) Option { return func(a *activity) { - a.channelId = channelId + a.ChannelId = channelId } } func WithHome(home bool, changed bool) Option { return func(a *activity) { if changed { - a.home = &home + a.Home = &home } } } func WithMaxResults(maxResults int64) Option { return func(a *activity) { - a.maxResults = maxResults + a.MaxResults = maxResults } } func WithMine(mine bool, changed bool) Option { return func(a *activity) { if changed { - a.mine = &mine + a.Mine = &mine } } } func WithPublishedAfter(publishedAfter string) Option { return func(a *activity) { - a.publishedAfter = publishedAfter + a.PublishedAfter = publishedAfter } } func WithPublishedBefore(publishedBefore string) Option { return func(a *activity) { - a.publishedBefore = publishedBefore + a.PublishedBefore = publishedBefore } } func WithRegionCode(regionCode string) Option { return func(a *activity) { - a.regionCode = regionCode + a.RegionCode = regionCode } } diff --git a/pkg/yutuber/activity/activity_test.go b/pkg/yutuber/activity/activity_test.go index c9cae40..9e3a74a 100644 --- a/pkg/yutuber/activity/activity_test.go +++ b/pkg/yutuber/activity/activity_test.go @@ -18,7 +18,7 @@ func TestNewActivity(t *testing.T) { name: "TestNewActivity", args: args{ opts: []Option{ - WithChannelId("channelId"), + WithChannelId("ChannelId"), WithHome(true, true), WithMaxResults(10), WithMine(true, true), @@ -28,13 +28,13 @@ func TestNewActivity(t *testing.T) { }, }, want: &activity{ - channelId: "channelId", - home: &[]bool{true}[0], - maxResults: 10, - mine: &[]bool{true}[0], - publishedAfter: "2021-01-01T00:00:00Z", - publishedBefore: "2021-01-31T00:00:00Z", - regionCode: "US", + ChannelId: "ChannelId", + Home: &[]bool{true}[0], + MaxResults: 10, + Mine: &[]bool{true}[0], + PublishedAfter: "2021-01-01T00:00:00Z", + PublishedBefore: "2021-01-31T00:00:00Z", + RegionCode: "US", }, }, { @@ -45,7 +45,7 @@ func TestNewActivity(t *testing.T) { }, }, want: &activity{ - home: &[]bool{false}[0], + Home: &[]bool{false}[0], }, }, { @@ -56,7 +56,7 @@ func TestNewActivity(t *testing.T) { }, }, want: &activity{ - maxResults: 5, + MaxResults: 5, }, }, } diff --git a/pkg/yutuber/caption/caption.go b/pkg/yutuber/caption/caption.go index 9855b60..f55698b 100644 --- a/pkg/yutuber/caption/caption.go +++ b/pkg/yutuber/caption/caption.go @@ -21,22 +21,22 @@ var ( ) type caption struct { - id string - file string - audioTrackType string - isAutoSynced *bool - isCC *bool - isDraft *bool - isEasyReader *bool - isLarge *bool - language string - name string - trackKind string - onBehalfOf string - onBehalfOfContentOwner string - videoId string - tfmt string - tlang string + ID string `yaml:"id" json:"id"` + File string `yaml:"file" json:"file"` + AudioTrackType string `yaml:"audio_track_type" json:"audio_track_type"` + IsAutoSynced *bool `yaml:"is_auto_synced" json:"is_auto_synced"` + IsCC *bool `yaml:"is_cc" json:"is_cc"` + IsDraft *bool `yaml:"is_draft" json:"is_draft"` + IsEasyReader *bool `yaml:"is_easy_reader" json:"is_easy_reader"` + IsLarge *bool `yaml:"is_large" json:"is_large"` + Language string `yaml:"language" json:"language"` + Name string `yaml:"name" json:"name"` + TrackKind string `yaml:"track_kind" json:"track_kind"` + OnBehalfOf string `yaml:"on_behalf_of" json:"on_behalf_of"` + OnBehalfOfContentOwner string `yaml:"on_behalf_of_content_owner" json:"on_behalf_of_content_owner"` + VideoId string `yaml:"video_id" json:"video_id"` + Tfmt string `yaml:"tfmt" json:"tfmt"` + Tlang string `yaml:"tlang" json:"tlang"` } type Caption interface { @@ -59,19 +59,20 @@ func NewCation(opts ...Option) Caption { } func (c *caption) get(parts []string) []*youtube.Caption { - call := service.Captions.List(parts, c.videoId) - if c.id != "" { - call = call.Id(c.id) + call := service.Captions.List(parts, c.VideoId) + if c.ID != "" { + call = call.Id(c.ID) } - if c.onBehalfOf != "" { - call = call.OnBehalfOf(c.onBehalfOf) + if c.OnBehalfOf != "" { + call = call.OnBehalfOf(c.OnBehalfOf) } - if c.onBehalfOfContentOwner != "" { - call = call.OnBehalfOfContentOwner(c.onBehalfOfContentOwner) + if c.OnBehalfOfContentOwner != "" { + call = call.OnBehalfOfContentOwner(c.OnBehalfOfContentOwner) } res, err := call.Do() if err != nil { + utils.PrintJSON(c) log.Fatalln(errors.Join(errGetCaption, err)) } @@ -94,37 +95,39 @@ func (c *caption) List(parts []string, output string) { } func (c *caption) Insert() { - file, err := os.Open(c.file) + file, err := os.Open(c.File) if err != nil { + utils.PrintJSON(c) log.Fatalln(errors.Join(errInsertCaption, err)) } defer file.Close() caption := &youtube.Caption{ Snippet: &youtube.CaptionSnippet{ - AudioTrackType: c.audioTrackType, - IsAutoSynced: *c.isAutoSynced, - IsCC: *c.isCC, - IsDraft: *c.isDraft, - IsEasyReader: *c.isEasyReader, - IsLarge: *c.isLarge, - Language: c.language, - Name: c.name, - TrackKind: c.trackKind, - VideoId: c.videoId, + AudioTrackType: c.AudioTrackType, + IsAutoSynced: *c.IsAutoSynced, + IsCC: *c.IsCC, + IsDraft: *c.IsDraft, + IsEasyReader: *c.IsEasyReader, + IsLarge: *c.IsLarge, + Language: c.Language, + Name: c.Name, + TrackKind: c.TrackKind, + VideoId: c.VideoId, }, } call := service.Captions.Insert([]string{"snippet"}, caption).Media(file) - if c.onBehalfOf != "" { - call = call.OnBehalfOf(c.onBehalfOf) + if c.OnBehalfOf != "" { + call = call.OnBehalfOf(c.OnBehalfOf) } - if c.onBehalfOfContentOwner != "" { - call = call.OnBehalfOfContentOwner(c.onBehalfOfContentOwner) + if c.OnBehalfOfContentOwner != "" { + call = call.OnBehalfOfContentOwner(c.OnBehalfOfContentOwner) } res, err := call.Do() if err != nil { + utils.PrintJSON(c) log.Fatalln(errors.Join(errInsertCaption, err)) } fmt.Printf("Caption %s inserted\n", res.Id) @@ -132,55 +135,57 @@ func (c *caption) Insert() { func (c *caption) Update() { caption := c.get([]string{"snippet"})[0] - if c.audioTrackType != "" { - caption.Snippet.AudioTrackType = c.audioTrackType + if c.AudioTrackType != "" { + caption.Snippet.AudioTrackType = c.AudioTrackType } - if c.isAutoSynced != nil { - caption.Snippet.IsAutoSynced = *c.isAutoSynced + if c.IsAutoSynced != nil { + caption.Snippet.IsAutoSynced = *c.IsAutoSynced } - if c.isCC != nil { - caption.Snippet.IsCC = *c.isCC + if c.IsCC != nil { + caption.Snippet.IsCC = *c.IsCC } - if c.isDraft != nil { - caption.Snippet.IsDraft = *c.isDraft + if c.IsDraft != nil { + caption.Snippet.IsDraft = *c.IsDraft } - if c.isEasyReader != nil { - caption.Snippet.IsEasyReader = *c.isEasyReader + if c.IsEasyReader != nil { + caption.Snippet.IsEasyReader = *c.IsEasyReader } - if c.isLarge != nil { - caption.Snippet.IsLarge = *c.isLarge + if c.IsLarge != nil { + caption.Snippet.IsLarge = *c.IsLarge } - if c.language != "" { - caption.Snippet.Language = c.language + if c.Language != "" { + caption.Snippet.Language = c.Language } - if c.name != "" { - caption.Snippet.Name = c.name + if c.Name != "" { + caption.Snippet.Name = c.Name } - if c.trackKind != "" { - caption.Snippet.TrackKind = c.trackKind + if c.TrackKind != "" { + caption.Snippet.TrackKind = c.TrackKind } - if c.videoId != "" { - caption.Snippet.VideoId = c.videoId + if c.VideoId != "" { + caption.Snippet.VideoId = c.VideoId } call := service.Captions.Update([]string{"snippet"}, caption) - if c.file != "" { - file, err := os.Open(c.file) + if c.File != "" { + file, err := os.Open(c.File) if err != nil { + utils.PrintJSON(c) log.Fatalln(errors.Join(errUpdateCaption, err)) } defer file.Close() call = call.Media(file) } - if c.onBehalfOf != "" { - call = call.OnBehalfOf(c.onBehalfOf) + if c.OnBehalfOf != "" { + call = call.OnBehalfOf(c.OnBehalfOf) } - if c.onBehalfOfContentOwner != "" { - call = call.OnBehalfOfContentOwner(c.onBehalfOfContentOwner) + if c.OnBehalfOfContentOwner != "" { + call = call.OnBehalfOfContentOwner(c.OnBehalfOfContentOwner) } res, err := call.Do() if err != nil { + utils.PrintJSON(c) log.Fatalln(errors.Join(errUpdateCaption, err)) } @@ -188,80 +193,85 @@ func (c *caption) Update() { } func (c *caption) Delete() { - call := service.Captions.Delete(c.id) - if c.onBehalfOf != "" { - call = call.OnBehalfOf(c.onBehalfOf) + call := service.Captions.Delete(c.ID) + if c.OnBehalfOf != "" { + call = call.OnBehalfOf(c.OnBehalfOf) } - if c.onBehalfOfContentOwner != "" { - call = call.OnBehalfOfContentOwner(c.onBehalfOfContentOwner) + if c.OnBehalfOfContentOwner != "" { + call = call.OnBehalfOfContentOwner(c.OnBehalfOfContentOwner) } err := call.Do() if err != nil { + utils.PrintJSON(c) log.Fatalln(errors.Join(errDeleteCaption, err)) } - fmt.Printf("Caption %s deleted\n", c.id) + fmt.Printf("Caption %s deleted\n", c.ID) } func (c *caption) Download() { - call := service.Captions.Download(c.id) - if c.tfmt != "" { - call = call.Tfmt(c.tfmt) + call := service.Captions.Download(c.ID) + if c.Tfmt != "" { + call = call.Tfmt(c.Tfmt) } - if c.tlang != "" { - call = call.Tlang(c.tlang) + if c.Tlang != "" { + call = call.Tlang(c.Tlang) } - if c.onBehalfOf != "" { - call = call.OnBehalfOf(c.onBehalfOf) + if c.OnBehalfOf != "" { + call = call.OnBehalfOf(c.OnBehalfOf) } - if c.onBehalfOfContentOwner != "" { - call = call.OnBehalfOfContentOwner(c.onBehalfOfContentOwner) + if c.OnBehalfOfContentOwner != "" { + call = call.OnBehalfOfContentOwner(c.OnBehalfOfContentOwner) } res, err := call.Download() if err != nil { + utils.PrintJSON(c) log.Fatalln(errors.Join(errDownloadCaption, err)) } defer res.Body.Close() body, err := io.ReadAll(res.Body) if err != nil { + utils.PrintJSON(c) log.Fatalln(errors.Join(errDownloadCaption, err)) } - file, err := os.Create(c.file) + file, err := os.Create(c.File) if err != nil { + utils.PrintJSON(c) log.Fatalln(errors.Join(errDownloadCaption, err)) } defer file.Close() _, err = file.Write(body) if err != nil { + utils.PrintJSON(c) log.Fatalln(errors.Join(errDownloadCaption, err)) } } -func WithId(id string) Option { +func WithID(id string) Option { return func(c *caption) { - c.id = id + c.ID = id } } func WithFile(file string) Option { return func(c *caption) { - c.file = file + c.File = file } } func WithAudioTrackType(audioTrackType string) Option { return func(c *caption) { - c.audioTrackType = audioTrackType + c.AudioTrackType = audioTrackType } } func WithIsAutoSynced(isAutoSynced bool, changed bool) Option { return func(c *caption) { if changed { - c.isAutoSynced = &isAutoSynced + c.IsAutoSynced = &isAutoSynced } } } @@ -269,7 +279,7 @@ func WithIsAutoSynced(isAutoSynced bool, changed bool) Option { func WithIsCC(isCC bool, changed bool) Option { return func(c *caption) { if changed { - c.isCC = &isCC + c.IsCC = &isCC } } } @@ -277,7 +287,7 @@ func WithIsCC(isCC bool, changed bool) Option { func WithIsDraft(isDraft bool, changed bool) Option { return func(c *caption) { if changed { - c.isDraft = &isDraft + c.IsDraft = &isDraft } } } @@ -285,7 +295,7 @@ func WithIsDraft(isDraft bool, changed bool) Option { func WithIsEasyReader(isEasyReader bool, changed bool) Option { return func(c *caption) { if changed { - c.isEasyReader = &isEasyReader + c.IsEasyReader = &isEasyReader } } } @@ -293,56 +303,56 @@ func WithIsEasyReader(isEasyReader bool, changed bool) Option { func WithIsLarge(isLarge bool, changed bool) Option { return func(c *caption) { if changed { - c.isLarge = &isLarge + c.IsLarge = &isLarge } } } func WithLanguage(language string) Option { return func(c *caption) { - c.language = language + c.Language = language } } func WithName(name string) Option { return func(c *caption) { - c.name = name + c.Name = name } } func WithTrackKind(trackKind string) Option { return func(c *caption) { - c.trackKind = trackKind + c.TrackKind = trackKind } } func WithOnBehalfOf(onBehalfOf string) Option { return func(c *caption) { - c.onBehalfOf = onBehalfOf + c.OnBehalfOf = onBehalfOf } } func WithOnBehalfOfContentOwner(onBehalfOfContentOwner string) Option { return func(c *caption) { - c.onBehalfOfContentOwner = onBehalfOfContentOwner + c.OnBehalfOfContentOwner = onBehalfOfContentOwner } } func WithVideoId(videoId string) Option { return func(c *caption) { - c.videoId = videoId + c.VideoId = videoId } } func WithTfmt(tfmt string) Option { return func(c *caption) { - c.tfmt = tfmt + c.Tfmt = tfmt } } func WithTlang(tlang string) Option { return func(c *caption) { - c.tlang = tlang + c.Tlang = tlang } } diff --git a/pkg/yutuber/caption/caption_test.go b/pkg/yutuber/caption/caption_test.go index 5e6b7a8..1c2e331 100644 --- a/pkg/yutuber/caption/caption_test.go +++ b/pkg/yutuber/caption/caption_test.go @@ -18,29 +18,29 @@ func TestNewCation(t *testing.T) { name: "TestNewCaption", args: args{ opts: []Option{ - WithId("id"), - WithFile("file"), - WithAudioTrackType("audioTrackType"), + WithID("ID"), + WithFile("File"), + WithAudioTrackType("AudioTrackType"), WithIsAutoSynced(true, true), WithIsCC(true, true), WithIsDraft(true, true), WithIsEasyReader(true, true), WithIsLarge(true, true), - WithLanguage("language"), - WithName("name"), + WithLanguage("Language"), + WithName("Name"), }, }, want: &caption{ - id: "id", - file: "file", - audioTrackType: "audioTrackType", - isAutoSynced: &[]bool{true}[0], - isCC: &[]bool{true}[0], - isDraft: &[]bool{true}[0], - isEasyReader: &[]bool{true}[0], - isLarge: &[]bool{true}[0], - language: "language", - name: "name", + ID: "ID", + File: "File", + AudioTrackType: "AudioTrackType", + IsAutoSynced: &[]bool{true}[0], + IsCC: &[]bool{true}[0], + IsDraft: &[]bool{true}[0], + IsEasyReader: &[]bool{true}[0], + IsLarge: &[]bool{true}[0], + Language: "Language", + Name: "Name", }, }, } diff --git a/pkg/yutuber/channel/channel.go b/pkg/yutuber/channel/channel.go index dbfdf0b..e6b09c1 100644 --- a/pkg/yutuber/channel/channel.go +++ b/pkg/yutuber/channel/channel.go @@ -18,22 +18,22 @@ var ( ) type channel struct { - categoryId string - forHandle string - forUsername string - hl string - id string - managedByMe *bool - maxResults int64 - mine *bool - mySubscribers *bool - onBehalfOfContentOwner string + CategoryId string `yaml:"category_id" json:"category_id"` + ForHandle string `yaml:"for_handle" json:"for_handle"` + ForUsername string `yaml:"for_username" json:"for_username"` + Hl string `yaml:"hl" json:"hl"` + ID string `yaml:"id" json:"id"` + ManagedByMe *bool `yaml:"managed_by_me" json:"managed_by_me"` + MaxResults int64 `yaml:"max_results" json:"max_results"` + Mine *bool `yaml:"mine" json:"mine"` + MySubscribers *bool `yaml:"my_subscribers" json:"my_subscribers"` + OnBehalfOfContentOwner string `yaml:"on_behalf_of_content_owner" json:"on_behalf_of_content_owner"` - country string - customUrl string - defaultLanguage string - description string - title string + Country string `yaml:"country" json:"country"` + CustomUrl string `yaml:"custom_url" json:"custom_url"` + DefaultLanguage string `yaml:"default_language" json:"default_language"` + Description string `yaml:"description" json:"description"` + Title string `yaml:"title" json:"title"` } type Channel interface { @@ -56,47 +56,48 @@ func NewChannel(opts ...Option) Channel { func (c *channel) get(parts []string) []*youtube.Channel { call := service.Channels.List(parts) - if c.categoryId != "" { - call = call.CategoryId(c.categoryId) + if c.CategoryId != "" { + call = call.CategoryId(c.CategoryId) } - if c.forHandle != "" { - call = call.ForUsername(c.forHandle) + if c.ForHandle != "" { + call = call.ForUsername(c.ForHandle) } - if c.forUsername != "" { - call = call.ForUsername(c.forUsername) + if c.ForUsername != "" { + call = call.ForUsername(c.ForUsername) } - if c.hl != "" { - call = call.Hl(c.hl) + if c.Hl != "" { + call = call.Hl(c.Hl) } - if c.id != "" { - call = call.Id(c.id) + if c.ID != "" { + call = call.Id(c.ID) } - if c.managedByMe != nil { - call = call.ManagedByMe(*c.managedByMe) + if c.ManagedByMe != nil { + call = call.ManagedByMe(*c.ManagedByMe) } - call = call.MaxResults(c.maxResults) + call = call.MaxResults(c.MaxResults) - if c.mine != nil { - call = call.Mine(*c.mine) + if c.Mine != nil { + call = call.Mine(*c.Mine) } - if c.mySubscribers != nil { - call = call.MySubscribers(*c.mySubscribers) + if c.MySubscribers != nil { + call = call.MySubscribers(*c.MySubscribers) } - if c.onBehalfOfContentOwner != "" { - call = call.OnBehalfOfContentOwner(c.onBehalfOfContentOwner) + if c.OnBehalfOfContentOwner != "" { + call = call.OnBehalfOfContentOwner(c.OnBehalfOfContentOwner) } res, err := call.Do() if err != nil { - log.Fatalln(errors.Join(errGetChannel, err), c.id) + utils.PrintJSON(c) + log.Fatalln(errors.Join(errGetChannel, err), c.ID) } return res.Items @@ -120,17 +121,18 @@ func (c *channel) List(parts []string, output string) { func (c *channel) Update() { parts := []string{"snippet"} channel := c.get(parts)[0] - if c.title != "" { - channel.Snippet.Title = c.title + if c.Title != "" { + channel.Snippet.Title = c.Title } - if c.description != "" { - channel.Snippet.Description = c.description + if c.Description != "" { + channel.Snippet.Description = c.Description } call := service.Channels.Update(parts, channel) res, err := call.Do() if err != nil { - log.Fatalln(errors.Join(errUpdateChannel, err), c.id) + utils.PrintJSON(c) + log.Fatalln(errors.Join(errUpdateChannel, err), c.ID) } fmt.Println("Channel updated:") utils.PrintYAML(res) @@ -138,52 +140,52 @@ func (c *channel) Update() { func WithCategoryId(categoryId string) Option { return func(c *channel) { - c.categoryId = categoryId + c.CategoryId = categoryId } } func WithForHandle(handle string) Option { return func(c *channel) { - c.forHandle = handle + c.ForHandle = handle } } func WithForUsername(username string) Option { return func(c *channel) { - c.forUsername = username + c.ForUsername = username } } func WithHl(hl string) Option { return func(c *channel) { - c.hl = hl + c.Hl = hl } } -func WithId(id string) Option { +func WithID(id string) Option { return func(c *channel) { - c.id = id + c.ID = id } } func WithChannelManagedByMe(managedByMe bool, changed bool) Option { return func(c *channel) { if changed { - c.managedByMe = &managedByMe + c.ManagedByMe = &managedByMe } } } func WithMaxResults(maxResults int64) Option { return func(c *channel) { - c.maxResults = maxResults + c.MaxResults = maxResults } } func WithMine(mine bool, changed bool) Option { return func(c *channel) { if changed { - c.mine = &mine + c.Mine = &mine } } } @@ -191,44 +193,44 @@ func WithMine(mine bool, changed bool) Option { func WithMySubscribers(mySubscribers bool, changed bool) Option { return func(c *channel) { if changed { - c.mySubscribers = &mySubscribers + c.MySubscribers = &mySubscribers } } } func WithOnBehalfOfContentOwner(contentOwner string) Option { return func(c *channel) { - c.onBehalfOfContentOwner = contentOwner + c.OnBehalfOfContentOwner = contentOwner } } func WithCountry(country string) Option { return func(c *channel) { - c.country = country + c.Country = country } } func WithCustomUrl(url string) Option { return func(c *channel) { - c.customUrl = url + c.CustomUrl = url } } func WithDefaultLanguage(language string) Option { return func(c *channel) { - c.defaultLanguage = language + c.DefaultLanguage = language } } func WithDescription(desc string) Option { return func(c *channel) { - c.description = desc + c.Description = desc } } func WithTitle(title string) Option { return func(c *channel) { - c.title = title + c.Title = title } } diff --git a/pkg/yutuber/channel/channel_test.go b/pkg/yutuber/channel/channel_test.go index 5ed5670..86ac75b 100644 --- a/pkg/yutuber/channel/channel_test.go +++ b/pkg/yutuber/channel/channel_test.go @@ -22,7 +22,7 @@ func TestNewChannel(t *testing.T) { WithForHandle("handle"), WithForUsername("username"), WithHl("hl"), - WithId("id"), + WithID("id"), WithChannelManagedByMe(true, true), WithMaxResults(5), WithMine(false, true), @@ -31,16 +31,16 @@ func TestNewChannel(t *testing.T) { }, }, want: &channel{ - categoryId: "15", - forHandle: "handle", - forUsername: "username", - hl: "hl", - id: "id", - managedByMe: &[]bool{true}[0], - maxResults: 5, - mine: &[]bool{false}[0], - mySubscribers: &[]bool{true}[0], - onBehalfOfContentOwner: "contentOwner", + CategoryId: "15", + ForHandle: "handle", + ForUsername: "username", + Hl: "hl", + ID: "id", + ManagedByMe: &[]bool{true}[0], + MaxResults: 5, + Mine: &[]bool{false}[0], + MySubscribers: &[]bool{true}[0], + OnBehalfOfContentOwner: "contentOwner", }, }, { @@ -57,13 +57,13 @@ func TestNewChannel(t *testing.T) { }, }, want: &channel{ - categoryId: "20", - forHandle: "handle", - country: "US", - customUrl: "customUrl", - defaultLanguage: "en", - description: "description", - title: "title", + CategoryId: "20", + ForHandle: "handle", + Country: "US", + CustomUrl: "customUrl", + DefaultLanguage: "en", + Description: "description", + Title: "title", }, }, } diff --git a/pkg/yutuber/channelBanner/channelBanner.go b/pkg/yutuber/channelBanner/channelBanner.go index ec0ed61..7cde59f 100644 --- a/pkg/yutuber/channelBanner/channelBanner.go +++ b/pkg/yutuber/channelBanner/channelBanner.go @@ -16,10 +16,10 @@ var ( ) type channelBanner struct { - file string + File string `yaml:"file" json:"file"` - onBehalfOfContentOwner string - onBehalfOfContentOwnerChannel string + OnBehalfOfContentOwner string `yaml:"on_behalf_of_content_owner" json:"on_behalf_of_content_owner"` + OnBehalfOfContentOwnerChannel string `yaml:"on_behalf_of_content_owner_channel" json:"on_behalf_of_content_owner_channel"` } type ChannelBanner interface { @@ -39,23 +39,25 @@ func NewChannelBanner(opts ...Option) ChannelBanner { } func (cb *channelBanner) Insert() { - file, err := os.Open(cb.file) + file, err := os.Open(cb.File) if err != nil { - log.Fatalln(errors.Join(errInsertChannelBanner, err), cb.file) + utils.PrintJSON(cb) + log.Fatalln(errors.Join(errInsertChannelBanner, err), cb.File) } defer file.Close() cbr := &youtube.ChannelBannerResource{} call := service.ChannelBanners.Insert(cbr).Media(file) - if cb.onBehalfOfContentOwner != "" { - call = call.OnBehalfOfContentOwner(cb.onBehalfOfContentOwner) + if cb.OnBehalfOfContentOwner != "" { + call = call.OnBehalfOfContentOwner(cb.OnBehalfOfContentOwner) } - if cb.onBehalfOfContentOwnerChannel != "" { - call = call.OnBehalfOfContentOwnerChannel(cb.onBehalfOfContentOwnerChannel) + if cb.OnBehalfOfContentOwnerChannel != "" { + call = call.OnBehalfOfContentOwnerChannel(cb.OnBehalfOfContentOwnerChannel) } res, err := call.Do() if err != nil { + utils.PrintJSON(cb) log.Fatalln(errors.Join(errInsertChannelBanner, err)) } @@ -65,19 +67,19 @@ func (cb *channelBanner) Insert() { func WithFile(file string) Option { return func(cb *channelBanner) { - cb.file = file + cb.File = file } } func WithOnBehalfOfContentOwner(onBehalfOfContentOwner string) Option { return func(cb *channelBanner) { - cb.onBehalfOfContentOwner = onBehalfOfContentOwner + cb.OnBehalfOfContentOwner = onBehalfOfContentOwner } } func WithOnBehalfOfContentOwnerChannel(onBehalfOfContentOwnerChannel string) Option { return func(cb *channelBanner) { - cb.onBehalfOfContentOwnerChannel = onBehalfOfContentOwnerChannel + cb.OnBehalfOfContentOwnerChannel = onBehalfOfContentOwnerChannel } } diff --git a/pkg/yutuber/channelBanner/channelBanner_test.go b/pkg/yutuber/channelBanner/channelBanner_test.go index 8c6057a..8474e9d 100644 --- a/pkg/yutuber/channelBanner/channelBanner_test.go +++ b/pkg/yutuber/channelBanner/channelBanner_test.go @@ -24,9 +24,9 @@ func TestNewChannelBanner(t *testing.T) { }, }, want: &channelBanner{ - file: "file", - onBehalfOfContentOwner: "contentOwner", - onBehalfOfContentOwnerChannel: "contentOwnerChannel", + File: "file", + OnBehalfOfContentOwner: "contentOwner", + OnBehalfOfContentOwnerChannel: "contentOwnerChannel", }, }, } diff --git a/pkg/yutuber/channelSection/channelSection.go b/pkg/yutuber/channelSection/channelSection.go index 0642411..7993687 100644 --- a/pkg/yutuber/channelSection/channelSection.go +++ b/pkg/yutuber/channelSection/channelSection.go @@ -16,11 +16,11 @@ var ( ) type channelSection struct { - id string - channelId string - hl string - mine *bool - onBehalfOfContentOwner string + ID string `yaml:"id" json:"id"` + ChannelId string `yaml:"channel_id" json:"channel_id"` + Hl string `yaml:"hl" json:"hl"` + Mine *bool `yaml:"mine" json:"mine"` + OnBehalfOfContentOwner string `yaml:"on_behalf_of_content_owner" json:"on_behalf_of_content_owner"` } type ChannelSection interface { @@ -44,24 +44,25 @@ func NewChannelSection(opts ...Option) ChannelSection { func (cs *channelSection) get(parts []string) []*youtube.ChannelSection { call := service.ChannelSections.List(parts) - if cs.id != "" { - call = call.Id(cs.id) + if cs.ID != "" { + call = call.Id(cs.ID) } - if cs.channelId != "" { - call = call.ChannelId(cs.channelId) + if cs.ChannelId != "" { + call = call.ChannelId(cs.ChannelId) } - if cs.hl != "" { - call = call.Hl(cs.hl) + if cs.Hl != "" { + call = call.Hl(cs.Hl) } - if cs.mine != nil { - call = call.Mine(*cs.mine) + if cs.Mine != nil { + call = call.Mine(*cs.Mine) } - if cs.onBehalfOfContentOwner != "" { - call = call.OnBehalfOfContentOwner(cs.onBehalfOfContentOwner) + if cs.OnBehalfOfContentOwner != "" { + call = call.OnBehalfOfContentOwner(cs.OnBehalfOfContentOwner) } res, err := call.Do() if err != nil { + utils.PrintJSON(cs) log.Fatalln(errors.Join(errGetChannelSection, err)) } return res.Items @@ -86,48 +87,49 @@ func (cs *channelSection) List(parts []string, output string) { } func (cs *channelSection) Delete() { - call := service.ChannelSections.Delete(cs.id) - if cs.onBehalfOfContentOwner != "" { - call = call.OnBehalfOfContentOwner(cs.onBehalfOfContentOwner) + call := service.ChannelSections.Delete(cs.ID) + if cs.OnBehalfOfContentOwner != "" { + call = call.OnBehalfOfContentOwner(cs.OnBehalfOfContentOwner) } err := call.Do() if err != nil { + utils.PrintJSON(cs) log.Fatalln(errors.Join(errDeleteChannelSection, err)) } - fmt.Printf("Channel section %s deleted\n", cs.id) + fmt.Printf("Channel section %s deleted\n", cs.ID) } -func WithId(id string) Option { +func WithID(id string) Option { return func(cs *channelSection) { - cs.id = id + cs.ID = id } } func WithChannelId(channelId string) Option { return func(cs *channelSection) { - cs.channelId = channelId + cs.ChannelId = channelId } } func WithHl(hl string) Option { return func(cs *channelSection) { - cs.hl = hl + cs.Hl = hl } } func WithMine(mine bool, changed bool) Option { return func(cs *channelSection) { if changed { - cs.mine = &mine + cs.Mine = &mine } } } func WithOnBehalfOfContentOwner(onBehalfOfContentOwner string) Option { return func(cs *channelSection) { - cs.onBehalfOfContentOwner = onBehalfOfContentOwner + cs.OnBehalfOfContentOwner = onBehalfOfContentOwner } } diff --git a/pkg/yutuber/channelSection/channelSection_test.go b/pkg/yutuber/channelSection/channelSection_test.go index 8dd74ce..4a161b9 100644 --- a/pkg/yutuber/channelSection/channelSection_test.go +++ b/pkg/yutuber/channelSection/channelSection_test.go @@ -25,10 +25,10 @@ func TestNewChannelSection(t *testing.T) { }, }, want: &channelSection{ - channelId: "channelId", - hl: "hl", - mine: &[]bool{true}[0], - onBehalfOfContentOwner: "contentOwner", + ChannelId: "channelId", + Hl: "hl", + Mine: &[]bool{true}[0], + OnBehalfOfContentOwner: "contentOwner", }, }, } diff --git a/pkg/yutuber/i18nLanguage/i18nLanguage.go b/pkg/yutuber/i18nLanguage/i18nLanguage.go index 3e5e70d..2c2479c 100644 --- a/pkg/yutuber/i18nLanguage/i18nLanguage.go +++ b/pkg/yutuber/i18nLanguage/i18nLanguage.go @@ -15,7 +15,7 @@ var ( ) type i18nLanguage struct { - hl string + Hl string `yaml:"hl" json:"hl"` } type I18nLanguage interface { @@ -37,12 +37,13 @@ func NewI18nLanguage(opts ...Option) I18nLanguage { func (i *i18nLanguage) get(parts []string) []*youtube.I18nLanguage { call := service.I18nLanguages.List(parts) - if i.hl != "" { - call = call.Hl(i.hl) + if i.Hl != "" { + call = call.Hl(i.Hl) } res, err := call.Do() if err != nil { + utils.PrintJSON(i) log.Fatalln(errors.Join(errGetI18nLanguage, err)) } @@ -69,7 +70,7 @@ func (i *i18nLanguage) List(parts []string, output string) { func WithHl(hl string) Option { return func(i *i18nLanguage) { - i.hl = hl + i.Hl = hl } } diff --git a/pkg/yutuber/i18nLanguage/i18nLanguage_test.go b/pkg/yutuber/i18nLanguage/i18nLanguage_test.go index 4025e05..a1330df 100644 --- a/pkg/yutuber/i18nLanguage/i18nLanguage_test.go +++ b/pkg/yutuber/i18nLanguage/i18nLanguage_test.go @@ -22,7 +22,7 @@ func TestNewI18nLanguage(t *testing.T) { }, }, want: &i18nLanguage{ - hl: "hl", + Hl: "hl", }, }, } diff --git a/pkg/yutuber/i18nRegion/i18nRegion.go b/pkg/yutuber/i18nRegion/i18nRegion.go index fc3b891..8bebe1c 100644 --- a/pkg/yutuber/i18nRegion/i18nRegion.go +++ b/pkg/yutuber/i18nRegion/i18nRegion.go @@ -15,7 +15,7 @@ var ( ) type i18nRegion struct { - hl string + Hl string `yaml:"hl" json:"hl"` } type I18nRegion interface { @@ -37,12 +37,13 @@ func NewI18nRegion(opts ...Option) I18nRegion { func (i *i18nRegion) get(parts []string) []*youtube.I18nRegion { call := service.I18nRegions.List(parts) - if i.hl != "" { - call = call.Hl(i.hl) + if i.Hl != "" { + call = call.Hl(i.Hl) } res, err := call.Do() if err != nil { + utils.PrintJSON(i) log.Fatalln(errors.Join(errGetI18nRegion, err)) } @@ -69,7 +70,7 @@ func (i *i18nRegion) List(parts []string, output string) { func WithHl(hl string) Option { return func(i *i18nRegion) { - i.hl = hl + i.Hl = hl } } diff --git a/pkg/yutuber/i18nRegion/i18nRegion_test.go b/pkg/yutuber/i18nRegion/i18nRegion_test.go index 204c8d0..1b5fe75 100644 --- a/pkg/yutuber/i18nRegion/i18nRegion_test.go +++ b/pkg/yutuber/i18nRegion/i18nRegion_test.go @@ -22,7 +22,7 @@ func TestNewI18nRegion(t *testing.T) { }, }, want: &i18nRegion{ - hl: "hl", + Hl: "hl", }, }, } diff --git a/pkg/yutuber/member/member.go b/pkg/yutuber/member/member.go index 07f09d7..6095fb2 100644 --- a/pkg/yutuber/member/member.go +++ b/pkg/yutuber/member/member.go @@ -15,10 +15,10 @@ var ( ) type member struct { - memberChannelId string - hasAccessToLevel string - maxResults int64 - mode string + MemberChannelId string `yaml:"member_channel_id" json:"member_channel_id"` + HasAccessToLevel string `yaml:"has_access_to_level" json:"has_access_to_level"` + MaxResults int64 `yaml:"max_results" json:"max_results"` + Mode string `yaml:"mode" json:"mode"` } type Member interface { @@ -40,19 +40,20 @@ func NewMember(opts ...Option) Member { func (m *member) get(parts []string) []*youtube.Member { call := service.Members.List(parts) - if m.memberChannelId != "" { - call = call.FilterByMemberChannelId(m.memberChannelId) + if m.MemberChannelId != "" { + call = call.FilterByMemberChannelId(m.MemberChannelId) } - if m.hasAccessToLevel != "" { - call = call.HasAccessToLevel(m.hasAccessToLevel) + if m.HasAccessToLevel != "" { + call = call.HasAccessToLevel(m.HasAccessToLevel) } - call = call.MaxResults(m.maxResults) - if m.mode != "" { - call = call.Mode(m.mode) + call = call.MaxResults(m.MaxResults) + if m.Mode != "" { + call = call.Mode(m.Mode) } res, err := call.Do() if err != nil { + utils.PrintJSON(m) log.Fatalln(errors.Join(errGetMember, err)) } @@ -80,25 +81,25 @@ func (m *member) List(parts []string, output string) { func WithMemberChannelId(channelId string) Option { return func(m *member) { - m.memberChannelId = channelId + m.MemberChannelId = channelId } } func WithHasAccessToLevel(level string) Option { return func(m *member) { - m.hasAccessToLevel = level + m.HasAccessToLevel = level } } func WithMaxResults(results int64) Option { return func(m *member) { - m.maxResults = results + m.MaxResults = results } } func WithMode(mode string) Option { return func(m *member) { - m.mode = mode + m.Mode = mode } } diff --git a/pkg/yutuber/member/member_test.go b/pkg/yutuber/member/member_test.go index 8da2fd2..c8704bf 100644 --- a/pkg/yutuber/member/member_test.go +++ b/pkg/yutuber/member/member_test.go @@ -25,10 +25,10 @@ func TestNewMember(t *testing.T) { }, }, want: &member{ - memberChannelId: "memberChannelId", - hasAccessToLevel: "hasAccessToLevel", - maxResults: 5, - mode: "all_current", + MemberChannelId: "memberChannelId", + HasAccessToLevel: "hasAccessToLevel", + MaxResults: 5, + Mode: "all_current", }, }, { @@ -41,9 +41,9 @@ func TestNewMember(t *testing.T) { }, }, want: &member{ - memberChannelId: "memberChannelId", - maxResults: 5, - mode: "updates", + MemberChannelId: "memberChannelId", + MaxResults: 5, + Mode: "updates", }, }, } diff --git a/pkg/yutuber/membershipsLevel/membershipsLevel.go b/pkg/yutuber/membershipsLevel/membershipsLevel.go index 90a2d10..86ac812 100644 --- a/pkg/yutuber/membershipsLevel/membershipsLevel.go +++ b/pkg/yutuber/membershipsLevel/membershipsLevel.go @@ -37,6 +37,7 @@ func (m *membershipsLevel) get(parts []string) []*youtube.MembershipsLevel { call := service.MembershipsLevels.List(parts) res, err := call.Do() if err != nil { + utils.PrintJSON(m) log.Fatalln(errors.Join(errGetMembershipsLevel, err)) } diff --git a/pkg/yutuber/playlist/playlist.go b/pkg/yutuber/playlist/playlist.go index a52ae1c..7a45a87 100644 --- a/pkg/yutuber/playlist/playlist.go +++ b/pkg/yutuber/playlist/playlist.go @@ -19,19 +19,19 @@ var ( ) type playlist struct { - id string - title string - description string - hl string - maxResults int64 - mine *bool - tags []string - language string - channelId string - privacy string + ID string `yaml:"id" json:"id"` + Title string `yaml:"title" json:"title"` + Description string `yaml:"description" json:"description"` + Hl string `yaml:"hl" json:"hl"` + MaxResults int64 `yaml:"max_results" json:"max_results"` + Mine *bool `yaml:"mine" json:"mine"` + Tags []string `yaml:"tags" json:"tags"` + Language string `yaml:"language" json:"language"` + ChannelId string `yaml:"channel_id" json:"channel_id"` + Privacy string `yaml:"privacy" json:"privacy"` - onBehalfOfContentOwner string - onBehalfOfContentOwnerChannel string + OnBehalfOfContentOwner string `yaml:"on_behalf_of_content_owner" json:"on_behalf_of_content_owner"` + OnBehalfOfContentOwnerChannel string `yaml:"on_behalf_of_content_owner_channel" json:"on_behalf_of_content_owner_channel"` } type Playlist interface { @@ -57,27 +57,28 @@ func NewPlaylist(opts ...Option) Playlist { func (p *playlist) get(parts []string) []*youtube.Playlist { call := service.Playlists.List(parts) - if p.id != "" { - call = call.Id(p.id) + if p.ID != "" { + call = call.Id(p.ID) } - if p.hl != "" { - call = call.Hl(p.hl) + if p.Hl != "" { + call = call.Hl(p.Hl) } - if p.mine != nil { - call = call.Mine(*p.mine) + if p.Mine != nil { + call = call.Mine(*p.Mine) } - call = call.MaxResults(p.maxResults) - if p.onBehalfOfContentOwner != "" { - call = call.OnBehalfOfContentOwner(p.onBehalfOfContentOwner) + call = call.MaxResults(p.MaxResults) + if p.OnBehalfOfContentOwner != "" { + call = call.OnBehalfOfContentOwner(p.OnBehalfOfContentOwner) } - if p.onBehalfOfContentOwnerChannel != "" { - call = call.OnBehalfOfContentOwnerChannel(p.onBehalfOfContentOwnerChannel) + if p.OnBehalfOfContentOwnerChannel != "" { + call = call.OnBehalfOfContentOwnerChannel(p.OnBehalfOfContentOwnerChannel) } res, err := call.Do() if err != nil { - log.Fatalln(errors.Join(errGetPlaylist, err), p.id) + utils.PrintJSON(p) + log.Fatalln(errors.Join(errGetPlaylist, err), p.ID) } return res.Items @@ -101,20 +102,21 @@ func (p *playlist) List(parts []string, output string) { func (p *playlist) Insert() { upload := &youtube.Playlist{ Snippet: &youtube.PlaylistSnippet{ - Title: p.title, - Description: p.description, - Tags: p.tags, - DefaultLanguage: p.language, - ChannelId: p.channelId, + Title: p.Title, + Description: p.Description, + Tags: p.Tags, + DefaultLanguage: p.Language, + ChannelId: p.ChannelId, }, Status: &youtube.PlaylistStatus{ - PrivacyStatus: p.privacy, + PrivacyStatus: p.Privacy, }, } call := service.Playlists.Insert([]string{"snippet", "status"}, upload) playlist, err := call.Do() if err != nil { + utils.PrintJSON(p) log.Fatalln(errors.Join(errInsertPlaylist, err)) } @@ -123,26 +125,27 @@ func (p *playlist) Insert() { func (p *playlist) Update() { playlist := p.get([]string{"id", "snippet", "status"})[0] - if p.title != "" { - playlist.Snippet.Title = p.title + if p.Title != "" { + playlist.Snippet.Title = p.Title } - if p.description != "" { - playlist.Snippet.Description = p.description + if p.Description != "" { + playlist.Snippet.Description = p.Description } - if p.tags != nil { - playlist.Snippet.Tags = p.tags + if p.Tags != nil { + playlist.Snippet.Tags = p.Tags } - if p.language != "" { - playlist.Snippet.DefaultLanguage = p.language + if p.Language != "" { + playlist.Snippet.DefaultLanguage = p.Language } - if p.privacy != "" { - playlist.Status.PrivacyStatus = p.privacy + if p.Privacy != "" { + playlist.Status.PrivacyStatus = p.Privacy } call := service.Playlists.Update([]string{"snippet", "status"}, playlist) res, err := call.Do() if err != nil { - log.Fatalln(errors.Join(errUpdatePlaylist, err), p.id) + utils.PrintJSON(p) + log.Fatalln(errors.Join(errUpdatePlaylist, err), p.ID) } fmt.Println("Playlist updated:") @@ -150,89 +153,90 @@ func (p *playlist) Update() { } func (p *playlist) Delete() { - call := service.Playlists.Delete(p.id) - if p.onBehalfOfContentOwner != "" { - call = call.OnBehalfOfContentOwner(p.onBehalfOfContentOwner) + call := service.Playlists.Delete(p.ID) + if p.OnBehalfOfContentOwner != "" { + call = call.OnBehalfOfContentOwner(p.OnBehalfOfContentOwner) } err := call.Do() if err != nil { - log.Fatalln(errors.Join(errDeletePlaylist, err), p.id) + utils.PrintJSON(p) + log.Fatalln(errors.Join(errDeletePlaylist, err), p.ID) } - fmt.Printf("Playlist %s deleted", p.id) + fmt.Printf("Playlist %s deleted", p.ID) } -func WithId(id string) Option { +func WithID(id string) Option { return func(p *playlist) { - p.id = id + p.ID = id } } func WithTitle(title string) Option { return func(p *playlist) { - p.title = title + p.Title = title } } func WithDescription(description string) Option { return func(p *playlist) { - p.description = description + p.Description = description } } func WithTags(tags []string) Option { return func(p *playlist) { - p.tags = tags + p.Tags = tags } } func WithLanguage(language string) Option { return func(p *playlist) { - p.language = language + p.Language = language } } func WithChannelId(channelId string) Option { return func(p *playlist) { - p.channelId = channelId + p.ChannelId = channelId } } func WithPrivacy(privacy string) Option { return func(p *playlist) { - p.privacy = privacy + p.Privacy = privacy } } func WithHl(hl string) Option { return func(p *playlist) { - p.hl = hl + p.Hl = hl } } func WithMaxResults(maxResults int64) Option { return func(p *playlist) { - p.maxResults = maxResults + p.MaxResults = maxResults } } func WithMine(mine bool, changed bool) Option { return func(p *playlist) { if changed { - p.mine = &mine + p.Mine = &mine } } } func WithOnBehalfOfContentOwner(contentOwner string) Option { return func(p *playlist) { - p.onBehalfOfContentOwner = contentOwner + p.OnBehalfOfContentOwner = contentOwner } } func WithOnBehalfOfContentOwnerChannel(channel string) Option { return func(p *playlist) { - p.onBehalfOfContentOwnerChannel = channel + p.OnBehalfOfContentOwnerChannel = channel } } diff --git a/pkg/yutuber/playlist/playlist_test.go b/pkg/yutuber/playlist/playlist_test.go index a7e9aa2..2174937 100644 --- a/pkg/yutuber/playlist/playlist_test.go +++ b/pkg/yutuber/playlist/playlist_test.go @@ -18,7 +18,7 @@ func TestNewPlaylist(t *testing.T) { name: "TestNewPlaylist", args: args{ opts: []Option{ - WithId("id"), + WithID("id"), WithTitle("title"), WithDescription("description"), WithHl("hl"), @@ -33,18 +33,18 @@ func TestNewPlaylist(t *testing.T) { }, }, want: &playlist{ - id: "id", - title: "title", - description: "description", - hl: "hl", - maxResults: 5, - mine: &[]bool{true}[0], - tags: []string{"tag1", "tag2"}, - language: "language", - channelId: "channelId", - privacy: "public", - onBehalfOfContentOwner: "contentOwner", - onBehalfOfContentOwnerChannel: "contentOwnerChannel", + ID: "id", + Title: "title", + Description: "description", + Hl: "hl", + MaxResults: 5, + Mine: &[]bool{true}[0], + Tags: []string{"tag1", "tag2"}, + Language: "language", + ChannelId: "channelId", + Privacy: "public", + OnBehalfOfContentOwner: "contentOwner", + OnBehalfOfContentOwnerChannel: "contentOwnerChannel", }, }, } diff --git a/pkg/yutuber/playlistItem/playlistItem.go b/pkg/yutuber/playlistItem/playlistItem.go index 03c5a2b..0af7c89 100644 --- a/pkg/yutuber/playlistItem/playlistItem.go +++ b/pkg/yutuber/playlistItem/playlistItem.go @@ -19,20 +19,20 @@ var ( ) type playlistItem struct { - id string - title string - description string - kind string - kVideoId string - kChannelId string - kPlaylistId string - videoId string - playlistId string - channelId string - privacy string - maxResults int64 + ID string `yaml:"id" json:"id"` + Title string `yaml:"title" json:"title"` + Description string `yaml:"description" json:"description"` + Kind string `yaml:"kind" json:"kind"` + KVideoId string `yaml:"k_video_id" json:"k_video_id"` + KChannelId string `yaml:"k_channel_id" json:"k_channel_id"` + KPlaylistId string `yaml:"k_playlist_id" json:"k_playlist_id"` + VideoId string `yaml:"video_id" json:"video_id"` + PlaylistId string `yaml:"playlist_id" json:"playlist_id"` + ChannelId string `yaml:"channel_id" json:"channel_id"` + Privacy string `yaml:"privacy" json:"privacy"` + MaxResults int64 `yaml:"max_results" json:"max_results"` - onBehalfOfContentOwner string + OnBehalfOfContentOwner string `yaml:"on_behalf_of_content_owner" json:"on_behalf_of_content_owner"` } type PlaylistItem interface { @@ -57,23 +57,24 @@ func NewPlaylistItem(opts ...Option) PlaylistItem { func (pi *playlistItem) get(parts []string) []*youtube.PlaylistItem { call := service.PlaylistItems.List(parts) - if pi.id != "" { - call = call.Id(pi.id) + if pi.ID != "" { + call = call.Id(pi.ID) } - if pi.playlistId != "" { - call = call.PlaylistId(pi.playlistId) + if pi.PlaylistId != "" { + call = call.PlaylistId(pi.PlaylistId) } - if pi.onBehalfOfContentOwner != "" { - call = call.OnBehalfOfContentOwner(pi.onBehalfOfContentOwner) + if pi.OnBehalfOfContentOwner != "" { + call = call.OnBehalfOfContentOwner(pi.OnBehalfOfContentOwner) } - if pi.videoId != "" { - call = call.VideoId(pi.videoId) + if pi.VideoId != "" { + call = call.VideoId(pi.VideoId) } - call = call.MaxResults(pi.maxResults) + call = call.MaxResults(pi.MaxResults) res, err := call.Do() if err != nil { - log.Fatalln(errors.Join(errGetPlaylistItem, err), pi.id) + utils.PrintJSON(pi) + log.Fatalln(errors.Join(errGetPlaylistItem, err), pi.ID) } return res.Items @@ -96,34 +97,34 @@ func (pi *playlistItem) List(parts []string, output string) { func (pi *playlistItem) Insert() { var resourceId *youtube.ResourceId - switch pi.kind { + switch pi.Kind { case "video": resourceId = &youtube.ResourceId{ Kind: "youtube#video", - VideoId: pi.kVideoId, + VideoId: pi.KVideoId, } case "channel": resourceId = &youtube.ResourceId{ Kind: "youtube#channel", - ChannelId: pi.kChannelId, + ChannelId: pi.KChannelId, } case "playlist": resourceId = &youtube.ResourceId{ Kind: "youtube#playlist", - PlaylistId: pi.kPlaylistId, + PlaylistId: pi.KPlaylistId, } } playlistItem := &youtube.PlaylistItem{ Snippet: &youtube.PlaylistItemSnippet{ - Title: pi.title, - Description: pi.description, + Title: pi.Title, + Description: pi.Description, ResourceId: resourceId, - PlaylistId: pi.playlistId, - ChannelId: pi.channelId, + PlaylistId: pi.PlaylistId, + ChannelId: pi.ChannelId, }, Status: &youtube.PlaylistItemStatus{ - PrivacyStatus: pi.privacy, + PrivacyStatus: pi.Privacy, }, } @@ -132,7 +133,8 @@ func (pi *playlistItem) Insert() { ) res, err := call.Do() if err != nil { - log.Fatalln(errors.Join(errInsertPlaylistItem, err), pi.videoId) + utils.PrintJSON(pi) + log.Fatalln(errors.Join(errInsertPlaylistItem, err), pi.VideoId) } fmt.Println("PlaylistItem inserted:") utils.PrintYAML(res) @@ -140,14 +142,14 @@ func (pi *playlistItem) Insert() { func (pi *playlistItem) Update() { playlistItem := pi.get([]string{"id", "snippet", "status"})[0] - if pi.title != "" { - playlistItem.Snippet.Title = pi.title + if pi.Title != "" { + playlistItem.Snippet.Title = pi.Title } - if pi.description != "" { - playlistItem.Snippet.Description = pi.description + if pi.Description != "" { + playlistItem.Snippet.Description = pi.Description } - if pi.privacy != "" { - playlistItem.Status.PrivacyStatus = pi.privacy + if pi.Privacy != "" { + playlistItem.Status.PrivacyStatus = pi.Privacy } call := service.PlaylistItems.Update( @@ -155,101 +157,103 @@ func (pi *playlistItem) Update() { ) res, err := call.Do() if err != nil { - log.Fatalln(errors.Join(errUpdatePlaylistItem, err), pi.id) + utils.PrintJSON(pi) + log.Fatalln(errors.Join(errUpdatePlaylistItem, err), pi.ID) } fmt.Println("PlaylistItem updated:") utils.PrintYAML(res) } func (pi *playlistItem) Delete() { - call := service.PlaylistItems.Delete(pi.id) - if pi.onBehalfOfContentOwner != "" { - call = call.OnBehalfOfContentOwner(pi.onBehalfOfContentOwner) + call := service.PlaylistItems.Delete(pi.ID) + if pi.OnBehalfOfContentOwner != "" { + call = call.OnBehalfOfContentOwner(pi.OnBehalfOfContentOwner) } err := call.Do() if err != nil { - log.Fatalln(errors.Join(errDeletePlaylistItem, err), pi.id) + utils.PrintJSON(pi) + log.Fatalln(errors.Join(errDeletePlaylistItem, err), pi.ID) } - fmt.Printf("Playlsit Item %s deleted", pi.id) + fmt.Printf("Playlsit Item %s deleted", pi.ID) } -func WithId(id string) Option { +func WithID(id string) Option { return func(p *playlistItem) { - p.id = id + p.ID = id } } func WithTitle(title string) Option { return func(p *playlistItem) { - p.title = title + p.Title = title } } func WithDescription(description string) Option { return func(p *playlistItem) { - p.description = description + p.Description = description } } func WithKind(kind string) Option { return func(p *playlistItem) { - p.kind = kind + p.Kind = kind } } func WithKVideoId(kVideoId string) Option { return func(p *playlistItem) { - p.kVideoId = kVideoId + p.KVideoId = kVideoId } } func WithKChannelId(kChannelId string) Option { return func(p *playlistItem) { - p.kChannelId = kChannelId + p.KChannelId = kChannelId } } func WithKPlaylistId(kPlaylistId string) Option { return func(p *playlistItem) { - p.kPlaylistId = kPlaylistId + p.KPlaylistId = kPlaylistId } } func WithVideoId(videoId string) Option { return func(p *playlistItem) { - p.videoId = videoId + p.VideoId = videoId } } func WithPlaylistId(playlistId string) Option { return func(p *playlistItem) { - p.playlistId = playlistId + p.PlaylistId = playlistId } } func WithChannelId(channelId string) Option { return func(p *playlistItem) { - p.channelId = channelId + p.ChannelId = channelId } } func WithPrivacy(privacy string) Option { return func(p *playlistItem) { - p.privacy = privacy + p.Privacy = privacy } } func WithMaxResults(maxResults int64) Option { return func(p *playlistItem) { - p.maxResults = maxResults + p.MaxResults = maxResults } } func WithOnBehalfOfContentOwner(onBehalfOfContentOwner string) Option { return func(p *playlistItem) { - p.onBehalfOfContentOwner = onBehalfOfContentOwner + p.OnBehalfOfContentOwner = onBehalfOfContentOwner } } diff --git a/pkg/yutuber/playlistItem/playlistItem_test.go b/pkg/yutuber/playlistItem/playlistItem_test.go index 2afa7e8..7e9a8de 100644 --- a/pkg/yutuber/playlistItem/playlistItem_test.go +++ b/pkg/yutuber/playlistItem/playlistItem_test.go @@ -18,7 +18,7 @@ func TestNewPlaylistItem(t *testing.T) { name: "TestNewPlaylistItem", args: args{ opts: []Option{ - WithId("id"), + WithID("id"), WithTitle("title"), WithDescription("description"), WithKind("video"), @@ -29,21 +29,21 @@ func TestNewPlaylistItem(t *testing.T) { }, }, want: &playlistItem{ - id: "id", - title: "title", - description: "description", - kind: "video", - kVideoId: "kVideoId", - playlistId: "playlistId", - channelId: "channelId", - privacy: "public", + ID: "id", + Title: "title", + Description: "description", + Kind: "video", + KVideoId: "kVideoId", + PlaylistId: "playlistId", + ChannelId: "channelId", + Privacy: "public", }, }, { name: "TestNewPlaylistItem", args: args{ opts: []Option{ - WithId("id"), + WithID("id"), WithTitle("title"), WithDescription("description"), WithKind("channel"), @@ -54,14 +54,14 @@ func TestNewPlaylistItem(t *testing.T) { }, }, want: &playlistItem{ - id: "id", - title: "title", - description: "description", - kind: "channel", - kChannelId: "kChannelId", - playlistId: "playlistId", - channelId: "channelId", - privacy: "private", + ID: "id", + Title: "title", + Description: "description", + Kind: "channel", + KChannelId: "kChannelId", + PlaylistId: "playlistId", + ChannelId: "channelId", + Privacy: "private", }, }, { @@ -74,9 +74,9 @@ func TestNewPlaylistItem(t *testing.T) { }, }, want: &playlistItem{ - videoId: "videoId", - maxResults: 5, - onBehalfOfContentOwner: "contentOwner", + VideoId: "videoId", + MaxResults: 5, + OnBehalfOfContentOwner: "contentOwner", }, }, } diff --git a/pkg/yutuber/search/search.go b/pkg/yutuber/search/search.go index 5d56036..3892ff5 100644 --- a/pkg/yutuber/search/search.go +++ b/pkg/yutuber/search/search.go @@ -15,35 +15,35 @@ var ( ) type search struct { - channelId string - channelType string - eventType string - forContentOwner *bool - forDeveloper *bool - forMine *bool - location string - locationRadius string - maxResults int64 - onBehalfOfContentOwner string - order string - publishedAfter string - publishedBefore string - q string - regionCode string - relevanceLanguage string - safeSearch string - topicId string - types string - videoCaption string - videoCategoryId string - videoDefinition string - videoDimension string - videoDuration string - videoEmbeddable string - videoLicense string - videoPaidProductPlacement string - videoSyndicated string - videoType string + ChannelId string `yaml:"channel_id" json:"channel_id"` + ChannelType string `yaml:"channel_type" json:"channel_type"` + EventType string `yaml:"event_type" json:"event_type"` + ForContentOwner *bool `yaml:"for_content_owner" json:"for_content_owner"` + ForDeveloper *bool `yaml:"for_developer" json:"for_developer"` + ForMine *bool `yaml:"for_mine" json:"for_mine"` + Location string `yaml:"location" json:"location"` + LocationRadius string `yaml:"location_radius" json:"location_radius"` + MaxResults int64 `yaml:"max_results" json:"max_results"` + OnBehalfOfContentOwner string `yaml:"on_behalf_of_content_owner" json:"on_behalf_of_content_owner"` + Order string `yaml:"order" json:"order"` + PublishedAfter string `yaml:"published_after" json:"published_after"` + PublishedBefore string `yaml:"published_before" json:"published_before"` + Q string `yaml:"q" json:"q"` + RegionCode string `yaml:"region_code" json:"region_code"` + RelevanceLanguage string `yaml:"relevance_language" json:"relevance_language"` + SafeSearch string `yaml:"safe_search" json:"safe_search"` + TopicId string `yaml:"topic_id" json:"topic_id"` + Types string `yaml:"types" json:"types"` + VideoCaption string `yaml:"video_caption" json:"video_caption"` + VideoCategoryId string `yaml:"video_category_id" json:"video_category_id"` + VideoDefinition string `yaml:"video_definition" json:"video_definition"` + VideoDimension string `yaml:"video_dimension" json:"video_dimension"` + VideoDuration string `yaml:"video_duration" json:"video_duration"` + VideoEmbeddable string `yaml:"video_embeddable" json:"video_embeddable"` + VideoLicense string `yaml:"video_license" json:"video_license"` + VideoPaidProductPlacement string `yaml:"video_paid_product_placement" json:"video_paid_product_placement"` + VideoSyndicated string `yaml:"video_syndicated" json:"video_syndicated"` + VideoType string `yaml:"video_type" json:"video_type"` } type Search interface { @@ -65,123 +65,124 @@ func NewSearch(opts ...Option) Search { func (s *search) get(parts []string) []*youtube.SearchResult { call := service.Search.List(parts) - if s.channelId != "" { - call.ChannelId(s.channelId) + if s.ChannelId != "" { + call.ChannelId(s.ChannelId) } - if s.channelType != "" { - call.ChannelType(s.channelType) + if s.ChannelType != "" { + call.ChannelType(s.ChannelType) } - if s.eventType != "" { - call.EventType(s.eventType) + if s.EventType != "" { + call.EventType(s.EventType) } - if s.forContentOwner != nil { - call.ForContentOwner(*s.forContentOwner) + if s.ForContentOwner != nil { + call.ForContentOwner(*s.ForContentOwner) } - if s.forDeveloper != nil { - call.ForDeveloper(*s.forDeveloper) + if s.ForDeveloper != nil { + call.ForDeveloper(*s.ForDeveloper) } - if s.forMine != nil { - call.ForMine(*s.forMine) + if s.ForMine != nil { + call.ForMine(*s.ForMine) } - if s.location != "" { - call.Location(s.location) + if s.Location != "" { + call.Location(s.Location) } - if s.locationRadius != "" { - call.LocationRadius(s.locationRadius) + if s.LocationRadius != "" { + call.LocationRadius(s.LocationRadius) } - call.MaxResults(s.maxResults) + call.MaxResults(s.MaxResults) - if s.onBehalfOfContentOwner != "" { - call.OnBehalfOfContentOwner(s.onBehalfOfContentOwner) + if s.OnBehalfOfContentOwner != "" { + call.OnBehalfOfContentOwner(s.OnBehalfOfContentOwner) } - if s.order != "" { - call.Order(s.order) + if s.Order != "" { + call.Order(s.Order) } - if s.publishedAfter != "" { - call.PublishedAfter(s.publishedAfter) + if s.PublishedAfter != "" { + call.PublishedAfter(s.PublishedAfter) } - if s.publishedBefore != "" { - call.PublishedBefore(s.publishedBefore) + if s.PublishedBefore != "" { + call.PublishedBefore(s.PublishedBefore) } - if s.q != "" { - call.Q(s.q) + if s.Q != "" { + call.Q(s.Q) } - if s.regionCode != "" { - call.RegionCode(s.regionCode) + if s.RegionCode != "" { + call.RegionCode(s.RegionCode) } - if s.relevanceLanguage != "" { - call.RelevanceLanguage(s.relevanceLanguage) + if s.RelevanceLanguage != "" { + call.RelevanceLanguage(s.RelevanceLanguage) } - if s.safeSearch != "" { - call.SafeSearch(s.safeSearch) + if s.SafeSearch != "" { + call.SafeSearch(s.SafeSearch) } - if s.topicId != "" { - call.TopicId(s.topicId) + if s.TopicId != "" { + call.TopicId(s.TopicId) } - if s.types != "" { - call.Type(s.types) + if s.Types != "" { + call.Type(s.Types) } - if s.videoCaption != "" { - call.VideoCaption(s.videoCaption) + if s.VideoCaption != "" { + call.VideoCaption(s.VideoCaption) } - if s.videoCategoryId != "" { - call.VideoCategoryId(s.videoCategoryId) + if s.VideoCategoryId != "" { + call.VideoCategoryId(s.VideoCategoryId) } - if s.videoDefinition != "" { - call.VideoDefinition(s.videoDefinition) + if s.VideoDefinition != "" { + call.VideoDefinition(s.VideoDefinition) } - if s.videoDimension != "" { - call.VideoDimension(s.videoDimension) + if s.VideoDimension != "" { + call.VideoDimension(s.VideoDimension) } - if s.videoDuration != "" { - call.VideoDuration(s.videoDuration) + if s.VideoDuration != "" { + call.VideoDuration(s.VideoDuration) } - if s.videoEmbeddable != "" { - call.VideoEmbeddable(s.videoEmbeddable) + if s.VideoEmbeddable != "" { + call.VideoEmbeddable(s.VideoEmbeddable) } - if s.videoLicense != "" { - call.VideoLicense(s.videoLicense) + if s.VideoLicense != "" { + call.VideoLicense(s.VideoLicense) } - if s.videoPaidProductPlacement != "" { - call.VideoPaidProductPlacement(s.videoPaidProductPlacement) + if s.VideoPaidProductPlacement != "" { + call.VideoPaidProductPlacement(s.VideoPaidProductPlacement) } - if s.videoSyndicated != "" { - call.VideoSyndicated(s.videoSyndicated) + if s.VideoSyndicated != "" { + call.VideoSyndicated(s.VideoSyndicated) } - if s.videoType != "" { - call.VideoType(s.videoType) + if s.VideoType != "" { + call.VideoType(s.VideoType) } res, err := call.Do() if err != nil { - log.Fatalln(errors.Join(errGetSearch, err), s.q) + utils.PrintJSON(s) + log.Fatalln(errors.Join(errGetSearch, err), s.Q) } return res.Items @@ -204,26 +205,26 @@ func (s *search) List(parts []string, output string) { func WithChannelId(channelId string) Option { return func(s *search) { - s.channelId = channelId + s.ChannelId = channelId } } func WithChannelType(channelType string) Option { return func(s *search) { - s.channelType = channelType + s.ChannelType = channelType } } func WithEventType(eventType string) Option { return func(s *search) { - s.eventType = eventType + s.EventType = eventType } } func WithForContentOwner(forContentOwner bool, changed bool) Option { return func(s *search) { if changed { - s.forContentOwner = &forContentOwner + s.ForContentOwner = &forContentOwner } } } @@ -231,7 +232,7 @@ func WithForContentOwner(forContentOwner bool, changed bool) Option { func WithForDeveloper(forDeveloper bool, changed bool) Option { return func(s *search) { if changed { - s.forDeveloper = &forDeveloper + s.ForDeveloper = &forDeveloper } } } @@ -239,146 +240,146 @@ func WithForDeveloper(forDeveloper bool, changed bool) Option { func WithForMine(forMine bool, changed bool) Option { return func(s *search) { if changed { - s.forMine = &forMine + s.ForMine = &forMine } } } func WithLocation(location string) Option { return func(s *search) { - s.location = location + s.Location = location } } func WithLocationRadius(locationRadius string) Option { return func(s *search) { - s.locationRadius = locationRadius + s.LocationRadius = locationRadius } } func WithMaxResults(maxResults int64) Option { return func(s *search) { - s.maxResults = maxResults + s.MaxResults = maxResults } } func WithOnBehalfOfContentOwner(onBehalfOfContentOwner string) Option { return func(s *search) { - s.onBehalfOfContentOwner = onBehalfOfContentOwner + s.OnBehalfOfContentOwner = onBehalfOfContentOwner } } func WithOrder(order string) Option { return func(s *search) { - s.order = order + s.Order = order } } func WithPublishedAfter(publishedAfter string) Option { return func(s *search) { - s.publishedAfter = publishedAfter + s.PublishedAfter = publishedAfter } } func WithPublishedBefore(publishedBefore string) Option { return func(s *search) { - s.publishedBefore = publishedBefore + s.PublishedBefore = publishedBefore } } func WithQ(q string) Option { return func(s *search) { - s.q = q + s.Q = q } } func WithRegionCode(regionCode string) Option { return func(s *search) { - s.regionCode = regionCode + s.RegionCode = regionCode } } func WithRelevanceLanguage(relevanceLanguage string) Option { return func(s *search) { - s.relevanceLanguage = relevanceLanguage + s.RelevanceLanguage = relevanceLanguage } } func WithSafeSearch(safeSearch string) Option { return func(s *search) { - s.safeSearch = safeSearch + s.SafeSearch = safeSearch } } func WithTopicId(topicId string) Option { return func(s *search) { - s.topicId = topicId + s.TopicId = topicId } } func WithTypes(types string) Option { return func(s *search) { - s.types = types + s.Types = types } } func WithVideoCaption(videoCaption string) Option { return func(s *search) { - s.videoCaption = videoCaption + s.VideoCaption = videoCaption } } func WithVideoCategoryId(videoCategoryId string) Option { return func(s *search) { - s.videoCategoryId = videoCategoryId + s.VideoCategoryId = videoCategoryId } } func WithVideoDefinition(videoDefinition string) Option { return func(s *search) { - s.videoDefinition = videoDefinition + s.VideoDefinition = videoDefinition } } func WithVideoDimension(videoDimension string) Option { return func(s *search) { - s.videoDimension = videoDimension + s.VideoDimension = videoDimension } } func WithVideoDuration(videoDuration string) Option { return func(s *search) { - s.videoDuration = videoDuration + s.VideoDuration = videoDuration } } func WithVideoEmbeddable(videoEmbeddable string) Option { return func(s *search) { - s.videoEmbeddable = videoEmbeddable + s.VideoEmbeddable = videoEmbeddable } } func WithVideoLicense(videoLicense string) Option { return func(s *search) { - s.videoLicense = videoLicense + s.VideoLicense = videoLicense } } func WithVideoPaidProductPlacement(videoPaidProductPlacement string) Option { return func(s *search) { - s.videoPaidProductPlacement = videoPaidProductPlacement + s.VideoPaidProductPlacement = videoPaidProductPlacement } } func WithVideoSyndicated(videoSyndicated string) Option { return func(s *search) { - s.videoSyndicated = videoSyndicated + s.VideoSyndicated = videoSyndicated } } func WithVideoType(videoType string) Option { return func(s *search) { - s.videoType = videoType + s.VideoType = videoType } } diff --git a/pkg/yutuber/search/search_test.go b/pkg/yutuber/search/search_test.go index 9c883d7..71b42a3 100644 --- a/pkg/yutuber/search/search_test.go +++ b/pkg/yutuber/search/search_test.go @@ -32,17 +32,17 @@ func TestNewSearch(t *testing.T) { }, }, want: &search{ - channelId: "channelId", - channelType: "show", - eventType: "live", - forContentOwner: &[]bool{true}[0], - forDeveloper: &[]bool{false}[0], - forMine: &[]bool{false}[0], - location: "location", - locationRadius: "radius", - maxResults: 10, - onBehalfOfContentOwner: "contentOwner", - order: "rating", + ChannelId: "channelId", + ChannelType: "show", + EventType: "live", + ForContentOwner: &[]bool{true}[0], + ForDeveloper: &[]bool{false}[0], + ForMine: &[]bool{false}[0], + Location: "location", + LocationRadius: "radius", + MaxResults: 10, + OnBehalfOfContentOwner: "contentOwner", + Order: "rating", }, }, } diff --git a/pkg/yutuber/subscription/subscription.go b/pkg/yutuber/subscription/subscription.go index 9c6d8ed..82a02f2 100644 --- a/pkg/yutuber/subscription/subscription.go +++ b/pkg/yutuber/subscription/subscription.go @@ -17,19 +17,19 @@ var ( ) type subscription struct { - id string - subscriberChannelId string - description string - channelId string - forChannelId string - maxResults int64 - mine *bool - myRecentSubscribers *bool - mySubscribers *bool - onBehalfOfContentOwner string - onBehalfOfContentOwnerChannel string - order string - title string + ID string `yaml:"id" json:"id"` + SubscriberChannelId string `yaml:"subscriber_channel_id" json:"subscriber_channel_id"` + Description string `yaml:"description" json:"description"` + ChannelId string `yaml:"channel_id" json:"channel_id"` + ForChannelId string `yaml:"for_channel_id" json:"for_channel_id"` + MaxResults int64 `yaml:"max_results" json:"max_results"` + Mine *bool `yaml:"mine" json:"mine"` + MyRecentSubscribers *bool `yaml:"my_recent_subscribers" json:"my_recent_subscribers"` + MySubscribers *bool `yaml:"my_subscribers" json:"my_subscribers"` + OnBehalfOfContentOwner string `yaml:"on_behalf_of_content_owner" json:"on_behalf_of_content_owner"` + OnBehalfOfContentOwnerChannel string `yaml:"on_behalf_of_content_owner_channel" json:"on_behalf_of_content_owner_channel"` + Order string `yaml:"order" json:"order"` + Title string `yaml:"title" json:"title"` } type Subscription interface { @@ -53,39 +53,40 @@ func NewSubscription(opts ...Option) Subscription { func (s *subscription) get(parts []string) []*youtube.Subscription { call := service.Subscriptions.List(parts) - if s.id != "" { - call = call.Id(s.id) + if s.ID != "" { + call = call.Id(s.ID) } - if s.channelId != "" { - call = call.ChannelId(s.channelId) + if s.ChannelId != "" { + call = call.ChannelId(s.ChannelId) } - if s.forChannelId != "" { - call = call.ForChannelId(s.forChannelId) + if s.ForChannelId != "" { + call = call.ForChannelId(s.ForChannelId) } - call = call.MaxResults(s.maxResults) + call = call.MaxResults(s.MaxResults) - if s.mine != nil { - call = call.Mine(*s.mine) + if s.Mine != nil { + call = call.Mine(*s.Mine) } - if s.myRecentSubscribers != nil { - call = call.MyRecentSubscribers(*s.myRecentSubscribers) + if s.MyRecentSubscribers != nil { + call = call.MyRecentSubscribers(*s.MyRecentSubscribers) } - if s.mySubscribers != nil { - call = call.MySubscribers(*s.mySubscribers) + if s.MySubscribers != nil { + call = call.MySubscribers(*s.MySubscribers) } - if s.onBehalfOfContentOwner != "" { - call = call.OnBehalfOfContentOwner(s.onBehalfOfContentOwner) + if s.OnBehalfOfContentOwner != "" { + call = call.OnBehalfOfContentOwner(s.OnBehalfOfContentOwner) } - if s.onBehalfOfContentOwnerChannel != "" { - call = call.OnBehalfOfContentOwnerChannel(s.onBehalfOfContentOwnerChannel) + if s.OnBehalfOfContentOwnerChannel != "" { + call = call.OnBehalfOfContentOwnerChannel(s.OnBehalfOfContentOwnerChannel) } - if s.order != "" { - call = call.Order(s.order) + if s.Order != "" { + call = call.Order(s.Order) } res, err := call.Do() if err != nil { + utils.PrintJSON(s) log.Fatalln(errors.Join(errGetSubscription, err)) } @@ -113,18 +114,19 @@ func (s *subscription) List(parts []string, output string) { func (s *subscription) Insert() { subscription := &youtube.Subscription{ Snippet: &youtube.SubscriptionSnippet{ - ChannelId: s.subscriberChannelId, - Description: s.description, + ChannelId: s.SubscriberChannelId, + Description: s.Description, ResourceId: &youtube.ResourceId{ - ChannelId: s.channelId, + ChannelId: s.ChannelId, }, - Title: s.title, + Title: s.Title, }, } call := service.Subscriptions.Insert([]string{"snippet"}, subscription) res, err := call.Do() if err != nil { + utils.PrintJSON(s) log.Fatalln(errors.Join(errInsertSubscription, err)) } fmt.Println("Subscription inserted") @@ -132,55 +134,56 @@ func (s *subscription) Insert() { } func (s *subscription) Delete() { - call := service.Subscriptions.Delete(s.id) + call := service.Subscriptions.Delete(s.ID) err := call.Do() if err != nil { - log.Fatalln(errors.Join(errDeleteSubscription, err), s.id) + utils.PrintJSON(s) + log.Fatalln(errors.Join(errDeleteSubscription, err), s.ID) } - fmt.Printf("Subscription %s deleted", s.id) + fmt.Printf("Subscription %s deleted", s.ID) } -func WithId(id string) Option { +func WithID(id string) Option { return func(s *subscription) { - s.id = id + s.ID = id } } func WithSubscriberChannelId(id string) Option { return func(s *subscription) { - s.subscriberChannelId = id + s.SubscriberChannelId = id } } func WithDescription(description string) Option { return func(s *subscription) { - s.description = description + s.Description = description } } func WithChannelId(channelId string) Option { return func(s *subscription) { - s.channelId = channelId + s.ChannelId = channelId } } func WithForChannelId(forChannelId string) Option { return func(s *subscription) { - s.forChannelId = forChannelId + s.ForChannelId = forChannelId } } func WithMaxResults(maxResults int64) Option { return func(s *subscription) { - s.maxResults = maxResults + s.MaxResults = maxResults } } func WithMine(mine bool, changed bool) Option { return func(s *subscription) { if changed { - s.mine = &mine + s.Mine = &mine } } } @@ -188,7 +191,7 @@ func WithMine(mine bool, changed bool) Option { func WithMyRecentSubscribers(myRecentSubscribers bool, changed bool) Option { return func(s *subscription) { if changed { - s.myRecentSubscribers = &myRecentSubscribers + s.MyRecentSubscribers = &myRecentSubscribers } } } @@ -196,32 +199,32 @@ func WithMyRecentSubscribers(myRecentSubscribers bool, changed bool) Option { func WithMySubscribers(mySubscribers bool, changed bool) Option { return func(s *subscription) { if changed { - s.mySubscribers = &mySubscribers + s.MySubscribers = &mySubscribers } } } func WithOnBehalfOfContentOwner(onBehalfOfContentOwner string) Option { return func(s *subscription) { - s.onBehalfOfContentOwner = onBehalfOfContentOwner + s.OnBehalfOfContentOwner = onBehalfOfContentOwner } } func WithOnBehalfOfContentOwnerChannel(onBehalfOfContentOwnerChannel string) Option { return func(s *subscription) { - s.onBehalfOfContentOwnerChannel = onBehalfOfContentOwnerChannel + s.OnBehalfOfContentOwnerChannel = onBehalfOfContentOwnerChannel } } func WithOrder(order string) Option { return func(s *subscription) { - s.order = order + s.Order = order } } func WithTitle(title string) Option { return func(s *subscription) { - s.title = title + s.Title = title } } diff --git a/pkg/yutuber/subscription/subscription_test.go b/pkg/yutuber/subscription/subscription_test.go index 44013d2..42c197d 100644 --- a/pkg/yutuber/subscription/subscription_test.go +++ b/pkg/yutuber/subscription/subscription_test.go @@ -18,7 +18,7 @@ func TestNewSubscription(t *testing.T) { name: "TestNewSubscription", args: args{ opts: []Option{ - WithId("id"), + WithID("id"), WithSubscriberChannelId("subscriberChannelId"), WithDescription("description"), WithChannelId("channelId"), @@ -33,18 +33,18 @@ func TestNewSubscription(t *testing.T) { }, }, want: &subscription{ - id: "id", - subscriberChannelId: "subscriberChannelId", - description: "description", - channelId: "channelId", - forChannelId: "forChannelId", - maxResults: 10, - mine: &[]bool{true}[0], - myRecentSubscribers: &[]bool{false}[0], - mySubscribers: &[]bool{false}[0], - onBehalfOfContentOwner: "contentOwner", - onBehalfOfContentOwnerChannel: "contentOwnerChannel", - order: "relevance", + ID: "id", + SubscriberChannelId: "subscriberChannelId", + Description: "description", + ChannelId: "channelId", + ForChannelId: "forChannelId", + MaxResults: 10, + Mine: &[]bool{true}[0], + MyRecentSubscribers: &[]bool{false}[0], + MySubscribers: &[]bool{false}[0], + OnBehalfOfContentOwner: "contentOwner", + OnBehalfOfContentOwnerChannel: "contentOwnerChannel", + Order: "relevance", }, }, } diff --git a/pkg/yutuber/thumbnail/thumbnail.go b/pkg/yutuber/thumbnail/thumbnail.go index b328d24..b0e09c3 100644 --- a/pkg/yutuber/thumbnail/thumbnail.go +++ b/pkg/yutuber/thumbnail/thumbnail.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "github.com/eat-pray-ai/yutu/pkg/auth" + "github.com/eat-pray-ai/yutu/pkg/utils" "google.golang.org/api/youtube/v3" "log" "os" @@ -15,8 +16,8 @@ var ( ) type thumbnail struct { - file string - videoId string + File string `yaml:"file" json:"file"` + VideoId string `yaml:"video_id" json:"video_id"` } type Thumbnail interface { @@ -34,27 +35,29 @@ func NewThumbnail(opts ...Option) Thumbnail { } func (t *thumbnail) Set() { - file, err := os.Open(t.file) + file, err := os.Open(t.File) if err != nil { - log.Fatalln(errors.Join(errSetThumbnail, err), t.file) + utils.PrintJSON(t) + log.Fatalln(errors.Join(errSetThumbnail, err), t.File) } - call := service.Thumbnails.Set(t.videoId).Media(file) + call := service.Thumbnails.Set(t.VideoId).Media(file) _, err = call.Do() if err != nil { + utils.PrintJSON(t) log.Fatalln(errors.Join(errSetThumbnail, err)) } - fmt.Printf("Thumbnail set for video ID %v\n", t.videoId) + fmt.Printf("Thumbnail set for video ID %v\n", t.VideoId) } func WithVideoId(videoId string) Option { return func(t *thumbnail) { - t.videoId = videoId + t.VideoId = videoId } } func WithFile(file string) Option { return func(t *thumbnail) { - t.file = file + t.File = file } } diff --git a/pkg/yutuber/thumbnail/thumbnail_test.go b/pkg/yutuber/thumbnail/thumbnail_test.go index d2b11ef..3894b90 100644 --- a/pkg/yutuber/thumbnail/thumbnail_test.go +++ b/pkg/yutuber/thumbnail/thumbnail_test.go @@ -23,8 +23,8 @@ func TestNewThumbnail(t *testing.T) { }, }, want: &thumbnail{ - file: "file", - videoId: "videoId", + File: "file", + VideoId: "videoId", }, }, } diff --git a/pkg/yutuber/video/video.go b/pkg/yutuber/video/video.go index d3178e3..898d5b0 100644 --- a/pkg/yutuber/video/video.go +++ b/pkg/yutuber/video/video.go @@ -24,36 +24,36 @@ var ( ) type video struct { - id string - autoLevels *bool - file string - title string - description string - hl string - tags []string - language string - locale string - license string - thumbnail string - rating string - chart string - channelId string - playlistId string - categoryId string - privacy string - forKids bool - embeddable bool - publishAt string - regionCode string - stabilize *bool - maxHeight int64 - maxWidth int64 - maxResults int64 + ID string `yaml:"id" json:"id"` + AutoLevels *bool `yaml:"auto_levels" json:"auto_levels"` + File string `yaml:"file" json:"file"` + Title string `yaml:"title" json:"title"` + Description string `yaml:"description" json:"description"` + Hl string `yaml:"hl" json:"hl"` + Tags []string `yaml:"tags" json:"tags"` + Language string `yaml:"language" json:"language"` + Locale string `yaml:"locale" json:"locale"` + License string `yaml:"license" json:"license"` + Thumbnail string `yaml:"thumbnail" json:"thumbnail"` + Rating string `yaml:"rating" json:"rating"` + Chart string `yaml:"chart" json:"chart"` + ChannelId string `yaml:"channel_id" json:"channel_id"` + PlaylistId string `yaml:"playlist_id" json:"playlist_id"` + CategoryId string `yaml:"category_id" json:"category_id"` + Privacy string `yaml:"privacy" json:"privacy"` + ForKids bool `yaml:"for_kids" json:"for_kids"` + Embeddable bool `yaml:"embeddable" json:"embeddable"` + PublishAt string `yaml:"publish_at" json:"publish_at"` + RegionCode string `yaml:"region_code" json:"region_code"` + Stabilize *bool `yaml:"stabilize" json:"stabilize"` + MaxHeight int64 `yaml:"max_height" json:"max_height"` + MaxWidth int64 `yaml:"max_width" json:"max_width"` + MaxResults int64 `yaml:"max_results" json:"max_results"` - notifySubscribers bool - publicStatsViewable bool - onBehalfOfContentOwner string - onBehalfOfContentOwnerChannel string + NotifySubscribers bool `yaml:"notify_subscribers" json:"notify_subscribers"` + PublicStatsViewable bool `yaml:"public_stats_viewable" json:"public_stats_viewable"` + OnBehalfOfContentOwner string `yaml:"on_behalf_of_content_owner" json:"on_behalf_of_content_owner"` + OnBehalfOfContentOwnerChannel string `yaml:"on_behalf_of_content_owner_channel" json:"on_behalf_of_content_owner_channel"` } type Video interface { @@ -80,41 +80,42 @@ func NewVideo(opts ...Option) Video { func (v *video) get(parts []string) []*youtube.Video { call := service.Videos.List(parts) - if v.id != "" { - call = call.Id(v.id) + if v.ID != "" { + call = call.Id(v.ID) } - if v.chart != "" { - call = call.Chart(v.chart) + if v.Chart != "" { + call = call.Chart(v.Chart) } - if v.hl != "" { - call = call.Hl(v.hl) + if v.Hl != "" { + call = call.Hl(v.Hl) } - if v.locale != "" { - call = call.Locale(v.locale) + if v.Locale != "" { + call = call.Locale(v.Locale) } - if v.categoryId != "" { - call = call.VideoCategoryId(v.categoryId) + if v.CategoryId != "" { + call = call.VideoCategoryId(v.CategoryId) } - if v.rating != "" { - call = call.MyRating(v.rating) + if v.Rating != "" { + call = call.MyRating(v.Rating) } - if v.regionCode != "" { - call = call.RegionCode(v.regionCode) + if v.RegionCode != "" { + call = call.RegionCode(v.RegionCode) } - if v.maxHeight != 0 { - call = call.MaxHeight(v.maxHeight) + if v.MaxHeight != 0 { + call = call.MaxHeight(v.MaxHeight) } - if v.maxWidth != 0 { - call = call.MaxWidth(v.maxWidth) + if v.MaxWidth != 0 { + call = call.MaxWidth(v.MaxWidth) } - if v.onBehalfOfContentOwner != "" { - call = call.OnBehalfOfContentOwner(v.onBehalfOfContentOwner) + if v.OnBehalfOfContentOwner != "" { + call = call.OnBehalfOfContentOwner(v.OnBehalfOfContentOwner) } - call = call.MaxResults(v.maxResults) + call = call.MaxResults(v.MaxResults) res, err := call.Do() if err != nil { - log.Fatalln(errors.Join(errGetVideo, err), v.id) + utils.PrintJSON(v) + log.Fatalln(errors.Join(errGetVideo, err), v.ID) } return res.Items @@ -136,71 +137,73 @@ func (v *video) List(parts []string, output string) { } func (v *video) Insert() { - file, err := os.Open(v.file) + file, err := os.Open(v.File) if err != nil { - log.Fatalln(errors.Join(errInsertVideo, err), v.file) + utils.PrintJSON(v) + log.Fatalln(errors.Join(errInsertVideo, err), v.File) } defer file.Close() video := &youtube.Video{ Snippet: &youtube.VideoSnippet{ - Title: v.title, - Description: v.description, - Tags: v.tags, - CategoryId: v.categoryId, - ChannelId: v.channelId, - DefaultLanguage: v.language, - DefaultAudioLanguage: v.language, + Title: v.Title, + Description: v.Description, + Tags: v.Tags, + CategoryId: v.CategoryId, + ChannelId: v.ChannelId, + DefaultLanguage: v.Language, + DefaultAudioLanguage: v.Language, }, Status: &youtube.VideoStatus{ - Embeddable: v.embeddable, - License: v.license, - SelfDeclaredMadeForKids: v.forKids, - PublishAt: v.publishAt, - PrivacyStatus: v.privacy, - PublicStatsViewable: v.publicStatsViewable, + Embeddable: v.Embeddable, + License: v.License, + SelfDeclaredMadeForKids: v.ForKids, + PublishAt: v.PublishAt, + PrivacyStatus: v.Privacy, + PublicStatsViewable: v.PublicStatsViewable, ForceSendFields: []string{"SelfDeclaredMadeForKids"}, }, } call := service.Videos.Insert([]string{"snippet,status"}, video) - if v.autoLevels != nil { - call = call.AutoLevels(*v.autoLevels) + if v.AutoLevels != nil { + call = call.AutoLevels(*v.AutoLevels) } - call = call.NotifySubscribers(v.notifySubscribers) - if v.onBehalfOfContentOwner != "" { - call = call.OnBehalfOfContentOwner(v.onBehalfOfContentOwner) + call = call.NotifySubscribers(v.NotifySubscribers) + if v.OnBehalfOfContentOwner != "" { + call = call.OnBehalfOfContentOwner(v.OnBehalfOfContentOwner) } - if v.onBehalfOfContentOwnerChannel != "" { - call = call.OnBehalfOfContentOwnerChannel(v.onBehalfOfContentOwnerChannel) + if v.OnBehalfOfContentOwnerChannel != "" { + call = call.OnBehalfOfContentOwnerChannel(v.OnBehalfOfContentOwnerChannel) } - if v.stabilize != nil { - call = call.Stabilize(*v.stabilize) + if v.Stabilize != nil { + call = call.Stabilize(*v.Stabilize) } res, err := call.Media(file).Do() if err != nil { + utils.PrintJSON(v) log.Fatalln(errors.Join(errInsertVideo, err)) } - if v.thumbnail != "" { + if v.Thumbnail != "" { t := thumbnail.NewThumbnail( - thumbnail.WithVideoId(v.id), - thumbnail.WithFile(v.thumbnail), + thumbnail.WithVideoId(v.ID), + thumbnail.WithFile(v.Thumbnail), thumbnail.WithService(service), ) t.Set() } - if v.playlistId != "" { + if v.PlaylistId != "" { pi := playlistItem.NewPlaylistItem( - playlistItem.WithTitle(v.title), - playlistItem.WithDescription(v.description), + playlistItem.WithTitle(v.Title), + playlistItem.WithDescription(v.Description), playlistItem.WithVideoId(res.Id), - playlistItem.WithPlaylistId(v.playlistId), - playlistItem.WithChannelId(v.channelId), - playlistItem.WithPrivacy(v.privacy), + playlistItem.WithPlaylistId(v.PlaylistId), + playlistItem.WithChannelId(v.ChannelId), + playlistItem.WithPrivacy(v.Privacy), playlistItem.WithService(service), ) pi.Insert() @@ -212,57 +215,58 @@ func (v *video) Insert() { func (v *video) Update() { video := v.get([]string{"id", "snippet", "status"})[0] - if v.title != "" { - video.Snippet.Title = v.title + if v.Title != "" { + video.Snippet.Title = v.Title } - if v.description != "" { - video.Snippet.Description = v.description + if v.Description != "" { + video.Snippet.Description = v.Description } - if v.tags != nil { - video.Snippet.Tags = v.tags + if v.Tags != nil { + video.Snippet.Tags = v.Tags } - if v.language != "" { - video.Snippet.DefaultLanguage = v.language - video.Snippet.DefaultAudioLanguage = v.language + if v.Language != "" { + video.Snippet.DefaultLanguage = v.Language + video.Snippet.DefaultAudioLanguage = v.Language } - if v.license != "" { - video.Status.License = v.license + if v.License != "" { + video.Status.License = v.License } - if v.categoryId != "" { - video.Snippet.CategoryId = v.categoryId + if v.CategoryId != "" { + video.Snippet.CategoryId = v.CategoryId } - if v.privacy != "" { - video.Status.PrivacyStatus = v.privacy + if v.Privacy != "" { + video.Status.PrivacyStatus = v.Privacy } - video.Status.Embeddable = v.embeddable + video.Status.Embeddable = v.Embeddable call := service.Videos.Update([]string{"snippet,status"}, video) - if v.onBehalfOfContentOwner != "" { - call = call.OnBehalfOfContentOwner(v.onBehalfOfContentOwner) + if v.OnBehalfOfContentOwner != "" { + call = call.OnBehalfOfContentOwner(v.OnBehalfOfContentOwner) } res, err := call.Do() if err != nil { - log.Fatalln(errors.Join(errUpdateVideo, err), v.id) + utils.PrintJSON(v) + log.Fatalln(errors.Join(errUpdateVideo, err), v.ID) } - if v.thumbnail != "" { + if v.Thumbnail != "" { t := thumbnail.NewThumbnail( - thumbnail.WithVideoId(v.id), - thumbnail.WithFile(v.thumbnail), + thumbnail.WithVideoId(v.ID), + thumbnail.WithFile(v.Thumbnail), thumbnail.WithService(service), ) t.Set() } - if v.playlistId != "" { + if v.PlaylistId != "" { pi := playlistItem.NewPlaylistItem( - playlistItem.WithTitle(v.title), - playlistItem.WithDescription(v.description), + playlistItem.WithTitle(v.Title), + playlistItem.WithDescription(v.Description), playlistItem.WithVideoId(res.Id), - playlistItem.WithPlaylistId(v.playlistId), - playlistItem.WithChannelId(v.channelId), - playlistItem.WithPrivacy(v.privacy), + playlistItem.WithPlaylistId(v.PlaylistId), + playlistItem.WithChannelId(v.ChannelId), + playlistItem.WithPrivacy(v.Privacy), playlistItem.WithService(service), ) pi.Insert() @@ -273,215 +277,218 @@ func (v *video) Update() { } func (v *video) Rate() { - call := service.Videos.Rate(v.id, v.rating) + call := service.Videos.Rate(v.ID, v.Rating) err := call.Do() if err != nil { - log.Fatalln(errors.Join(errRating, err), v.id) + utils.PrintJSON(v) + log.Fatalln(errors.Join(errRating, err), v.ID) } - fmt.Printf("Video %s rated %s\n", v.id, v.rating) + fmt.Printf("Video %s rated %s\n", v.ID, v.Rating) } func (v *video) GetRating() { - call := service.Videos.GetRating([]string{v.id}) - if v.onBehalfOfContentOwner != "" { - call = call.OnBehalfOfContentOwner(v.onBehalfOfContentOwnerChannel) + call := service.Videos.GetRating([]string{v.ID}) + if v.OnBehalfOfContentOwner != "" { + call = call.OnBehalfOfContentOwner(v.OnBehalfOfContentOwnerChannel) } res, err := call.Do() if err != nil { - log.Fatalln(errors.Join(errGetRating, err), v.id) + utils.PrintJSON(v) + log.Fatalln(errors.Join(errGetRating, err), v.ID) } utils.PrintYAML(res) } func (v *video) Delete() { - call := service.Videos.Delete(v.id) - if v.onBehalfOfContentOwner != "" { - call = call.OnBehalfOfContentOwner(v.onBehalfOfContentOwner) + call := service.Videos.Delete(v.ID) + if v.OnBehalfOfContentOwner != "" { + call = call.OnBehalfOfContentOwner(v.OnBehalfOfContentOwner) } err := call.Do() if err != nil { + utils.PrintJSON(v) log.Fatalln(errors.Join(errDeleteVideo, err)) } - fmt.Printf("Video %s deleted", v.id) + fmt.Printf("Video %s deleted", v.ID) } -func WithId(id string) Option { +func WithID(id string) Option { return func(v *video) { - v.id = id + v.ID = id } } func WithAutoLevels(autoLevels bool, changed bool) Option { return func(v *video) { if changed { - v.autoLevels = &autoLevels + v.AutoLevels = &autoLevels } } } func WithFile(file string) Option { return func(v *video) { - v.file = file + v.File = file } } func WithTitle(title string) Option { return func(v *video) { - v.title = title + v.Title = title } } func WithDescription(description string) Option { return func(v *video) { - v.description = description + v.Description = description } } func WithHl(hl string) Option { return func(v *video) { - v.hl = hl + v.Hl = hl } } func WithTags(tags []string) Option { return func(v *video) { - v.tags = tags + v.Tags = tags } } func WithLanguage(language string) Option { return func(v *video) { - v.language = language + v.Language = language } } func WithLocale(locale string) Option { return func(v *video) { - v.locale = locale + v.Locale = locale } } func WithLicense(license string) Option { return func(v *video) { - v.license = license + v.License = license } } func WithThumbnail(thumbnail string) Option { return func(v *video) { - v.thumbnail = thumbnail + v.Thumbnail = thumbnail } } func WithRating(rating string) Option { return func(v *video) { - v.rating = rating + v.Rating = rating } } func WithChart(chart string) Option { return func(v *video) { - v.chart = chart + v.Chart = chart } } func WithForKids(forKids bool) Option { return func(v *video) { - v.forKids = forKids + v.ForKids = forKids } } func WithEmbeddable(embeddable bool) Option { return func(v *video) { - v.embeddable = embeddable + v.Embeddable = embeddable } } func WithCategory(categoryId string) Option { return func(v *video) { - v.categoryId = categoryId + v.CategoryId = categoryId } } func WithPrivacy(privacy string) Option { return func(v *video) { - v.privacy = privacy + v.Privacy = privacy } } func WithChannelId(channelId string) Option { return func(v *video) { - v.channelId = channelId + v.ChannelId = channelId } } func WithPlaylistId(playlistId string) Option { return func(v *video) { - v.playlistId = playlistId + v.PlaylistId = playlistId } } func WithPublicStatsViewable(publicStatsViewable bool) Option { return func(v *video) { - v.publicStatsViewable = publicStatsViewable + v.PublicStatsViewable = publicStatsViewable } } func WithPublishAt(publishAt string) Option { return func(v *video) { - v.publishAt = publishAt + v.PublishAt = publishAt } } func WithRegionCode(regionCode string) Option { return func(v *video) { - v.regionCode = regionCode + v.RegionCode = regionCode } } func WithStabilize(stabilize bool, changed bool) Option { return func(v *video) { if changed { - v.stabilize = &stabilize + v.Stabilize = &stabilize } } } func WithMaxHeight(maxHeight int64) Option { return func(v *video) { - v.maxHeight = maxHeight + v.MaxHeight = maxHeight } } func WithMaxWidth(maxWidth int64) Option { return func(v *video) { - v.maxWidth = maxWidth + v.MaxWidth = maxWidth } } func WithMaxResults(maxResults int64) Option { return func(v *video) { - v.maxResults = maxResults + v.MaxResults = maxResults } } func WithNotifySubscribers(notifySubscribers bool) Option { return func(v *video) { - v.notifySubscribers = notifySubscribers + v.NotifySubscribers = notifySubscribers } } func WithOnBehalfOfContentOwner(onBehalfOfContentOwner string) Option { return func(v *video) { - v.onBehalfOfContentOwner = onBehalfOfContentOwner + v.OnBehalfOfContentOwner = onBehalfOfContentOwner } } func WithOnBehalfOfContentOwnerChannel(onBehalfOfContentOwnerChannel string) Option { return func(v *video) { - v.onBehalfOfContentOwnerChannel = onBehalfOfContentOwnerChannel + v.OnBehalfOfContentOwnerChannel = onBehalfOfContentOwnerChannel } } diff --git a/pkg/yutuber/video/video_test.go b/pkg/yutuber/video/video_test.go index bfe5da1..55f96f6 100644 --- a/pkg/yutuber/video/video_test.go +++ b/pkg/yutuber/video/video_test.go @@ -18,7 +18,7 @@ func TestNewVideo(t *testing.T) { name: "TestNewVideo", args: args{ opts: []Option{ - WithId("id"), + WithID("id"), WithAutoLevels(true, true), WithFile("file"), WithTitle("title"), @@ -31,16 +31,16 @@ func TestNewVideo(t *testing.T) { }, }, want: &video{ - id: "id", - autoLevels: &[]bool{true}[0], - file: "file", - title: "title", - description: "description", - hl: "hl", - tags: []string{"tag1", "tag2"}, - language: "language", - locale: "locale", - license: "license", + ID: "id", + AutoLevels: &[]bool{true}[0], + File: "file", + Title: "title", + Description: "description", + Hl: "hl", + Tags: []string{"tag1", "tag2"}, + Language: "language", + Locale: "locale", + License: "license", }, }, } diff --git a/pkg/yutuber/videoAbuseReportReason/videoAbuseReportReason.go b/pkg/yutuber/videoAbuseReportReason/videoAbuseReportReason.go index 26c07be..1e72dda 100644 --- a/pkg/yutuber/videoAbuseReportReason/videoAbuseReportReason.go +++ b/pkg/yutuber/videoAbuseReportReason/videoAbuseReportReason.go @@ -15,7 +15,7 @@ var ( ) type videoAbuseReportReason struct { - hl string + Hl string `yaml:"hl" json:"hl"` } type VideoAbuseReportReason interface { @@ -33,22 +33,23 @@ func NewVideoAbuseReportReason(opt ...Option) VideoAbuseReportReason { return va } -func (vc *videoAbuseReportReason) get(parts []string) []*youtube.VideoAbuseReportReason { +func (va *videoAbuseReportReason) get(parts []string) []*youtube.VideoAbuseReportReason { call := service.VideoAbuseReportReasons.List(parts) - if vc.hl != "" { - call = call.Hl(vc.hl) + if va.Hl != "" { + call = call.Hl(va.Hl) } res, err := call.Do() if err != nil { + utils.PrintJSON(va) log.Fatalln(errors.Join(errGetVideoAbuseReportReason, err)) } return res.Items } -func (vc *videoAbuseReportReason) List(parts []string, output string) { - videoAbuseReportReasons := vc.get(parts) +func (va *videoAbuseReportReason) List(parts []string, output string) { + videoAbuseReportReasons := va.get(parts) switch output { case "json": utils.PrintJSON(videoAbuseReportReasons) @@ -67,7 +68,7 @@ func (vc *videoAbuseReportReason) List(parts []string, output string) { func WithHL(hl string) Option { return func(vc *videoAbuseReportReason) { - vc.hl = hl + vc.Hl = hl } } diff --git a/pkg/yutuber/videoAbuseReportReason/videoAbuseReportReason_test.go b/pkg/yutuber/videoAbuseReportReason/videoAbuseReportReason_test.go index 59bf80d..063accf 100644 --- a/pkg/yutuber/videoAbuseReportReason/videoAbuseReportReason_test.go +++ b/pkg/yutuber/videoAbuseReportReason/videoAbuseReportReason_test.go @@ -22,7 +22,7 @@ func TestNewVideoAbuseReportReason(t *testing.T) { }, }, want: &videoAbuseReportReason{ - hl: "hl", + Hl: "hl", }, }, } diff --git a/pkg/yutuber/videoCategory/videoCategory.go b/pkg/yutuber/videoCategory/videoCategory.go index c81caa6..e43dbc3 100644 --- a/pkg/yutuber/videoCategory/videoCategory.go +++ b/pkg/yutuber/videoCategory/videoCategory.go @@ -16,9 +16,9 @@ var ( ) type videoCategory struct { - id string - hl string - regionCode string + ID string `yaml:"id" json:"id"` + Hl string `yaml:"hl" json:"hl"` + RegionCode string `yaml:"region_code" json:"region_code"` } type VideoCategory interface { @@ -38,19 +38,20 @@ func NewVideoCategory(opt ...Option) VideoCategory { func (vc *videoCategory) get(parts []string) []*youtube.VideoCategory { call := service.VideoCategories.List(parts) - if vc.id != "" { - call = call.Id(vc.id) + if vc.ID != "" { + call = call.Id(vc.ID) } - if vc.hl != "" { - call = call.Hl(vc.hl) + if vc.Hl != "" { + call = call.Hl(vc.Hl) } - if vc.regionCode != "" { - call = call.RegionCode(vc.regionCode) + if vc.RegionCode != "" { + call = call.RegionCode(vc.RegionCode) } res, err := call.Do() if err != nil { - log.Fatalln(errors.Join(errGetVideoCategory, err), vc.regionCode) + utils.PrintJSON(vc) + log.Fatalln(errors.Join(errGetVideoCategory, err), vc.RegionCode) } return res.Items @@ -74,21 +75,21 @@ func (vc *videoCategory) List(parts []string, output string) { } } -func WithId(id string) Option { +func WithID(id string) Option { return func(vc *videoCategory) { - vc.id = id + vc.ID = id } } func WithHl(hl string) Option { return func(vc *videoCategory) { - vc.hl = hl + vc.Hl = hl } } func WithRegionCode(regionCode string) Option { return func(vc *videoCategory) { - vc.regionCode = regionCode + vc.RegionCode = regionCode } } diff --git a/pkg/yutuber/videoCategory/videoCategory_test.go b/pkg/yutuber/videoCategory/videoCategory_test.go index 2a46d07..9ef1332 100644 --- a/pkg/yutuber/videoCategory/videoCategory_test.go +++ b/pkg/yutuber/videoCategory/videoCategory_test.go @@ -18,15 +18,15 @@ func TestNewVideoCategory(t *testing.T) { name: "TestNewVideoCategory", args: args{ opt: []Option{ - WithId("id"), + WithID("id"), WithHl("hl"), WithRegionCode("regionCode"), }, }, want: &videoCategory{ - id: "id", - hl: "hl", - regionCode: "regionCode", + ID: "id", + Hl: "hl", + RegionCode: "regionCode", }, }, } diff --git a/pkg/yutuber/watermark/watermark.go b/pkg/yutuber/watermark/watermark.go index d6381f0..02f6bd1 100644 --- a/pkg/yutuber/watermark/watermark.go +++ b/pkg/yutuber/watermark/watermark.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "github.com/eat-pray-ai/yutu/pkg/auth" + "github.com/eat-pray-ai/yutu/pkg/utils" "google.golang.org/api/youtube/v3" "log" "os" @@ -16,13 +17,13 @@ var ( ) type watermark struct { - channelId string - file string - inVideoPosition string - durationMs uint64 - offsetMs uint64 - offsetType string - onBehalfOfContentOwner string + ChannelId string `yaml:"channel_id" json:"channel_id"` + File string `yaml:"file" json:"file"` + InVideoPosition string `yaml:"in_video_position" json:"in_video_position"` + DurationMs uint64 `yaml:"duration_ms" json:"duration_ms"` + OffsetMs uint64 `yaml:"offset_ms" json:"offset_ms"` + OffsetType string `yaml:"offset_type" json:"offset_type"` + OnBehalfOfContentOwner string `yaml:"on_behalf_of_content_owner" json:"on_behalf_of_content_owner"` } type Watermark interface { @@ -42,37 +43,39 @@ func NewWatermark(opts ...Option) Watermark { return w } -func (w watermark) Set() { - file, err := os.Open(w.file) +func (w *watermark) Set() { + file, err := os.Open(w.File) if err != nil { - log.Fatalln(errors.Join(errSetWatermark, err), w.file) + utils.PrintJSON(w) + log.Fatalln(errors.Join(errSetWatermark, err), w.File) } defer file.Close() inVideoBranding := &youtube.InvideoBranding{ Position: &youtube.InvideoPosition{}, Timing: &youtube.InvideoTiming{}, } - if w.inVideoPosition != "" { + if w.InVideoPosition != "" { inVideoBranding.Position.Type = "corner" - inVideoBranding.Position.CornerPosition = w.inVideoPosition + inVideoBranding.Position.CornerPosition = w.InVideoPosition } - if w.durationMs != 0 { - inVideoBranding.Timing.DurationMs = w.durationMs + if w.DurationMs != 0 { + inVideoBranding.Timing.DurationMs = w.DurationMs } - if w.offsetMs != 0 { - inVideoBranding.Timing.OffsetMs = w.offsetMs + if w.OffsetMs != 0 { + inVideoBranding.Timing.OffsetMs = w.OffsetMs } - if w.offsetType != "" { - inVideoBranding.Timing.Type = w.offsetType + if w.OffsetType != "" { + inVideoBranding.Timing.Type = w.OffsetType } - call := service.Watermarks.Set(w.channelId, inVideoBranding).Media(file) - if w.onBehalfOfContentOwner != "" { - call = call.OnBehalfOfContentOwner(w.onBehalfOfContentOwner) + call := service.Watermarks.Set(w.ChannelId, inVideoBranding).Media(file) + if w.OnBehalfOfContentOwner != "" { + call = call.OnBehalfOfContentOwner(w.OnBehalfOfContentOwner) } err = call.Do() if err != nil { + utils.PrintJSON(w) log.Fatalln(errors.Join(errSetWatermark, err)) } fmt.Println("Watermark set done") @@ -80,13 +83,14 @@ func (w watermark) Set() { } func (w *watermark) Unset() { - call := service.Watermarks.Unset(w.channelId) - if w.onBehalfOfContentOwner != "" { - call = call.OnBehalfOfContentOwner(w.onBehalfOfContentOwner) + call := service.Watermarks.Unset(w.ChannelId) + if w.OnBehalfOfContentOwner != "" { + call = call.OnBehalfOfContentOwner(w.OnBehalfOfContentOwner) } err := call.Do() if err != nil { + utils.PrintJSON(w) log.Fatalln(errors.Join(errUnsetWatermark, err)) } @@ -95,43 +99,43 @@ func (w *watermark) Unset() { func WithChannelId(channelId string) Option { return func(w *watermark) { - w.channelId = channelId + w.ChannelId = channelId } } func WithFile(file string) Option { return func(w *watermark) { - w.file = file + w.File = file } } func WithInVideoPosition(inVideoPosition string) Option { return func(w *watermark) { - w.inVideoPosition = inVideoPosition + w.InVideoPosition = inVideoPosition } } func WithDurationMs(durationMs uint64) Option { return func(w *watermark) { - w.durationMs = durationMs + w.DurationMs = durationMs } } func WithOffsetMs(offsetMs uint64) Option { return func(w *watermark) { - w.offsetMs = offsetMs + w.OffsetMs = offsetMs } } func WithOffsetType(offsetType string) Option { return func(w *watermark) { - w.offsetType = offsetType + w.OffsetType = offsetType } } func WithOnBehalfOfContentOwner(onBehalfOfContentOwner string) Option { return func(w *watermark) { - w.onBehalfOfContentOwner = onBehalfOfContentOwner + w.OnBehalfOfContentOwner = onBehalfOfContentOwner } } diff --git a/pkg/yutuber/watermark/watermark_test.go b/pkg/yutuber/watermark/watermark_test.go index 5c5df46..68c0654 100644 --- a/pkg/yutuber/watermark/watermark_test.go +++ b/pkg/yutuber/watermark/watermark_test.go @@ -28,13 +28,13 @@ func TestNewWatermark(t *testing.T) { }, }, want: &watermark{ - channelId: "channelId", - file: "file", - inVideoPosition: "topRight", - durationMs: 1024, - offsetMs: 31415, - offsetType: "offsetFromEnd", - onBehalfOfContentOwner: "contentOwner", + ChannelId: "channelId", + File: "file", + InVideoPosition: "topRight", + DurationMs: 1024, + OffsetMs: 31415, + OffsetType: "offsetFromEnd", + OnBehalfOfContentOwner: "contentOwner", }, }, }