Skip to content

Commit

Permalink
✨ Support more flags of video category and ARR
Browse files Browse the repository at this point in the history
  • Loading branch information
OpenWaygate committed May 17, 2024
1 parent 1a8b1f8 commit 87435ac
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cmd/i18nLanguage/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var listCmd = &cobra.Command{

func init() {
i18nLanguageCmd.AddCommand(listCmd)
listCmd.Flags().StringVarP(&hl, "hl", "l", "", "host language")
listCmd.Flags().StringVarP(&hl, "hl", "l", "", "Host language")
listCmd.Flags().StringSliceVarP(
&parts, "parts", "p", []string{"id", "snippet"}, "Comma separated parts",
)
Expand Down
15 changes: 12 additions & 3 deletions cmd/videoAbuseReportReason/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,23 @@ var listCmd = &cobra.Command{
Short: "list YouTube video abuse report reasons",
Long: "list YouTube video abuse report reasons",
Run: func(cmd *cobra.Command, args []string) {
va := yutuber.NewVideoAbuseReportReason()
va := yutuber.NewVideoAbuseReportReason(
yutuber.WithVideoAbuseReportReasonHL(hl),
)
va.List(parts, output)
},
}

func init() {
videoAbuseReportReasonCmd.AddCommand(listCmd)

listCmd.Flags().StringSliceVarP(&parts, "parts", "p", []string{"id", "snippet"}, "Comma separated parts")
listCmd.Flags().StringVarP(&output, "output", "o", "", "Output format: json or yaml")
listCmd.Flags().StringVarP(
&hl, "hl", "l", "", "Host language",
)
listCmd.Flags().StringSliceVarP(
&parts, "parts", "p", []string{"id", "snippet"}, "Comma separated parts",
)
listCmd.Flags().StringVarP(
&output, "output", "o", "", "Output format: json or yaml",
)
}
1 change: 1 addition & 0 deletions cmd/videoAbuseReportReason/videoAbuseReportReason.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
)

var (
hl string
parts []string
output string
)
Expand Down
14 changes: 11 additions & 3 deletions cmd/videoCategory/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ var listCmd = &cobra.Command{
Long: "list video categories' info, such as ID, title, assignable, etc.",
Run: func(cmd *cobra.Command, args []string) {
vc := yutuber.NewVideoCategory(
yutuber.WithRegionCode(regionCode),
yutuber.WithVideoCategoryId(id),
yutuber.WithVideoCategoryHl(hl),
yutuber.WithVideoCategoryRegionCode(regionCode),
)
vc.List(parts, output)
},
Expand All @@ -20,7 +22,13 @@ var listCmd = &cobra.Command{
func init() {
videoCategoryCmd.AddCommand(listCmd)

listCmd.Flags().StringVarP(&id, "id", "i", "", "ID of the video category")
listCmd.Flags().StringVarP(&hl, "hl", "l", "", "Host language")
listCmd.Flags().StringVarP(&regionCode, "regionCode", "r", "US", "Region code")
listCmd.Flags().StringSliceVarP(&parts, "parts", "p", []string{"id", "snippet"}, "Comma separated parts")
listCmd.Flags().StringVarP(&output, "output", "o", "", "Output format: json or yaml")
listCmd.Flags().StringSliceVarP(
&parts, "parts", "p", []string{"id", "snippet"}, "Comma separated parts",
)
listCmd.Flags().StringVarP(
&output, "output", "o", "", "Output format: json or yaml",
)
}
2 changes: 2 additions & 0 deletions cmd/videoCategory/videoCategory.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
)

var (
id string
hl string
regionCode string
parts []string
output string
Expand Down
14 changes: 13 additions & 1 deletion pkg/yutuber/videoAbuseReportReason.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ var (
errGetVideoAbuseReportReason = errors.New("failed to get video abuse report reason")
)

type videoAbuseReportReason struct{}
type videoAbuseReportReason struct {
hl string
}

type VideoAbuseReportReason interface {
get([]string) []*youtube.VideoAbuseReportReason
Expand All @@ -33,6 +35,10 @@ func NewVideoAbuseReportReason(opt ...VideoAbuseReportReasonOption) VideoAbuseRe

func (vc *videoAbuseReportReason) get(parts []string) []*youtube.VideoAbuseReportReason {
call := service.VideoAbuseReportReasons.List(parts)
if vc.hl != "" {
call = call.Hl(vc.hl)
}

response, err := call.Do()
if err != nil {
log.Fatalln(errors.Join(errGetVideoAbuseReportReason, err))
Expand All @@ -58,3 +64,9 @@ func (vc *videoAbuseReportReason) List(parts []string, output string) {
}
}
}

func WithVideoAbuseReportReasonHL(hl string) VideoAbuseReportReasonOption {
return func(vc *videoAbuseReportReason) {
vc.hl = hl
}
}
28 changes: 26 additions & 2 deletions pkg/yutuber/videoCategory.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ var (
)

type videoCategory struct {
id string
hl string
regionCode string
}

Expand All @@ -35,7 +37,17 @@ func NewVideoCategory(opt ...VideoCategoryOption) VideoCategory {
}

func (vc *videoCategory) get(parts []string) []*youtube.VideoCategory {
call := service.VideoCategories.List(parts).RegionCode(vc.regionCode)
call := service.VideoCategories.List(parts)
if vc.id != "" {
call = call.Id(vc.id)
}
if vc.hl != "" {
call = call.Hl(vc.hl)
}
if vc.regionCode != "" {
call = call.RegionCode(vc.regionCode)
}

response, err := call.Do()
if err != nil {
log.Fatalln(errors.Join(errGetVideoCategory, err), vc.regionCode)
Expand All @@ -62,7 +74,19 @@ func (vc *videoCategory) List(parts []string, output string) {
}
}

func WithRegionCode(regionCode string) VideoCategoryOption {
func WithVideoCategoryId(id string) VideoCategoryOption {
return func(vc *videoCategory) {
vc.id = id
}
}

func WithVideoCategoryHl(hl string) VideoCategoryOption {
return func(vc *videoCategory) {
vc.hl = hl
}
}

func WithVideoCategoryRegionCode(regionCode string) VideoCategoryOption {
return func(vc *videoCategory) {
vc.regionCode = regionCode
}
Expand Down

0 comments on commit 87435ac

Please # to comment.