♻️ Allow service reuse

This commit is contained in:
chaoqun committed 2024-06-24 22:58:53 +08:00
1 parent 3973e155ba
commit 95ccdf5652
54 files changed
+159 -74

No files matched your search

+1 -1
View File
@@ -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)
},
+1 -1
View File
@@ -14,7 +14,7 @@ var deleteCmd = &cobra.Command{
caption.WithId(id),
caption.WithOnBehalfOf(onBehalfOf),
caption.WithOnBehalfOfContentOwner(onBehalfOfContentOwner),
caption.WithService(),
caption.WithService(nil),
)
c.Delete()
},
+1 -1
View File
@@ -24,7 +24,7 @@ var insertCmd = &cobra.Command{
caption.WithOnBehalfOf(onBehalfOf),
caption.WithOnBehalfOfContentOwner(onBehalfOfContentOwner),
caption.WithVideoId(videoId),
caption.WithService(),
caption.WithService(nil),
)
c.Insert()
},
+1 -1
View File
@@ -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)
},
+1 -1
View File
@@ -24,7 +24,7 @@ var updateCmd = &cobra.Command{
caption.WithOnBehalfOf(onBehalfOf),
caption.WithOnBehalfOfContentOwner(onBehalfOfContentOwner),
caption.WithVideoId(videoId),
caption.WithService(),
caption.WithService(nil),
)
c.Update()
},
+1 -1
View File
@@ -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)
},
+1 -1
View File
@@ -17,7 +17,7 @@ var updateCmd = &cobra.Command{
channel.WithDefaultLanguage(defaultLanguage),
channel.WithDescription(description),
channel.WithTitle(title),
channel.WithService(),
channel.WithService(nil),
)
c.Update()
},
+1 -1
View File
@@ -14,7 +14,7 @@ var insertCmd = &cobra.Command{
channelBanner.WithFile(file),
channelBanner.WithOnBehalfOfContentOwner(onBehalfOfContentOwner),
channelBanner.WithOnBehalfOfContentOwnerChannel(onBehalfOfContentOwnerChannel),
channelBanner.WithService(),
channelBanner.WithService(nil),
)
cb.Insert()
},
+1
View File
@@ -13,6 +13,7 @@ var deleteCmd = &cobra.Command{
cs := channelSection.NewChannelSection(
channelSection.WithId(id),
channelSection.WithOnBehalfOfContentOwner(onBehalfOfContentOwner),
channelSection.WithService(nil),
)
cs.Delete()
},
+1
View File
@@ -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)
},
+1 -1
View File
@@ -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)
},
+1 -1
View File
@@ -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)
},
+1 -1
View File
@@ -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)
},
+1 -1
View File
@@ -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)
},
}
+1 -1
View File
@@ -13,7 +13,7 @@ var deleteCmd = &cobra.Command{
p := playlist.NewPlaylist(
playlist.WithId(id),
playlist.WithOnBehalfOfContentOwner(onBehalfOfContentOwner),
playlist.WithService(),
playlist.WithService(nil),
)
p.Delete()
},
+1 -1
View File
@@ -17,7 +17,7 @@ var insertCmd = &cobra.Command{
playlist.WithLanguage(language),
playlist.WithChannelId(channelId),
playlist.WithPrivacy(privacy),
playlist.WithService(),
playlist.WithService(nil),
)
p.Insert()
},
+1 -1
View File
@@ -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)
},
+1 -1
View File
@@ -17,7 +17,7 @@ var updateCmd = &cobra.Command{
playlist.WithTags(tags),
playlist.WithLanguage(language),
playlist.WithPrivacy(privacy),
playlist.WithService(),
playlist.WithService(nil),
)
p.Update()
},
+1 -1
View File
@@ -13,7 +13,7 @@ var deleteCmd = &cobra.Command{
pi := playlistItem.NewPlaylistItem(
playlistItem.WithId(id),
playlistItem.WithOnBehalfOfContentOwner(onBehalfOfContentOwner),
playlistItem.WithService(),
playlistItem.WithService(nil),
)
pi.Delete()
},
+1 -1
View File
@@ -19,7 +19,7 @@ var insertCmd = &cobra.Command{
playlistItem.WithKPlaylistId(kPlaylistId),
playlistItem.WithPlaylistId(playlistId),
playlistItem.WithPrivacy(privacy),
playlistItem.WithService(),
playlistItem.WithService(nil),
)
pi.Insert()
},
+1 -1
View File
@@ -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)
},
+1 -1
View File
@@ -15,7 +15,7 @@ var updateCmd = &cobra.Command{
playlistItem.WithTitle(title),
playlistItem.WithDescription(description),
playlistItem.WithPrivacy(privacy),
playlistItem.WithService(),
playlistItem.WithService(nil),
)
pi.Update()
},
+1 -1
View File
@@ -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)
},
+1 -1
View File
@@ -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()
},
+1 -1
View File
@@ -15,7 +15,7 @@ var insertCmd = &cobra.Command{
subscription.WithDescription(description),
subscription.WithChannelId(channelId),
subscription.WithTitle(title),
subscription.WithService(),
subscription.WithService(nil),
)
s.Insert()
},
+1 -1
View File
@@ -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)
},
+1 -1
View File
@@ -13,7 +13,7 @@ var setCmd = &cobra.Command{
t := thumbnail.NewThumbnail(
thumbnail.WithFile(file),
thumbnail.WithVideoId(videoId),
thumbnail.WithService(),
thumbnail.WithService(nil),
)
t.Set()
},
+1 -1
View File
@@ -14,7 +14,7 @@ var getRatingCmd = &cobra.Command{
v := video.NewVideo(
video.WithId(id),
video.WithOnBehalfOfContentOwner(onBehalfOfContentOwner),
video.WithService(),
video.WithService(nil),
)
v.GetRating()
},
+1 -1
View File
@@ -32,7 +32,7 @@ var insertCmd = &cobra.Command{
video.WithPublicStatsViewable(publicStatsViewable),
video.WithOnBehalfOfContentOwner(onBehalfOfContentOwner),
video.WithOnBehalfOfContentOwnerChannel(onBehalfOfContentOwnerChannel),
video.WithService(),
video.WithService(nil),
)
v.Insert()
},
+1 -1
View File
@@ -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)
},
+1 -1
View File
@@ -14,7 +14,7 @@ var rateCmd = &cobra.Command{
v := video.NewVideo(
video.WithId(id),
video.WithRating(rating),
video.WithService(),
video.WithService(nil),
)
v.Rate()
},
+1 -1
View File
@@ -22,7 +22,7 @@ var updateCmd = &cobra.Command{
video.WithCategory(categoryId),
video.WithPrivacy(privacy),
video.WithEmbeddable(embeddable),
video.WithService(),
video.WithService(nil),
)
v.Update()
},
+1 -1
View File
@@ -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)
},
+1 -1
View File
@@ -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)
},
+1
View File
@@ -18,6 +18,7 @@ var setCmd = &cobra.Command{
watermark.WithOffsetMs(offsetMs),
watermark.WithOffsetType(offsetType),
watermark.WithOnBehalfOfContentOwner(onBehalfOfContentOwner),
watermark.WithService(nil),
)
w.Set()
},
+4 -1
View File
@@ -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()
},
}
+6 -2
View File
@@ -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()
}
}
}
+6 -2
View File
@@ -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()
}
}
}
+6 -2
View File
@@ -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()
}
}
}
+6 -2
View File
@@ -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()
}
}
}
@@ -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()
}
}
}
+6 -2
View File
@@ -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()
}
}
}
+6 -2
View File
@@ -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()
}
}
}
+6 -2
View File
@@ -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()
}
}
}
@@ -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()
}
}
}
+6 -2
View File
@@ -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()
}
}
}
+7 -3
View File
@@ -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()
}
}
}
+6 -2
View File
@@ -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()
}
}
}
+6 -2
View File
@@ -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()
}
}
}
+6 -2
View File
@@ -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()
}
}
}
+11 -7
View File
@@ -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()
}
}
}
@@ -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()
}
}
}
+7 -3
View File
@@ -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()
}
}
}
+6 -2
View File
@@ -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()
}
}
}