✨ Support rate a video
This commit is contained in:
1 parent
6a773770d7
commit
bf1ac4a6e4
5 files changed
+51
-10
No files matched your search
@@ -41,8 +41,8 @@ Here are the features that are currently supported by yutu, and the ones that ar
|
||||
- [x] list, 1
|
||||
- [x] insert, 1600
|
||||
- [x] update, 50
|
||||
- [ ] rate, 50
|
||||
- [ ] getRating, 1
|
||||
- [x] rate, 50
|
||||
- [x] getRating, 1
|
||||
- [ ] reportAbuse, 50
|
||||
- [ ] delete, 50
|
||||
- channels
|
||||
|
||||
+2
-2
@@ -13,7 +13,7 @@ var listCmd = &cobra.Command{
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
v := yutuber.NewVideo(
|
||||
yutuber.WithVideoId(id),
|
||||
yutuber.WithVideoMyRating(myRating),
|
||||
yutuber.WithVideoRating(rating),
|
||||
)
|
||||
v.List(parts, output)
|
||||
},
|
||||
@@ -24,7 +24,7 @@ func init() {
|
||||
parts := []string{"id", "snippet", "status"}
|
||||
|
||||
listCmd.Flags().StringVarP(&id, "id", "i", "", "ID of the video")
|
||||
listCmd.Flags().StringVarP(&myRating, "myRating", "r", "", "My rating of the video")
|
||||
listCmd.Flags().StringVarP(&rating, "rating", "r", "", "My rating of the video")
|
||||
listCmd.Flags().StringVarP(&output, "output", "o", "", "Output format: json or yaml")
|
||||
listCmd.Flags().StringArrayVarP(&parts, "parts", "p", parts, "Comma separated parts")
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package video
|
||||
|
||||
import (
|
||||
"github.com/eat-pray-ai/yutu/pkg/yutuber"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var rateCmd = &cobra.Command{
|
||||
Use: "rate",
|
||||
Short: "rate a video on YouTube",
|
||||
Long: "rate a video on YouTube, with the specified rating",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
v := yutuber.NewVideo(
|
||||
yutuber.WithVideoId(id),
|
||||
yutuber.WithVideoRating(rating),
|
||||
)
|
||||
v.Rate()
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
videoCmd.AddCommand(rateCmd)
|
||||
|
||||
rateCmd.Flags().StringVarP(&id, "id", "i", "", "ID of the video")
|
||||
rateCmd.Flags().StringVarP(&rating, "rating", "r", "", "Rating of the video")
|
||||
|
||||
rateCmd.MarkFlagRequired("id")
|
||||
rateCmd.MarkFlagRequired("rating")
|
||||
}
|
||||
+1
-1
@@ -14,7 +14,7 @@ var (
|
||||
tags []string
|
||||
language string
|
||||
thumbnail string
|
||||
myRating string
|
||||
rating string
|
||||
chart string
|
||||
channelId string
|
||||
playListId string
|
||||
|
||||
+16
-5
@@ -17,6 +17,7 @@ var (
|
||||
errUpdateVideo error = errors.New("failed to update video")
|
||||
errOpenFile error = errors.New("failed to open file")
|
||||
errSetThumbnail error = errors.New("failed to set thumbnail")
|
||||
errRating error = errors.New("failed to rate video")
|
||||
errGetRating error = errors.New("failed to get rating")
|
||||
)
|
||||
|
||||
@@ -28,7 +29,7 @@ type Video struct {
|
||||
tags []string
|
||||
language string
|
||||
thumbnail string
|
||||
myRating string
|
||||
rating string
|
||||
chart string
|
||||
channelId string
|
||||
playlistId string
|
||||
@@ -42,6 +43,7 @@ type VideoService interface {
|
||||
List([]string, string)
|
||||
Insert()
|
||||
Update()
|
||||
Rate()
|
||||
GetRating()
|
||||
get([]string) *youtube.Video
|
||||
setThumbnail()
|
||||
@@ -65,8 +67,8 @@ func (v *Video) get(parts []string) []*youtube.Video {
|
||||
call := service.Videos.List(parts)
|
||||
if v.id != "" {
|
||||
call = call.Id(v.id)
|
||||
} else if v.myRating != "" {
|
||||
call = call.MyRating(v.myRating)
|
||||
} else if v.rating != "" {
|
||||
call = call.MyRating(v.rating)
|
||||
}
|
||||
response, err := call.Do()
|
||||
if err != nil {
|
||||
@@ -191,6 +193,15 @@ func (v *Video) Update() {
|
||||
utils.PrintJSON(res)
|
||||
}
|
||||
|
||||
func (v *Video) Rate() {
|
||||
call := service.Videos.Rate(v.id, v.rating)
|
||||
err := call.Do()
|
||||
if err != nil {
|
||||
log.Fatalln(errors.Join(errRating, err), v.id)
|
||||
}
|
||||
fmt.Printf("Video %s rated %s\n", v.id, v.rating)
|
||||
}
|
||||
|
||||
func (v *Video) GetRating() {
|
||||
call := service.Videos.GetRating([]string{v.id})
|
||||
res, err := call.Do()
|
||||
@@ -255,9 +266,9 @@ func WithVideoThumbnail(thumbnail string) VideoOption {
|
||||
}
|
||||
}
|
||||
|
||||
func WithVideoMyRating(myRating string) VideoOption {
|
||||
func WithVideoRating(rating string) VideoOption {
|
||||
return func(v *Video) {
|
||||
v.myRating = myRating
|
||||
v.rating = rating
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user