From 95ccdf5652df28cfbd74626221d32641adfa5617 Mon Sep 17 00:00:00 2001 From: chaoqun <27287694+OpenWaygate@users.noreply.github.com> Date: Mon, 24 Jun 2024 22:58:53 +0800 Subject: [PATCH] :recycle: Allow service reuse --- cmd/activity/list.go | 2 +- cmd/caption/delete.go | 2 +- cmd/caption/insert.go | 2 +- cmd/caption/list.go | 2 +- cmd/caption/update.go | 2 +- cmd/channel/list.go | 2 +- cmd/channel/update.go | 2 +- cmd/channelBanner/insert.go | 2 +- cmd/channelSection/delete.go | 1 + cmd/channelSection/list.go | 1 + cmd/i18nLanguage/list.go | 2 +- cmd/i18nRegion/list.go | 2 +- cmd/member/list.go | 2 +- cmd/membershipsLevel/list.go | 2 +- cmd/playlist/delete.go | 2 +- cmd/playlist/insert.go | 2 +- cmd/playlist/list.go | 2 +- cmd/playlist/update.go | 2 +- cmd/playlistItem/delete.go | 2 +- cmd/playlistItem/insert.go | 2 +- cmd/playlistItem/list.go | 2 +- cmd/playlistItem/update.go | 2 +- cmd/search/list.go | 2 +- cmd/subscription/delete.go | 2 +- cmd/subscription/insert.go | 2 +- cmd/subscription/list.go | 2 +- cmd/thumbnail/set.go | 2 +- cmd/video/getRating.go | 2 +- cmd/video/insert.go | 2 +- cmd/video/list.go | 2 +- cmd/video/rate.go | 2 +- cmd/video/update.go | 2 +- cmd/videoAbuseReportReason/list.go | 2 +- cmd/videoCategory/list.go | 2 +- cmd/watermark/set.go | 1 + cmd/watermark/unset.go | 5 ++++- pkg/yutuber/activity/activity.go | 8 ++++++-- pkg/yutuber/caption/caption.go | 8 ++++++-- pkg/yutuber/channel/channel.go | 8 ++++++-- pkg/yutuber/channelBanner/channelBanner.go | 8 ++++++-- pkg/yutuber/channelSection/channelSection.go | 11 +++++++++++ pkg/yutuber/i18nLanguage/i18nLanguage.go | 8 ++++++-- pkg/yutuber/i18nRegion/i18nRegion.go | 8 ++++++-- pkg/yutuber/member/member.go | 8 ++++++-- .../membershipsLevel/membershipsLevel.go | 8 ++++++-- pkg/yutuber/playlist/playlist.go | 8 ++++++-- pkg/yutuber/playlistItem/playlistItem.go | 10 +++++++--- pkg/yutuber/search/search.go | 8 ++++++-- pkg/yutuber/subscription/subscription.go | 8 ++++++-- pkg/yutuber/thumbnail/thumbnail.go | 8 ++++++-- pkg/yutuber/video/video.go | 18 +++++++++++------- .../videoAbuseReportReason.go | 8 ++++++-- pkg/yutuber/videoCategory/videoCategory.go | 10 +++++++--- pkg/yutuber/watermark/watermark.go | 8 ++++++-- 54 files changed, 159 insertions(+), 74 deletions(-) diff --git a/cmd/activity/list.go b/cmd/activity/list.go index 1536a32..22a8a23 100644 --- a/cmd/activity/list.go +++ b/cmd/activity/list.go @@ -18,7 +18,7 @@ var listCmd = &cobra.Command{ activity.WithPublishedAfter(publishedAfter), activity.WithPublishedBefore(publishedBefore), activity.WithRegionCode(regionCode), - activity.WithService(), + activity.WithService(nil), ) a.List(parts, output) }, diff --git a/cmd/caption/delete.go b/cmd/caption/delete.go index 1213bf8..8dd74e5 100644 --- a/cmd/caption/delete.go +++ b/cmd/caption/delete.go @@ -14,7 +14,7 @@ var deleteCmd = &cobra.Command{ caption.WithId(id), caption.WithOnBehalfOf(onBehalfOf), caption.WithOnBehalfOfContentOwner(onBehalfOfContentOwner), - caption.WithService(), + caption.WithService(nil), ) c.Delete() }, diff --git a/cmd/caption/insert.go b/cmd/caption/insert.go index 685523f..f33b6a9 100644 --- a/cmd/caption/insert.go +++ b/cmd/caption/insert.go @@ -24,7 +24,7 @@ var insertCmd = &cobra.Command{ caption.WithOnBehalfOf(onBehalfOf), caption.WithOnBehalfOfContentOwner(onBehalfOfContentOwner), caption.WithVideoId(videoId), - caption.WithService(), + caption.WithService(nil), ) c.Insert() }, diff --git a/cmd/caption/list.go b/cmd/caption/list.go index d7ddbd5..71703e5 100644 --- a/cmd/caption/list.go +++ b/cmd/caption/list.go @@ -15,7 +15,7 @@ var listCmd = &cobra.Command{ caption.WithVideoId(videoId), caption.WithOnBehalfOf(onBehalfOf), caption.WithOnBehalfOfContentOwner(onBehalfOfContentOwner), - caption.WithService(), + caption.WithService(nil), ) c.List(parts, output) }, diff --git a/cmd/caption/update.go b/cmd/caption/update.go index e06b611..69450f6 100644 --- a/cmd/caption/update.go +++ b/cmd/caption/update.go @@ -24,7 +24,7 @@ var updateCmd = &cobra.Command{ caption.WithOnBehalfOf(onBehalfOf), caption.WithOnBehalfOfContentOwner(onBehalfOfContentOwner), caption.WithVideoId(videoId), - caption.WithService(), + caption.WithService(nil), ) c.Update() }, diff --git a/cmd/channel/list.go b/cmd/channel/list.go index de6cacc..9255f43 100644 --- a/cmd/channel/list.go +++ b/cmd/channel/list.go @@ -21,7 +21,7 @@ var listCmd = &cobra.Command{ channel.WithMine(mine, true), channel.WithMySubscribers(mySubscribers, true), channel.WithOnBehalfOfContentOwner(onBehalfOfContentOwner), - channel.WithService(), + channel.WithService(nil), ) c.List(parts, output) }, diff --git a/cmd/channel/update.go b/cmd/channel/update.go index 186a7b2..9fb5fe0 100644 --- a/cmd/channel/update.go +++ b/cmd/channel/update.go @@ -17,7 +17,7 @@ var updateCmd = &cobra.Command{ channel.WithDefaultLanguage(defaultLanguage), channel.WithDescription(description), channel.WithTitle(title), - channel.WithService(), + channel.WithService(nil), ) c.Update() }, diff --git a/cmd/channelBanner/insert.go b/cmd/channelBanner/insert.go index 94f08fc..5e9b1d5 100644 --- a/cmd/channelBanner/insert.go +++ b/cmd/channelBanner/insert.go @@ -14,7 +14,7 @@ var insertCmd = &cobra.Command{ channelBanner.WithFile(file), channelBanner.WithOnBehalfOfContentOwner(onBehalfOfContentOwner), channelBanner.WithOnBehalfOfContentOwnerChannel(onBehalfOfContentOwnerChannel), - channelBanner.WithService(), + channelBanner.WithService(nil), ) cb.Insert() }, diff --git a/cmd/channelSection/delete.go b/cmd/channelSection/delete.go index 8a07100..bbe23b1 100644 --- a/cmd/channelSection/delete.go +++ b/cmd/channelSection/delete.go @@ -13,6 +13,7 @@ var deleteCmd = &cobra.Command{ cs := channelSection.NewChannelSection( channelSection.WithId(id), channelSection.WithOnBehalfOfContentOwner(onBehalfOfContentOwner), + channelSection.WithService(nil), ) cs.Delete() }, diff --git a/cmd/channelSection/list.go b/cmd/channelSection/list.go index 1cb06a8..1562119 100644 --- a/cmd/channelSection/list.go +++ b/cmd/channelSection/list.go @@ -16,6 +16,7 @@ var listCmd = &cobra.Command{ channelSection.WithHl(hl), channelSection.WithMine(mine, true), channelSection.WithOnBehalfOfContentOwner(onBehalfOfContentOwner), + channelSection.WithService(nil), ) cs.List(parts, output) }, diff --git a/cmd/i18nLanguage/list.go b/cmd/i18nLanguage/list.go index 34e826b..603f0d0 100644 --- a/cmd/i18nLanguage/list.go +++ b/cmd/i18nLanguage/list.go @@ -11,7 +11,7 @@ var listCmd = &cobra.Command{ Long: "List i18nLanguages' id, hl, and name", Run: func(cmd *cobra.Command, args []string) { i := i18nLanguage.NewI18nLanguage( - i18nLanguage.WithHl(hl), i18nLanguage.WithService(), + i18nLanguage.WithHl(hl), i18nLanguage.WithService(nil), ) i.List(parts, output) }, diff --git a/cmd/i18nRegion/list.go b/cmd/i18nRegion/list.go index 78e37b6..d320987 100644 --- a/cmd/i18nRegion/list.go +++ b/cmd/i18nRegion/list.go @@ -11,7 +11,7 @@ var listCmd = &cobra.Command{ Long: "List i18nRegions' id, hl, and name", Run: func(cmd *cobra.Command, args []string) { i := i18nRegion.NewI18nRegion( - i18nRegion.WithHl(hl), i18nRegion.WithService(), + i18nRegion.WithHl(hl), i18nRegion.WithService(nil), ) i.List(parts, output) }, diff --git a/cmd/member/list.go b/cmd/member/list.go index dfe1764..3ea6fad 100644 --- a/cmd/member/list.go +++ b/cmd/member/list.go @@ -15,7 +15,7 @@ var listCmd = &cobra.Command{ member.WithHasAccessToLevel(hasAccessToLevel), member.WithMaxResults(maxResults), member.WithMode(mode), - member.WithService(), + member.WithService(nil), ) m.List(parts, output) }, diff --git a/cmd/membershipsLevel/list.go b/cmd/membershipsLevel/list.go index ee9b2b4..03b807d 100644 --- a/cmd/membershipsLevel/list.go +++ b/cmd/membershipsLevel/list.go @@ -10,7 +10,7 @@ var listCmd = &cobra.Command{ Short: "List memberships levels", Long: "List memberships levels' info, such as id, displayName, etc.", Run: func(cmd *cobra.Command, args []string) { - m := membershipsLevel.NewMembershipsLevel(membershipsLevel.WithService()) + m := membershipsLevel.NewMembershipsLevel(membershipsLevel.WithService(nil)) m.List(parts, output) }, } diff --git a/cmd/playlist/delete.go b/cmd/playlist/delete.go index 7e508ae..69a77f7 100644 --- a/cmd/playlist/delete.go +++ b/cmd/playlist/delete.go @@ -13,7 +13,7 @@ var deleteCmd = &cobra.Command{ p := playlist.NewPlaylist( playlist.WithId(id), playlist.WithOnBehalfOfContentOwner(onBehalfOfContentOwner), - playlist.WithService(), + playlist.WithService(nil), ) p.Delete() }, diff --git a/cmd/playlist/insert.go b/cmd/playlist/insert.go index bba821f..42ce41d 100644 --- a/cmd/playlist/insert.go +++ b/cmd/playlist/insert.go @@ -17,7 +17,7 @@ var insertCmd = &cobra.Command{ playlist.WithLanguage(language), playlist.WithChannelId(channelId), playlist.WithPrivacy(privacy), - playlist.WithService(), + playlist.WithService(nil), ) p.Insert() }, diff --git a/cmd/playlist/list.go b/cmd/playlist/list.go index 52dc4b5..be75a67 100644 --- a/cmd/playlist/list.go +++ b/cmd/playlist/list.go @@ -19,7 +19,7 @@ var listCmd = &cobra.Command{ playlist.WithMine(mine, true), playlist.WithOnBehalfOfContentOwner(onBehalfOfContentOwner), playlist.WithOnBehalfOfContentOwnerChannel(onBehalfOfContentOwnerChannel), - playlist.WithService(), + playlist.WithService(nil), ) p.List(parts, output) }, diff --git a/cmd/playlist/update.go b/cmd/playlist/update.go index c8f6a84..8951bf9 100644 --- a/cmd/playlist/update.go +++ b/cmd/playlist/update.go @@ -17,7 +17,7 @@ var updateCmd = &cobra.Command{ playlist.WithTags(tags), playlist.WithLanguage(language), playlist.WithPrivacy(privacy), - playlist.WithService(), + playlist.WithService(nil), ) p.Update() }, diff --git a/cmd/playlistItem/delete.go b/cmd/playlistItem/delete.go index 1a382a6..e4553c1 100644 --- a/cmd/playlistItem/delete.go +++ b/cmd/playlistItem/delete.go @@ -13,7 +13,7 @@ var deleteCmd = &cobra.Command{ pi := playlistItem.NewPlaylistItem( playlistItem.WithId(id), playlistItem.WithOnBehalfOfContentOwner(onBehalfOfContentOwner), - playlistItem.WithService(), + playlistItem.WithService(nil), ) pi.Delete() }, diff --git a/cmd/playlistItem/insert.go b/cmd/playlistItem/insert.go index 1616036..27cbc49 100644 --- a/cmd/playlistItem/insert.go +++ b/cmd/playlistItem/insert.go @@ -19,7 +19,7 @@ var insertCmd = &cobra.Command{ playlistItem.WithKPlaylistId(kPlaylistId), playlistItem.WithPlaylistId(playlistId), playlistItem.WithPrivacy(privacy), - playlistItem.WithService(), + playlistItem.WithService(nil), ) pi.Insert() }, diff --git a/cmd/playlistItem/list.go b/cmd/playlistItem/list.go index b47215a..5ad5cbf 100644 --- a/cmd/playlistItem/list.go +++ b/cmd/playlistItem/list.go @@ -16,7 +16,7 @@ var listCmd = &cobra.Command{ playlistItem.WithMaxResults(maxResults), playlistItem.WithVideoId(videoId), playlistItem.WithOnBehalfOfContentOwner(onBehalfOfContentOwner), - playlistItem.WithService(), + playlistItem.WithService(nil), ) pi.List(parts, output) }, diff --git a/cmd/playlistItem/update.go b/cmd/playlistItem/update.go index 27d232b..8753ccc 100644 --- a/cmd/playlistItem/update.go +++ b/cmd/playlistItem/update.go @@ -15,7 +15,7 @@ var updateCmd = &cobra.Command{ playlistItem.WithTitle(title), playlistItem.WithDescription(description), playlistItem.WithPrivacy(privacy), - playlistItem.WithService(), + playlistItem.WithService(nil), ) pi.Update() }, diff --git a/cmd/search/list.go b/cmd/search/list.go index f54f415..7a08059 100644 --- a/cmd/search/list.go +++ b/cmd/search/list.go @@ -40,7 +40,7 @@ var listCmd = &cobra.Command{ search.WithVideoPaidProductPlacement(videoPaidProductPlacement), search.WithVideoSyndicated(videoSyndicated), search.WithVideoType(videoType), - search.WithService(), + search.WithService(nil), ) s.List(parts, output) }, diff --git a/cmd/subscription/delete.go b/cmd/subscription/delete.go index 1737e7a..8aa2e26 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(), + subscription.WithId(id), subscription.WithService(nil), ) s.Delete() }, diff --git a/cmd/subscription/insert.go b/cmd/subscription/insert.go index 4e05511..5791302 100644 --- a/cmd/subscription/insert.go +++ b/cmd/subscription/insert.go @@ -15,7 +15,7 @@ var insertCmd = &cobra.Command{ subscription.WithDescription(description), subscription.WithChannelId(channelId), subscription.WithTitle(title), - subscription.WithService(), + subscription.WithService(nil), ) s.Insert() }, diff --git a/cmd/subscription/list.go b/cmd/subscription/list.go index 4c03f9a..467b7ea 100644 --- a/cmd/subscription/list.go +++ b/cmd/subscription/list.go @@ -21,7 +21,7 @@ var listCmd = &cobra.Command{ subscription.WithOnBehalfOfContentOwner(onBehalfOfContentOwner), subscription.WithOnBehalfOfContentOwnerChannel(onBehalfOfContentOwnerChannel), subscription.WithOrder(order), - subscription.WithService(), + subscription.WithService(nil), ) s.List(parts, output) }, diff --git a/cmd/thumbnail/set.go b/cmd/thumbnail/set.go index eb66672..742cac6 100644 --- a/cmd/thumbnail/set.go +++ b/cmd/thumbnail/set.go @@ -13,7 +13,7 @@ var setCmd = &cobra.Command{ t := thumbnail.NewThumbnail( thumbnail.WithFile(file), thumbnail.WithVideoId(videoId), - thumbnail.WithService(), + thumbnail.WithService(nil), ) t.Set() }, diff --git a/cmd/video/getRating.go b/cmd/video/getRating.go index 3baf14a..86f430e 100644 --- a/cmd/video/getRating.go +++ b/cmd/video/getRating.go @@ -14,7 +14,7 @@ var getRatingCmd = &cobra.Command{ v := video.NewVideo( video.WithId(id), video.WithOnBehalfOfContentOwner(onBehalfOfContentOwner), - video.WithService(), + video.WithService(nil), ) v.GetRating() }, diff --git a/cmd/video/insert.go b/cmd/video/insert.go index a3a40b2..95664eb 100644 --- a/cmd/video/insert.go +++ b/cmd/video/insert.go @@ -32,7 +32,7 @@ var insertCmd = &cobra.Command{ video.WithPublicStatsViewable(publicStatsViewable), video.WithOnBehalfOfContentOwner(onBehalfOfContentOwner), video.WithOnBehalfOfContentOwnerChannel(onBehalfOfContentOwnerChannel), - video.WithService(), + video.WithService(nil), ) v.Insert() }, diff --git a/cmd/video/list.go b/cmd/video/list.go index f454736..c686c98 100644 --- a/cmd/video/list.go +++ b/cmd/video/list.go @@ -23,7 +23,7 @@ var listCmd = &cobra.Command{ video.WithMaxResults(maxResults), video.WithOnBehalfOfContentOwner(onBehalfOfContentOwner), video.WithRating(rating), - video.WithService(), + video.WithService(nil), ) v.List(parts, output) }, diff --git a/cmd/video/rate.go b/cmd/video/rate.go index b7f6e78..81be106 100644 --- a/cmd/video/rate.go +++ b/cmd/video/rate.go @@ -14,7 +14,7 @@ var rateCmd = &cobra.Command{ v := video.NewVideo( video.WithId(id), video.WithRating(rating), - video.WithService(), + video.WithService(nil), ) v.Rate() }, diff --git a/cmd/video/update.go b/cmd/video/update.go index 9eb656b..173b69a 100644 --- a/cmd/video/update.go +++ b/cmd/video/update.go @@ -22,7 +22,7 @@ var updateCmd = &cobra.Command{ video.WithCategory(categoryId), video.WithPrivacy(privacy), video.WithEmbeddable(embeddable), - video.WithService(), + video.WithService(nil), ) v.Update() }, diff --git a/cmd/videoAbuseReportReason/list.go b/cmd/videoAbuseReportReason/list.go index b283112..3698164 100644 --- a/cmd/videoAbuseReportReason/list.go +++ b/cmd/videoAbuseReportReason/list.go @@ -12,7 +12,7 @@ var listCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { va := videoAbuseReportReason.NewVideoAbuseReportReason( videoAbuseReportReason.WithHL(hl), - videoAbuseReportReason.WithService(), + videoAbuseReportReason.WithService(nil), ) va.List(parts, output) }, diff --git a/cmd/videoCategory/list.go b/cmd/videoCategory/list.go index 6a6c35b..9cba0d0 100644 --- a/cmd/videoCategory/list.go +++ b/cmd/videoCategory/list.go @@ -14,7 +14,7 @@ var listCmd = &cobra.Command{ videoCategory.WithId(id), videoCategory.WithHl(hl), videoCategory.WithRegionCode(regionCode), - videoCategory.WithService(), + videoCategory.WithService(nil), ) vc.List(parts, output) }, diff --git a/cmd/watermark/set.go b/cmd/watermark/set.go index aefb157..eba4ee6 100644 --- a/cmd/watermark/set.go +++ b/cmd/watermark/set.go @@ -18,6 +18,7 @@ var setCmd = &cobra.Command{ watermark.WithOffsetMs(offsetMs), watermark.WithOffsetType(offsetType), watermark.WithOnBehalfOfContentOwner(onBehalfOfContentOwner), + watermark.WithService(nil), ) w.Set() }, diff --git a/cmd/watermark/unset.go b/cmd/watermark/unset.go index 2bcd3f1..757748d 100644 --- a/cmd/watermark/unset.go +++ b/cmd/watermark/unset.go @@ -10,7 +10,10 @@ var unsetCmd = &cobra.Command{ Short: "Unset watermark for channel's video", Long: "Unset watermark for channel's video", Run: func(cmd *cobra.Command, args []string) { - w := watermark.NewWatermark(watermark.WithChannelId(channelId)) + w := watermark.NewWatermark( + watermark.WithChannelId(channelId), + watermark.WithService(nil), + ) w.Unset() }, } diff --git a/pkg/yutuber/activity/activity.go b/pkg/yutuber/activity/activity.go index dca90b6..254f0ac 100644 --- a/pkg/yutuber/activity/activity.go +++ b/pkg/yutuber/activity/activity.go @@ -139,8 +139,12 @@ func WithRegionCode(regionCode string) Option { } } -func WithService() Option { +func WithService(svc *youtube.Service) Option { return func(a *activity) { - service = auth.NewY2BService() + if svc != nil { + service = svc + } else { + service = auth.NewY2BService() + } } } diff --git a/pkg/yutuber/caption/caption.go b/pkg/yutuber/caption/caption.go index 088e28b..0473a14 100644 --- a/pkg/yutuber/caption/caption.go +++ b/pkg/yutuber/caption/caption.go @@ -294,8 +294,12 @@ func WithVideoId(videoId string) Option { } } -func WithService() Option { +func WithService(svc *youtube.Service) Option { return func(c *caption) { - service = auth.NewY2BService() + if svc != nil { + service = svc + } else { + service = auth.NewY2BService() + } } } diff --git a/pkg/yutuber/channel/channel.go b/pkg/yutuber/channel/channel.go index 77d4dd5..dbfdf0b 100644 --- a/pkg/yutuber/channel/channel.go +++ b/pkg/yutuber/channel/channel.go @@ -232,8 +232,12 @@ func WithTitle(title string) Option { } } -func WithService() Option { +func WithService(svc *youtube.Service) Option { return func(c *channel) { - service = auth.NewY2BService() + if svc != nil { + service = svc + } else { + service = auth.NewY2BService() + } } } diff --git a/pkg/yutuber/channelBanner/channelBanner.go b/pkg/yutuber/channelBanner/channelBanner.go index 41c0796..db64ce4 100644 --- a/pkg/yutuber/channelBanner/channelBanner.go +++ b/pkg/yutuber/channelBanner/channelBanner.go @@ -82,8 +82,12 @@ func WithOnBehalfOfContentOwnerChannel(onBehalfOfContentOwnerChannel string) Opt } } -func WithService() Option { +func WithService(svc *youtube.Service) Option { return func(cb *channelBanner) { - service = auth.NewY2BService() + if svc != nil { + service = svc + } else { + service = auth.NewY2BService() + } } } diff --git a/pkg/yutuber/channelSection/channelSection.go b/pkg/yutuber/channelSection/channelSection.go index 52eef6f..0642411 100644 --- a/pkg/yutuber/channelSection/channelSection.go +++ b/pkg/yutuber/channelSection/channelSection.go @@ -3,6 +3,7 @@ package channelSection 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" @@ -129,3 +130,13 @@ func WithOnBehalfOfContentOwner(onBehalfOfContentOwner string) Option { cs.onBehalfOfContentOwner = onBehalfOfContentOwner } } + +func WithService(svc *youtube.Service) Option { + return func(cs *channelSection) { + if svc != nil { + service = svc + } else { + service = auth.NewY2BService() + } + } +} diff --git a/pkg/yutuber/i18nLanguage/i18nLanguage.go b/pkg/yutuber/i18nLanguage/i18nLanguage.go index d499404..3e5e70d 100644 --- a/pkg/yutuber/i18nLanguage/i18nLanguage.go +++ b/pkg/yutuber/i18nLanguage/i18nLanguage.go @@ -73,8 +73,12 @@ func WithHl(hl string) Option { } } -func WithService() Option { +func WithService(svc *youtube.Service) Option { return func(i *i18nLanguage) { - service = auth.NewY2BService() + if svc != nil { + service = svc + } else { + service = auth.NewY2BService() + } } } diff --git a/pkg/yutuber/i18nRegion/i18nRegion.go b/pkg/yutuber/i18nRegion/i18nRegion.go index 55c25a3..fc3b891 100644 --- a/pkg/yutuber/i18nRegion/i18nRegion.go +++ b/pkg/yutuber/i18nRegion/i18nRegion.go @@ -73,8 +73,12 @@ func WithHl(hl string) Option { } } -func WithService() Option { +func WithService(svc *youtube.Service) Option { return func(i *i18nRegion) { - service = auth.NewY2BService() + if svc != nil { + service = svc + } else { + service = auth.NewY2BService() + } } } diff --git a/pkg/yutuber/member/member.go b/pkg/yutuber/member/member.go index 00b4d91..07f09d7 100644 --- a/pkg/yutuber/member/member.go +++ b/pkg/yutuber/member/member.go @@ -102,8 +102,12 @@ func WithMode(mode string) Option { } } -func WithService() Option { +func WithService(svc *youtube.Service) Option { return func(m *member) { - service = auth.NewY2BService() + if svc != nil { + service = svc + } else { + service = auth.NewY2BService() + } } } diff --git a/pkg/yutuber/membershipsLevel/membershipsLevel.go b/pkg/yutuber/membershipsLevel/membershipsLevel.go index cf814e8..90a2d10 100644 --- a/pkg/yutuber/membershipsLevel/membershipsLevel.go +++ b/pkg/yutuber/membershipsLevel/membershipsLevel.go @@ -61,8 +61,12 @@ func (m *membershipsLevel) List(parts []string, output string) { } } -func WithService() Option { +func WithService(svc *youtube.Service) Option { return func(m *membershipsLevel) { - service = auth.NewY2BService() + if svc != nil { + service = svc + } else { + service = auth.NewY2BService() + } } } diff --git a/pkg/yutuber/playlist/playlist.go b/pkg/yutuber/playlist/playlist.go index 70e2f73..a52ae1c 100644 --- a/pkg/yutuber/playlist/playlist.go +++ b/pkg/yutuber/playlist/playlist.go @@ -236,8 +236,12 @@ func WithOnBehalfOfContentOwnerChannel(channel string) Option { } } -func WithService() Option { +func WithService(svc *youtube.Service) Option { return func(p *playlist) { - service = auth.NewY2BService() + if svc != nil { + service = svc + } else { + service = auth.NewY2BService() + } } } diff --git a/pkg/yutuber/playlistItem/playlistItem.go b/pkg/yutuber/playlistItem/playlistItem.go index 9bbe617..03c5a2b 100644 --- a/pkg/yutuber/playlistItem/playlistItem.go +++ b/pkg/yutuber/playlistItem/playlistItem.go @@ -3,9 +3,9 @@ package playlistItem import ( "errors" "fmt" + "github.com/eat-pray-ai/yutu/pkg/auth" "log" - "github.com/eat-pray-ai/yutu/pkg/auth" "github.com/eat-pray-ai/yutu/pkg/utils" "google.golang.org/api/youtube/v3" ) @@ -253,8 +253,12 @@ func WithOnBehalfOfContentOwner(onBehalfOfContentOwner string) Option { } } -func WithService() Option { +func WithService(svc *youtube.Service) Option { return func(p *playlistItem) { - service = auth.NewY2BService() + if svc != nil { + service = svc + } else { + service = auth.NewY2BService() + } } } diff --git a/pkg/yutuber/search/search.go b/pkg/yutuber/search/search.go index efdee07..5d56036 100644 --- a/pkg/yutuber/search/search.go +++ b/pkg/yutuber/search/search.go @@ -382,8 +382,12 @@ func WithVideoType(videoType string) Option { } } -func WithService() Option { +func WithService(svc *youtube.Service) Option { return func(s *search) { - service = auth.NewY2BService() + if svc != nil { + service = svc + } else { + service = auth.NewY2BService() + } } } diff --git a/pkg/yutuber/subscription/subscription.go b/pkg/yutuber/subscription/subscription.go index fe3e291..9c6d8ed 100644 --- a/pkg/yutuber/subscription/subscription.go +++ b/pkg/yutuber/subscription/subscription.go @@ -225,8 +225,12 @@ func WithTitle(title string) Option { } } -func WithService() Option { +func WithService(svc *youtube.Service) Option { return func(s *subscription) { - service = auth.NewY2BService() + if svc != nil { + service = svc + } else { + service = auth.NewY2BService() + } } } diff --git a/pkg/yutuber/thumbnail/thumbnail.go b/pkg/yutuber/thumbnail/thumbnail.go index 6bf670b..b328d24 100644 --- a/pkg/yutuber/thumbnail/thumbnail.go +++ b/pkg/yutuber/thumbnail/thumbnail.go @@ -58,8 +58,12 @@ func WithFile(file string) Option { } } -func WithService() Option { +func WithService(svc *youtube.Service) Option { return func(t *thumbnail) { - service = auth.NewY2BService() + if svc != nil { + service = svc + } else { + service = auth.NewY2BService() + } } } diff --git a/pkg/yutuber/video/video.go b/pkg/yutuber/video/video.go index 897f12d..ed5b179 100644 --- a/pkg/yutuber/video/video.go +++ b/pkg/yutuber/video/video.go @@ -3,12 +3,12 @@ package video import ( "errors" "fmt" + "github.com/eat-pray-ai/yutu/pkg/auth" "github.com/eat-pray-ai/yutu/pkg/yutuber/playlistItem" "github.com/eat-pray-ai/yutu/pkg/yutuber/thumbnail" "log" "os" - "github.com/eat-pray-ai/yutu/pkg/auth" "github.com/eat-pray-ai/yutu/pkg/utils" "google.golang.org/api/youtube/v3" ) @@ -190,7 +190,7 @@ func (v *video) Insert() { t := thumbnail.NewThumbnail( thumbnail.WithVideoId(v.id), thumbnail.WithFile(v.thumbnail), - thumbnail.WithService(), + thumbnail.WithService(service), ) t.Set() } @@ -203,7 +203,7 @@ func (v *video) Insert() { playlistItem.WithPlaylistId(v.playlistId), playlistItem.WithChannelId(v.channelId), playlistItem.WithPrivacy(v.privacy), - playlistItem.WithService(), + playlistItem.WithService(service), ) pi.Insert() } @@ -252,7 +252,7 @@ func (v *video) Update() { t := thumbnail.NewThumbnail( thumbnail.WithVideoId(v.id), thumbnail.WithFile(v.thumbnail), - thumbnail.WithService(), + thumbnail.WithService(service), ) t.Set() } @@ -265,7 +265,7 @@ func (v *video) Update() { playlistItem.WithPlaylistId(v.playlistId), playlistItem.WithChannelId(v.channelId), playlistItem.WithPrivacy(v.privacy), - playlistItem.WithService(), + playlistItem.WithService(service), ) pi.Insert() } @@ -487,8 +487,12 @@ func WithOnBehalfOfContentOwnerChannel(onBehalfOfContentOwnerChannel string) Opt } } -func WithService() Option { +func WithService(svc *youtube.Service) Option { return func(v *video) { - service = auth.NewY2BService() + if svc != nil { + service = svc + } else { + service = auth.NewY2BService() + } } } diff --git a/pkg/yutuber/videoAbuseReportReason/videoAbuseReportReason.go b/pkg/yutuber/videoAbuseReportReason/videoAbuseReportReason.go index fe401ae..26c07be 100644 --- a/pkg/yutuber/videoAbuseReportReason/videoAbuseReportReason.go +++ b/pkg/yutuber/videoAbuseReportReason/videoAbuseReportReason.go @@ -71,8 +71,12 @@ func WithHL(hl string) Option { } } -func WithService() Option { +func WithService(svc *youtube.Service) Option { return func(vc *videoAbuseReportReason) { - service = auth.NewY2BService() + if svc != nil { + service = svc + } else { + service = auth.NewY2BService() + } } } diff --git a/pkg/yutuber/videoCategory/videoCategory.go b/pkg/yutuber/videoCategory/videoCategory.go index c072f6a..c81caa6 100644 --- a/pkg/yutuber/videoCategory/videoCategory.go +++ b/pkg/yutuber/videoCategory/videoCategory.go @@ -3,9 +3,9 @@ package videoCategory import ( "errors" "fmt" + "github.com/eat-pray-ai/yutu/pkg/auth" "log" - "github.com/eat-pray-ai/yutu/pkg/auth" "github.com/eat-pray-ai/yutu/pkg/utils" "google.golang.org/api/youtube/v3" ) @@ -92,8 +92,12 @@ func WithRegionCode(regionCode string) Option { } } -func WithService() Option { +func WithService(svc *youtube.Service) Option { return func(vc *videoCategory) { - service = auth.NewY2BService() + if svc != nil { + service = svc + } else { + service = auth.NewY2BService() + } } } diff --git a/pkg/yutuber/watermark/watermark.go b/pkg/yutuber/watermark/watermark.go index d90aa5a..1ed57a5 100644 --- a/pkg/yutuber/watermark/watermark.go +++ b/pkg/yutuber/watermark/watermark.go @@ -136,8 +136,12 @@ func WithOnBehalfOfContentOwner(onBehalfOfContentOwner string) Option { } } -func WithService() Option { +func WithService(svc *youtube.Service) Option { return func(w *watermark) { - service = auth.NewY2BService() + if svc != nil { + service = svc + } else { + service = auth.NewY2BService() + } } }