✨ Support more flags about video
This commit is contained in:
1 parent
3869893b91
commit
07dbdebe09
7 files changed
+115
-15
No files matched your search
@@ -13,6 +13,7 @@ var getRatingCmd = &cobra.Command{
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
v := yutuber.NewVideo(
|
||||
yutuber.WithVideoId(id),
|
||||
yutuber.WithVideoOnBehalfOfContentOwner(onBehalfOfContentOwner),
|
||||
)
|
||||
v.GetRating()
|
||||
},
|
||||
@@ -22,5 +23,6 @@ func init() {
|
||||
videoCmd.AddCommand(getRatingCmd)
|
||||
|
||||
getRatingCmd.Flags().StringVarP(&id, "id", "i", "", "ID of the video")
|
||||
getRatingCmd.Flags().StringVarP(&onBehalfOfContentOwner, "onBehalfOfContentOwner", "b", "", "")
|
||||
getRatingCmd.MarkFlagRequired("id")
|
||||
}
|
||||
+3
-3
@@ -22,7 +22,7 @@ var insertCmd = &cobra.Command{
|
||||
yutuber.WithVideoThumbnail(thumbnail),
|
||||
yutuber.WithVideoChannelId(channelId),
|
||||
yutuber.WithVideoPlaylistId(playListId),
|
||||
yutuber.WithVideoCategory(category),
|
||||
yutuber.WithVideoCategory(categoryId),
|
||||
yutuber.WithVideoPrivacy(privacy),
|
||||
yutuber.WithVideoForKids(forKids),
|
||||
yutuber.WithVideoEmbeddable(embeddable),
|
||||
@@ -50,7 +50,7 @@ func init() {
|
||||
insertCmd.Flags().StringVarP(&thumbnail, "thumbnail", "u", "", "Path to the thumbnail")
|
||||
insertCmd.Flags().StringVarP(&channelId, "channelId", "c", "", "Channel ID of the video")
|
||||
insertCmd.Flags().StringVarP(&playListId, "playlistId", "y", "", "Playlist ID of the video")
|
||||
insertCmd.Flags().StringVarP(&category, "category", "g", "", "Category of the video")
|
||||
insertCmd.Flags().StringVarP(&categoryId, "categoryId", "g", "", "Category of the video")
|
||||
insertCmd.Flags().StringVarP(
|
||||
&privacy, "privacy", "p", "", "Privacy status of the video: public, private, or unlisted",
|
||||
)
|
||||
@@ -70,6 +70,6 @@ func init() {
|
||||
|
||||
insertCmd.MarkFlagRequired("file")
|
||||
insertCmd.MarkFlagRequired("title")
|
||||
insertCmd.MarkFlagRequired("category")
|
||||
insertCmd.MarkFlagRequired("categoryId")
|
||||
insertCmd.MarkFlagRequired("privacy")
|
||||
}
|
||||
+21
-1
@@ -13,6 +13,15 @@ var listCmd = &cobra.Command{
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
v := yutuber.NewVideo(
|
||||
yutuber.WithVideoId(id),
|
||||
yutuber.WithVideoChart(chart),
|
||||
yutuber.WithVideoHl(hl),
|
||||
yutuber.WithVideoLocale(locale),
|
||||
yutuber.WithVideoCategory(categoryId),
|
||||
yutuber.WithVideoRegionCode(regionCode),
|
||||
yutuber.WithVideoMaxHeight(maxHeight),
|
||||
yutuber.WithVideoMaxWidth(maxWidth),
|
||||
yutuber.WithVideoMaxResults(maxResults),
|
||||
yutuber.WithVideoOnBehalfOfContentOwner(onBehalfOfContentOwner),
|
||||
yutuber.WithVideoRating(rating),
|
||||
)
|
||||
v.List(parts, output)
|
||||
@@ -24,7 +33,18 @@ func init() {
|
||||
parts := []string{"id", "snippet", "status"}
|
||||
|
||||
listCmd.Flags().StringVarP(&id, "id", "i", "", "Return videos with the given ids")
|
||||
listCmd.Flags().StringVarP(&rating, "rating", "r", "", "Return videos liked/disliked by the authenticated user")
|
||||
listCmd.Flags().StringVarP(&chart, "chart", "c", "", "chartUnspecified or mostPopular")
|
||||
listCmd.Flags().StringVarP(&hl, "hl", "L", "", "Specifies the localization language")
|
||||
listCmd.Flags().StringVarP(&locale, "locale", "l", "", "")
|
||||
listCmd.Flags().StringVarP(&categoryId, "videoCategoryId", "v", "", "Specific to the specified video category")
|
||||
listCmd.Flags().StringVarP(®ionCode, "regionCode", "r", "", "Specific to the specified region")
|
||||
listCmd.Flags().Int64VarP(&maxHeight, "maxHeight", "H", 0, "")
|
||||
listCmd.Flags().Int64VarP(&maxWidth, "maxWidth", "W", 0, "")
|
||||
listCmd.Flags().Int64VarP(
|
||||
&maxResults, "maxResults", "n", 5, "Specifies the maximum number of items that should be returned",
|
||||
)
|
||||
listCmd.Flags().StringVarP(&onBehalfOfContentOwner, "onBehalfOfContentOwner", "b", "", "")
|
||||
listCmd.Flags().StringVarP(&rating, "myRating", "R", "", "Return videos liked/disliked by the authenticated user")
|
||||
listCmd.Flags().StringVarP(&output, "output", "o", "", "Output format: json or yaml")
|
||||
listCmd.Flags().StringArrayVarP(&parts, "parts", "p", parts, "Comma separated parts")
|
||||
}
|
||||
+2
-2
@@ -19,7 +19,7 @@ var updateCmd = &cobra.Command{
|
||||
yutuber.WithVideoLicense(license),
|
||||
yutuber.WithVideoPlaylistId(playListId),
|
||||
yutuber.WithVideoThumbnail(thumbnail),
|
||||
yutuber.WithVideoCategory(category),
|
||||
yutuber.WithVideoCategory(categoryId),
|
||||
yutuber.WithVideoPrivacy(privacy),
|
||||
yutuber.WithVideoEmbeddable(embeddable),
|
||||
)
|
||||
@@ -38,7 +38,7 @@ func init() {
|
||||
updateCmd.Flags().StringVarP(&license, "license", "L", "youtube", "youtube(default) or creativeCommon")
|
||||
updateCmd.Flags().StringVarP(&thumbnail, "thumbnail", "h", "", "Path to the thumbnail")
|
||||
updateCmd.Flags().StringVarP(&playListId, "playlistId", "y", "", "Playlist ID of the video")
|
||||
updateCmd.Flags().StringVarP(&category, "category", "g", "", "Category of the video")
|
||||
updateCmd.Flags().StringVarP(&categoryId, "categoryId", "g", "", "Category of the video")
|
||||
updateCmd.Flags().StringVarP(&privacy, "privacy", "p", "", "Privacy status of the video: public, private or unlisted")
|
||||
updateCmd.Flags().BoolVarP(&embeddable, "embeddable", "e", true, "Whether the video is embeddable")
|
||||
|
||||
|
||||
+7
-1
@@ -12,22 +12,28 @@ var (
|
||||
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
|
||||
category string
|
||||
categoryId string
|
||||
privacy string
|
||||
forKids bool
|
||||
embeddable bool
|
||||
output string
|
||||
parts []string
|
||||
publishAt string
|
||||
regionCode string
|
||||
stabilize string
|
||||
maxHeight int64
|
||||
maxWidth int64
|
||||
maxResults int64
|
||||
|
||||
notifySubscribers bool
|
||||
publicStatsViewable bool
|
||||
|
||||
+79
-7
@@ -27,20 +27,26 @@ type video struct {
|
||||
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
|
||||
category string
|
||||
categoryId string
|
||||
privacy string
|
||||
forKids bool
|
||||
embeddable bool
|
||||
publishAt string
|
||||
regionCode string
|
||||
stabilize string
|
||||
maxHeight int64
|
||||
maxWidth int64
|
||||
maxResults int64
|
||||
|
||||
notifySubscribers bool
|
||||
publicStatsViewable bool
|
||||
@@ -75,9 +81,36 @@ func (v *video) get(parts []string) []*youtube.Video {
|
||||
call := service.Videos.List(parts)
|
||||
if v.id != "" {
|
||||
call = call.Id(v.id)
|
||||
} else if v.rating != "" {
|
||||
}
|
||||
if v.chart != "" {
|
||||
call = call.Chart(v.chart)
|
||||
}
|
||||
if v.hl != "" {
|
||||
call = call.Hl(v.hl)
|
||||
}
|
||||
if v.locale != "" {
|
||||
call = call.Locale(v.locale)
|
||||
}
|
||||
if v.categoryId != "" {
|
||||
call = call.VideoCategoryId(v.categoryId)
|
||||
}
|
||||
if v.rating != "" {
|
||||
call = call.MyRating(v.rating)
|
||||
}
|
||||
if v.regionCode != "" {
|
||||
call = call.RegionCode(v.regionCode)
|
||||
}
|
||||
if v.maxHeight != 0 {
|
||||
call = call.MaxHeight(v.maxHeight)
|
||||
}
|
||||
if v.maxWidth != 0 {
|
||||
call = call.MaxWidth(v.maxWidth)
|
||||
}
|
||||
if v.onBehalfOfContentOwner != "" {
|
||||
call = call.OnBehalfOfContentOwner(v.onBehalfOfContentOwner)
|
||||
}
|
||||
call = call.MaxResults(v.maxResults)
|
||||
|
||||
response, err := call.Do()
|
||||
if err != nil {
|
||||
log.Fatalln(errors.Join(errGetVideo, err), v.id)
|
||||
@@ -113,7 +146,7 @@ func (v *video) Insert() {
|
||||
Title: v.title,
|
||||
Description: v.description,
|
||||
Tags: v.tags,
|
||||
CategoryId: v.category,
|
||||
CategoryId: v.categoryId,
|
||||
ChannelId: v.channelId,
|
||||
DefaultLanguage: v.language,
|
||||
DefaultAudioLanguage: v.language,
|
||||
@@ -192,8 +225,8 @@ func (v *video) Update() {
|
||||
if v.license != "" {
|
||||
video.Status.License = v.license
|
||||
}
|
||||
if v.category != "" {
|
||||
video.Snippet.CategoryId = v.category
|
||||
if v.categoryId != "" {
|
||||
video.Snippet.CategoryId = v.categoryId
|
||||
}
|
||||
if v.privacy != "" {
|
||||
video.Status.PrivacyStatus = v.privacy
|
||||
@@ -241,6 +274,9 @@ func (v *video) Rate() {
|
||||
|
||||
func (v *video) GetRating() {
|
||||
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)
|
||||
@@ -291,6 +327,12 @@ func WithVideoDescription(description string) VideoOption {
|
||||
}
|
||||
}
|
||||
|
||||
func WithVideoHl(hl string) VideoOption {
|
||||
return func(v *video) {
|
||||
v.hl = hl
|
||||
}
|
||||
}
|
||||
|
||||
func WithVideoTags(tags []string) VideoOption {
|
||||
return func(v *video) {
|
||||
v.tags = tags
|
||||
@@ -303,6 +345,12 @@ func WithVideoLanguage(language string) VideoOption {
|
||||
}
|
||||
}
|
||||
|
||||
func WithVideoLocale(locale string) VideoOption {
|
||||
return func(v *video) {
|
||||
v.locale = locale
|
||||
}
|
||||
}
|
||||
|
||||
func WithVideoLicense(license string) VideoOption {
|
||||
return func(v *video) {
|
||||
v.license = license
|
||||
@@ -339,9 +387,9 @@ func WithVideoEmbeddable(embeddable bool) VideoOption {
|
||||
}
|
||||
}
|
||||
|
||||
func WithVideoCategory(category string) VideoOption {
|
||||
func WithVideoCategory(categoryId string) VideoOption {
|
||||
return func(v *video) {
|
||||
v.category = category
|
||||
v.categoryId = categoryId
|
||||
}
|
||||
}
|
||||
|
||||
@@ -375,12 +423,36 @@ func WithVideoPublishAt(publishAt string) VideoOption {
|
||||
}
|
||||
}
|
||||
|
||||
func WithVideoRegionCode(regionCode string) VideoOption {
|
||||
return func(v *video) {
|
||||
v.regionCode = regionCode
|
||||
}
|
||||
}
|
||||
|
||||
func WithVideoStabilize(stabilize string) VideoOption {
|
||||
return func(v *video) {
|
||||
v.stabilize = stabilize
|
||||
}
|
||||
}
|
||||
|
||||
func WithVideoMaxHeight(maxHeight int64) VideoOption {
|
||||
return func(v *video) {
|
||||
v.maxHeight = maxHeight
|
||||
}
|
||||
}
|
||||
|
||||
func WithVideoMaxWidth(maxWidth int64) VideoOption {
|
||||
return func(v *video) {
|
||||
v.maxWidth = maxWidth
|
||||
}
|
||||
}
|
||||
|
||||
func WithVideoMaxResults(maxResults int64) VideoOption {
|
||||
return func(v *video) {
|
||||
v.maxResults = maxResults
|
||||
}
|
||||
}
|
||||
|
||||
func WithVideoNotifySubscribers(notifySubscribers bool) VideoOption {
|
||||
return func(v *video) {
|
||||
v.notifySubscribers = notifySubscribers
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
errGetVideoCategory = errors.New("failed to get video category")
|
||||
errGetVideoCategory = errors.New("failed to get video categoryId")
|
||||
)
|
||||
|
||||
type videoCategory struct {
|
||||
|
||||
Reference in new issue
Block a user