✨ Support delete item from playlist
This commit is contained in:
1 parent
a9e66d2cd2
commit
2aff3cb889
4 files changed
+49
-8
No files matched your search
@@ -0,0 +1,26 @@
|
||||
package playlistItem
|
||||
|
||||
import (
|
||||
"github.com/eat-pray-ai/yutu/pkg/yutuber"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var deleteCmd = &cobra.Command{
|
||||
Use: "delete",
|
||||
Short: "delete a item from a playlist",
|
||||
Long: "delete a item from a playlist",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
pi := yutuber.NewPlaylistItem(
|
||||
yutuber.WithPlaylistItemId(id),
|
||||
yutuber.WithPlaylistItemOnBehalfOfContentOwner(onBehalfOfContentOwner),
|
||||
)
|
||||
pi.Delete()
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
playlistItemCmd.AddCommand(deleteCmd)
|
||||
|
||||
deleteCmd.Flags().StringVarP(&id, "id", "i", "", "ID of the playlist item to be deleted")
|
||||
deleteCmd.Flags().StringVarP(&onBehalfOfContentOwner, "onBehalfOfContentOwner", "b", "", "")
|
||||
}
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
|
||||
var insertCmd = &cobra.Command{
|
||||
Use: "insert",
|
||||
Short: "insert playlist item",
|
||||
Long: "insert playlist item into a playlist",
|
||||
Short: "insert a playlist item into a playlist",
|
||||
Long: "insert a playlist item into a playlist",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
pi := yutuber.NewPlaylistItem(
|
||||
yutuber.WithPlaylistItemTitle(title),
|
||||
@@ -43,8 +43,7 @@ func init() {
|
||||
&kChannelId, "kChannelId", "C", "", "ID of the channel if kind is channel",
|
||||
)
|
||||
insertCmd.Flags().StringVarP(
|
||||
&kPlaylistId, "kPlaylistId", "P", "",
|
||||
"ID of the playlist if kind is playlist",
|
||||
&kPlaylistId, "kPlaylistId", "P", "", "ID of the playlist if kind is playlist",
|
||||
)
|
||||
insertCmd.Flags().StringVarP(
|
||||
&playlistId, "playlistId", "p", "",
|
||||
|
||||
@@ -26,7 +26,7 @@ func init() {
|
||||
|
||||
listCmd.Flags().StringVarP(&id, "id", "i", "", "ID of the playlist item")
|
||||
listCmd.Flags().StringVarP(
|
||||
&playlistId, "playlistId", "l", "",
|
||||
&playlistId, "playlistId", "I", "",
|
||||
"Return the playlist items within the given playlist",
|
||||
)
|
||||
listCmd.Flags().Int64VarP(
|
||||
|
||||
@@ -11,9 +11,10 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
errGetPlaylistItem = fmt.Errorf("failed to get playlist item")
|
||||
errUpdatePlaylistItem = fmt.Errorf("failed to update playlist item")
|
||||
errInsertPlaylistItem = fmt.Errorf("failed to insert playlist item")
|
||||
errGetPlaylistItem = errors.New("failed to get playlist item")
|
||||
errUpdatePlaylistItem = errors.New("failed to update playlist item")
|
||||
errInsertPlaylistItem = errors.New("failed to insert playlist item")
|
||||
errDeletePlaylistItem = errors.New("failed to delete playlist item")
|
||||
)
|
||||
|
||||
type playlistItem struct {
|
||||
@@ -37,6 +38,7 @@ type PlaylistItem interface {
|
||||
List([]string, string)
|
||||
Insert()
|
||||
Update()
|
||||
Delete()
|
||||
get([]string) []*youtube.PlaylistItem
|
||||
}
|
||||
|
||||
@@ -159,6 +161,20 @@ func (pi *playlistItem) Update() {
|
||||
utils.PrintJSON(res)
|
||||
}
|
||||
|
||||
func (pi *playlistItem) Delete() {
|
||||
call := service.PlaylistItems.Delete(pi.id)
|
||||
if pi.onBehalfOfContentOwner != "" {
|
||||
call = call.OnBehalfOfContentOwner(pi.onBehalfOfContentOwner)
|
||||
}
|
||||
|
||||
err := call.Do()
|
||||
if err != nil {
|
||||
log.Fatalln(errors.Join(errDeletePlaylistItem, err), pi.id)
|
||||
}
|
||||
|
||||
fmt.Printf("Playlsit Item %s deleted", pi.id)
|
||||
}
|
||||
|
||||
func WithPlaylistItemId(id string) PlaylistItemOption {
|
||||
return func(p *playlistItem) {
|
||||
p.id = id
|
||||
|
||||
Reference in new issue
Block a user