♻️ Extract terminal print

This commit is contained in:
OpenWaygate committed 2026-04-06 23:51:08 +08:00
1 parent 80470ef69d
commit 5c4ff9d8a3
43 files changed
+176 -645

No files matched your search

-2
View File
@@ -6,9 +6,7 @@ go_library(
importpath = "github.com/eat-pray-ai/yutu/pkg/activity",
visibility = ["//visibility:public"],
deps = [
"//pkg",
"//pkg/common",
"//pkg/utils",
"@com_github_jedib0t_go_pretty_v6//table",
"@org_golang_google_api//youtube/v3:youtube",
],
+3 -22
View File
@@ -7,9 +7,7 @@ import (
"errors"
"io"
"github.com/eat-pray-ai/yutu/pkg"
"github.com/eat-pray-ai/yutu/pkg/common"
"github.com/eat-pray-ai/yutu/pkg/utils"
"github.com/jedib0t/go-pretty/v6/table"
"google.golang.org/api/youtube/v3"
)
@@ -82,26 +80,9 @@ func (a *Activity) List(writer io.Writer) error {
return err
}
switch a.Output {
case "json":
utils.PrintJSON(activities, writer)
case "yaml":
utils.PrintYAML(activities, writer)
case "table":
tb := table.NewWriter()
defer tb.Render()
tb.SetOutputMirror(writer)
tb.SetStyle(pkg.TableStyle)
tb.AppendHeader(table.Row{"ID", "Title", "Type", "Time"})
for _, activity := range activities {
tb.AppendRow(
table.Row{
activity.Id, activity.Snippet.Title,
activity.Snippet.Type, activity.Snippet.PublishedAt,
},
)
}
}
common.PrintList(a.Output, activities, writer, table.Row{"ID", "Title", "Type", "Time"}, func(a *youtube.Activity) table.Row {
return table.Row{a.Id, a.Snippet.Title, a.Snippet.Type, a.Snippet.PublishedAt}
})
return err
}
-1
View File
@@ -8,7 +8,6 @@ go_library(
deps = [
"//pkg",
"//pkg/common",
"//pkg/utils",
"@com_github_jedib0t_go_pretty_v6//table",
"@org_golang_google_api//youtube/v3:youtube",
],
+5 -39
View File
@@ -11,7 +11,6 @@ import (
"github.com/eat-pray-ai/yutu/pkg"
"github.com/eat-pray-ai/yutu/pkg/common"
"github.com/eat-pray-ai/yutu/pkg/utils"
"github.com/jedib0t/go-pretty/v6/table"
"google.golang.org/api/youtube/v3"
)
@@ -94,26 +93,9 @@ func (c *Caption) List(writer io.Writer) error {
return err
}
switch c.Output {
case "json":
utils.PrintJSON(captions, writer)
case "yaml":
utils.PrintYAML(captions, writer)
case "table":
tb := table.NewWriter()
tb.SetOutputMirror(writer)
tb.SetStyle(pkg.TableStyle)
tb.AppendHeader(table.Row{"ID", "Video ID", "Name", "Language"})
defer tb.Render()
for _, caption := range captions {
tb.AppendRow(
table.Row{
caption.Id, caption.Snippet.VideoId,
caption.Snippet.Name, caption.Snippet.Language,
},
)
}
}
common.PrintList(c.Output, captions, writer, table.Row{"ID", "Video ID", "Name", "Language"}, func(cap *youtube.Caption) table.Row {
return table.Row{cap.Id, cap.Snippet.VideoId, cap.Snippet.Name, cap.Snippet.Language}
})
return nil
}
@@ -157,15 +139,7 @@ func (c *Caption) Insert(writer io.Writer) error {
return errors.Join(errInsertCaption, err)
}
switch c.Output {
case "json":
utils.PrintJSON(res, writer)
case "yaml":
utils.PrintYAML(res, writer)
case "silent":
default:
_, _ = fmt.Fprintf(writer, "Caption inserted: %s\n", res.Id)
}
common.PrintResult(c.Output, res, writer, "Caption inserted: %s\n", res.Id)
return nil
}
@@ -234,15 +208,7 @@ func (c *Caption) Update(writer io.Writer) error {
return errors.Join(errUpdateCaption, err)
}
switch c.Output {
case "json":
utils.PrintJSON(res, writer)
case "yaml":
utils.PrintYAML(res, writer)
case "silent":
default:
_, _ = fmt.Fprintf(writer, "Caption updated: %s\n", res.Id)
}
common.PrintResult(c.Output, res, writer, "Caption updated: %s\n", res.Id)
return nil
}
-2
View File
@@ -6,9 +6,7 @@ go_library(
importpath = "github.com/eat-pray-ai/yutu/pkg/channel",
visibility = ["//visibility:public"],
deps = [
"//pkg",
"//pkg/common",
"//pkg/utils",
"@com_github_jedib0t_go_pretty_v6//table",
"@org_golang_google_api//youtube/v3:youtube",
],
+9 -34
View File
@@ -5,12 +5,9 @@ package channel
import (
"errors"
"fmt"
"io"
"github.com/eat-pray-ai/yutu/pkg"
"github.com/eat-pray-ai/yutu/pkg/common"
"github.com/eat-pray-ai/yutu/pkg/utils"
"github.com/jedib0t/go-pretty/v6/table"
"google.golang.org/api/youtube/v3"
@@ -96,29 +93,15 @@ func (c *Channel) List(writer io.Writer) error {
return err
}
switch c.Output {
case "json":
utils.PrintJSON(channels, writer)
case "yaml":
utils.PrintYAML(channels, writer)
case "table":
tb := table.NewWriter()
defer tb.Render()
tb.SetOutputMirror(writer)
tb.SetStyle(pkg.TableStyle)
tb.AppendHeader(table.Row{"ID", "Title", "Country"})
for _, channel := range channels {
title := ""
country := ""
if channel.Snippet != nil {
title = channel.Snippet.Title
country = channel.Snippet.Country
}
tb.AppendRow(
table.Row{channel.Id, title, country},
)
common.PrintList(c.Output, channels, writer, table.Row{"ID", "Title", "Country"}, func(ch *youtube.Channel) table.Row {
title := ""
country := ""
if ch.Snippet != nil {
title = ch.Snippet.Title
country = ch.Snippet.Country
}
}
return table.Row{ch.Id, title, country}
})
return err
}
@@ -155,15 +138,7 @@ func (c *Channel) Update(writer io.Writer) error {
return errors.Join(errUpdateChannel, err)
}
switch c.Output {
case "json":
utils.PrintJSON(res, writer)
case "yaml":
utils.PrintYAML(res, writer)
case "silent":
default:
_, _ = fmt.Fprintf(writer, "Channel updated: %s\n", res.Id)
}
common.PrintResult(c.Output, res, writer, "Channel updated: %s\n", res.Id)
return nil
}
-1
View File
@@ -8,7 +8,6 @@ go_library(
deps = [
"//pkg",
"//pkg/common",
"//pkg/utils",
"@org_golang_google_api//youtube/v3:youtube",
],
)
+1 -11
View File
@@ -5,13 +5,11 @@ package channelBanner
import (
"errors"
"fmt"
"io"
"os"
"github.com/eat-pray-ai/yutu/pkg"
"github.com/eat-pray-ai/yutu/pkg/common"
"github.com/eat-pray-ai/yutu/pkg/utils"
"google.golang.org/api/youtube/v3"
)
@@ -66,15 +64,7 @@ func (cb *ChannelBanner) Insert(writer io.Writer) error {
return errors.Join(errInsertChannelBanner, err)
}
switch cb.Output {
case "json":
utils.PrintJSON(res, writer)
case "yaml":
utils.PrintYAML(res, writer)
case "silent":
default:
_, _ = fmt.Fprintf(writer, "ChannelBanner inserted: %s\n", res.Url)
}
common.PrintResult(cb.Output, res, writer, "ChannelBanner inserted: %s\n", res.Url)
return nil
}
-2
View File
@@ -6,9 +6,7 @@ go_library(
importpath = "github.com/eat-pray-ai/yutu/pkg/channelSection",
visibility = ["//visibility:public"],
deps = [
"//pkg",
"//pkg/common",
"//pkg/utils",
"@com_github_jedib0t_go_pretty_v6//table",
"@org_golang_google_api//youtube/v3:youtube",
],
+3 -17
View File
@@ -8,9 +8,7 @@ import (
"fmt"
"io"
"github.com/eat-pray-ai/yutu/pkg"
"github.com/eat-pray-ai/yutu/pkg/common"
"github.com/eat-pray-ai/yutu/pkg/utils"
"github.com/jedib0t/go-pretty/v6/table"
"google.golang.org/api/youtube/v3"
)
@@ -83,21 +81,9 @@ func (cs *ChannelSection) List(writer io.Writer) error {
return err
}
switch cs.Output {
case "json":
utils.PrintJSON(channelSections, writer)
case "yaml":
utils.PrintYAML(channelSections, writer)
case "table":
tb := table.NewWriter()
defer tb.Render()
tb.SetOutputMirror(writer)
tb.SetStyle(pkg.TableStyle)
tb.AppendHeader(table.Row{"ID", "Channel ID", "Title"})
for _, chs := range channelSections {
tb.AppendRow(table.Row{chs.Id, chs.Snippet.ChannelId, chs.Snippet.Title})
}
}
common.PrintList(cs.Output, channelSections, writer, table.Row{"ID", "Channel ID", "Title"}, func(s *youtube.ChannelSection) table.Row {
return table.Row{s.Id, s.Snippet.ChannelId, s.Snippet.Title}
})
return nil
}
-2
View File
@@ -6,9 +6,7 @@ go_library(
importpath = "github.com/eat-pray-ai/yutu/pkg/comment",
visibility = ["//visibility:public"],
deps = [
"//pkg",
"//pkg/common",
"//pkg/utils",
"@com_github_jedib0t_go_pretty_v6//table",
"@org_golang_google_api//youtube/v3:youtube",
],
+14 -67
View File
@@ -8,9 +8,7 @@ import (
"fmt"
"io"
"github.com/eat-pray-ai/yutu/pkg"
"github.com/eat-pray-ai/yutu/pkg/common"
"github.com/eat-pray-ai/yutu/pkg/utils"
"github.com/jedib0t/go-pretty/v6/table"
"google.golang.org/api/youtube/v3"
)
@@ -83,33 +81,17 @@ func (c *Comment) List(writer io.Writer) error {
return err
}
switch c.Output {
case "json":
utils.PrintJSON(comments, writer)
case "yaml":
utils.PrintYAML(comments, writer)
case "table":
tb := table.NewWriter()
defer tb.Render()
tb.SetOutputMirror(writer)
tb.SetStyle(pkg.TableStyle)
tb.AppendHeader(table.Row{"ID", "Author", "Video ID", "Text Display"})
for _, comment := range comments {
author := ""
videoId := ""
textDisplay := ""
if comment.Snippet != nil {
author = comment.Snippet.AuthorDisplayName
videoId = comment.Snippet.VideoId
textDisplay = comment.Snippet.TextDisplay
}
tb.AppendRow(
table.Row{
comment.Id, author, videoId, textDisplay,
},
)
common.PrintList(c.Output, comments, writer, table.Row{"ID", "Author", "Video ID", "Text Display"}, func(cm *youtube.Comment) table.Row {
author := ""
videoId := ""
textDisplay := ""
if cm.Snippet != nil {
author = cm.Snippet.AuthorDisplayName
videoId = cm.Snippet.VideoId
textDisplay = cm.Snippet.TextDisplay
}
}
return table.Row{cm.Id, author, videoId, textDisplay}
})
return err
}
@@ -139,15 +121,7 @@ func (c *Comment) Insert(writer io.Writer) error {
return errors.Join(errInsertComment, err)
}
switch c.Output {
case "json":
utils.PrintJSON(res, writer)
case "yaml":
utils.PrintYAML(res, writer)
case "silent":
default:
_, _ = fmt.Fprintf(writer, "Comment inserted: %s\n", res.Id)
}
common.PrintResult(c.Output, res, writer, "Comment inserted: %s\n", res.Id)
return nil
}
@@ -184,15 +158,7 @@ func (c *Comment) Update(writer io.Writer) error {
return errors.Join(errUpdateComment, err)
}
switch c.Output {
case "json":
utils.PrintJSON(res, writer)
case "yaml":
utils.PrintYAML(res, writer)
case "silent":
default:
_, _ = fmt.Fprintf(writer, "Comment updated: %s\n", res.Id)
}
common.PrintResult(c.Output, res, writer, "Comment updated: %s\n", res.Id)
return nil
}
@@ -206,15 +172,7 @@ func (c *Comment) MarkAsSpam(writer io.Writer) error {
return errors.Join(errMarkAsSpam, err)
}
switch c.Output {
case "json":
utils.PrintJSON(c, writer)
case "yaml":
utils.PrintYAML(c, writer)
case "silent":
default:
_, _ = fmt.Fprintf(writer, "Comment marked as spam: %s\n", c.Ids)
}
common.PrintResult(c.Output, c, writer, "Comment marked as spam: %s\n", c.Ids)
return nil
}
@@ -233,18 +191,7 @@ func (c *Comment) SetModerationStatus(writer io.Writer) error {
return errors.Join(errSetModerationStatus, err)
}
switch c.Output {
case "json":
utils.PrintJSON(c, writer)
case "yaml":
utils.PrintYAML(c, writer)
case "silent":
default:
_, _ = fmt.Fprintf(
writer, "Comment moderation status set to %s: %s\n",
c.ModerationStatus, c.Ids,
)
}
common.PrintResult(c.Output, c, writer, "Comment moderation status set to %s: %s\n", c.ModerationStatus, c.Ids)
return nil
}
-2
View File
@@ -6,9 +6,7 @@ go_library(
importpath = "github.com/eat-pray-ai/yutu/pkg/commentThread",
visibility = ["//visibility:public"],
deps = [
"//pkg",
"//pkg/common",
"//pkg/utils",
"@com_github_jedib0t_go_pretty_v6//table",
"@org_golang_google_api//youtube/v3:youtube",
],
+5 -33
View File
@@ -5,12 +5,9 @@ package commentThread
import (
"errors"
"fmt"
"io"
"github.com/eat-pray-ai/yutu/pkg"
"github.com/eat-pray-ai/yutu/pkg/common"
"github.com/eat-pray-ai/yutu/pkg/utils"
"github.com/jedib0t/go-pretty/v6/table"
"google.golang.org/api/youtube/v3"
)
@@ -90,27 +87,10 @@ func (c *CommentThread) List(writer io.Writer) error {
return err
}
switch c.Output {
case "json":
utils.PrintJSON(commentThreads, writer)
case "yaml":
utils.PrintYAML(commentThreads, writer)
case "table":
tb := table.NewWriter()
defer tb.Render()
tb.SetOutputMirror(writer)
tb.SetStyle(pkg.TableStyle)
tb.AppendHeader(table.Row{"ID", "Author", "Video ID", "Text Display"})
for _, cot := range commentThreads {
snippet := cot.Snippet.TopLevelComment.Snippet
tb.AppendRow(
table.Row{
cot.Id, snippet.AuthorDisplayName,
snippet.VideoId, snippet.TextDisplay,
},
)
}
}
common.PrintList(c.Output, commentThreads, writer, table.Row{"ID", "Author", "Video ID", "Text Display"}, func(cot *youtube.CommentThread) table.Row {
snippet := cot.Snippet.TopLevelComment.Snippet
return table.Row{cot.Id, snippet.AuthorDisplayName, snippet.VideoId, snippet.TextDisplay}
})
return err
}
@@ -139,15 +119,7 @@ func (c *CommentThread) Insert(writer io.Writer) error {
return errors.Join(errInsertCommentThread, err)
}
switch c.Output {
case "json":
utils.PrintJSON(res, writer)
case "yaml":
utils.PrintYAML(res, writer)
case "silent":
default:
_, _ = fmt.Fprintf(writer, "CommentThread inserted: %s\n", res.Id)
}
common.PrintResult(c.Output, res, writer, "CommentThread inserted: %s\n", res.Id)
return nil
}
+2
View File
@@ -11,6 +11,8 @@ go_library(
deps = [
"//pkg",
"//pkg/auth",
"//pkg/utils",
"@com_github_jedib0t_go_pretty_v6//table",
"@org_golang_google_api//googleapi",
"@org_golang_google_api//option",
"@org_golang_google_api//youtube/v3:youtube",
+36
View File
@@ -6,10 +6,13 @@ package common
import (
"errors"
"fmt"
"io"
"math"
"github.com/eat-pray-ai/yutu/pkg"
"github.com/eat-pray-ai/yutu/pkg/auth"
"github.com/eat-pray-ai/yutu/pkg/utils"
"github.com/jedib0t/go-pretty/v6/table"
"google.golang.org/api/googleapi"
"google.golang.org/api/youtube/v3"
)
@@ -103,6 +106,39 @@ func WithOnBehalfOfContentOwner[T HasFields](owner string) func(T) {
}
}
// PrintList handles the json/yaml/table output switch for List methods.
// The header and row function are only used for table output.
func PrintList[T any](output string, items []*T, w io.Writer, header table.Row, row func(*T) table.Row) {
switch output {
case "json":
utils.PrintJSON(items, w)
case "yaml":
utils.PrintYAML(items, w)
case "table":
tb := table.NewWriter()
defer tb.Render()
tb.SetOutputMirror(w)
tb.SetStyle(pkg.TableStyle)
tb.AppendHeader(header)
for _, item := range items {
tb.AppendRow(row(item))
}
}
}
// PrintResult handles the json/yaml/silent/default output switch for mutation methods.
func PrintResult(output string, data any, w io.Writer, format string, args ...any) {
switch output {
case "json":
utils.PrintJSON(data, w)
case "yaml":
utils.PrintYAML(data, w)
case "silent":
default:
_, _ = fmt.Fprintf(w, format, args...)
}
}
// PagedLister is satisfied by all YouTube API *XxxListCall types.
type PagedLister[C any, R any] interface {
MaxResults(int64) C
-2
View File
@@ -6,9 +6,7 @@ go_library(
importpath = "github.com/eat-pray-ai/yutu/pkg/i18nLanguage",
visibility = ["//visibility:public"],
deps = [
"//pkg",
"//pkg/common",
"//pkg/utils",
"@com_github_jedib0t_go_pretty_v6//table",
"@org_golang_google_api//youtube/v3:youtube",
],
+4 -18
View File
@@ -7,9 +7,7 @@ import (
"errors"
"io"
"github.com/eat-pray-ai/yutu/pkg"
"github.com/eat-pray-ai/yutu/pkg/common"
"github.com/eat-pray-ai/yutu/pkg/utils"
"github.com/jedib0t/go-pretty/v6/table"
"google.golang.org/api/youtube/v3"
)
@@ -57,26 +55,14 @@ func (i *I18nLanguage) Get() (
}
func (i *I18nLanguage) List(writer io.Writer) error {
i18nLanguages, err := i.Get()
languages, err := i.Get()
if err != nil {
return err
}
switch i.Output {
case "json":
utils.PrintJSON(i18nLanguages, writer)
case "yaml":
utils.PrintYAML(i18nLanguages, writer)
case "table":
tb := table.NewWriter()
defer tb.Render()
tb.SetOutputMirror(writer)
tb.SetStyle(pkg.TableStyle)
tb.AppendHeader(table.Row{"ID", "Hl", "Name"})
for _, lang := range i18nLanguages {
tb.AppendRow(table.Row{lang.Id, lang.Snippet.Hl, lang.Snippet.Name})
}
}
common.PrintList(i.Output, languages, writer, table.Row{"ID", "Hl", "Name"}, func(l *youtube.I18nLanguage) table.Row {
return table.Row{l.Id, l.Snippet.Hl, l.Snippet.Name}
})
return nil
}
-2
View File
@@ -6,9 +6,7 @@ go_library(
importpath = "github.com/eat-pray-ai/yutu/pkg/i18nRegion",
visibility = ["//visibility:public"],
deps = [
"//pkg",
"//pkg/common",
"//pkg/utils",
"@com_github_jedib0t_go_pretty_v6//table",
"@org_golang_google_api//youtube/v3:youtube",
],
+4 -18
View File
@@ -7,9 +7,7 @@ import (
"errors"
"io"
"github.com/eat-pray-ai/yutu/pkg"
"github.com/eat-pray-ai/yutu/pkg/common"
"github.com/eat-pray-ai/yutu/pkg/utils"
"github.com/jedib0t/go-pretty/v6/table"
"google.golang.org/api/youtube/v3"
)
@@ -55,26 +53,14 @@ func (i *I18nRegion) Get() ([]*youtube.I18nRegion, error) {
}
func (i *I18nRegion) List(writer io.Writer) error {
i18nRegions, err := i.Get()
regions, err := i.Get()
if err != nil {
return err
}
switch i.Output {
case "json":
utils.PrintJSON(i18nRegions, writer)
case "yaml":
utils.PrintYAML(i18nRegions, writer)
case "table":
tb := table.NewWriter()
defer tb.Render()
tb.SetOutputMirror(writer)
tb.SetStyle(pkg.TableStyle)
tb.AppendHeader(table.Row{"ID", "Gl", "Name"})
for _, region := range i18nRegions {
tb.AppendRow(table.Row{region.Id, region.Snippet.Gl, region.Snippet.Name})
}
}
common.PrintList(i.Output, regions, writer, table.Row{"ID", "Gl", "Name"}, func(r *youtube.I18nRegion) table.Row {
return table.Row{r.Id, r.Snippet.Gl, r.Snippet.Name}
})
return nil
}
-2
View File
@@ -6,9 +6,7 @@ go_library(
importpath = "github.com/eat-pray-ai/yutu/pkg/member",
visibility = ["//visibility:public"],
deps = [
"//pkg",
"//pkg/common",
"//pkg/utils",
"@com_github_jedib0t_go_pretty_v6//table",
"@org_golang_google_api//youtube/v3:youtube",
],
+3 -22
View File
@@ -7,9 +7,7 @@ import (
"errors"
"io"
"github.com/eat-pray-ai/yutu/pkg"
"github.com/eat-pray-ai/yutu/pkg/common"
"github.com/eat-pray-ai/yutu/pkg/utils"
"github.com/jedib0t/go-pretty/v6/table"
"google.golang.org/api/youtube/v3"
)
@@ -66,26 +64,9 @@ func (m *Member) List(writer io.Writer) error {
return err
}
switch m.Output {
case "json":
utils.PrintJSON(members, writer)
case "yaml":
utils.PrintYAML(members, writer)
case "table":
tb := table.NewWriter()
defer tb.Render()
tb.SetOutputMirror(writer)
tb.SetStyle(pkg.TableStyle)
tb.AppendHeader(table.Row{"Channel ID", "Display Name"})
for _, member := range members {
tb.AppendRow(
table.Row{
member.Snippet.MemberDetails.ChannelId,
member.Snippet.MemberDetails.DisplayName,
},
)
}
}
common.PrintList(m.Output, members, writer, table.Row{"Channel ID", "Display Name"}, func(m *youtube.Member) table.Row {
return table.Row{m.Snippet.MemberDetails.ChannelId, m.Snippet.MemberDetails.DisplayName}
})
return err
}
-2
View File
@@ -6,9 +6,7 @@ go_library(
importpath = "github.com/eat-pray-ai/yutu/pkg/membershipsLevel",
visibility = ["//visibility:public"],
deps = [
"//pkg",
"//pkg/common",
"//pkg/utils",
"@com_github_jedib0t_go_pretty_v6//table",
"@org_golang_google_api//youtube/v3:youtube",
],
+4 -18
View File
@@ -7,9 +7,7 @@ import (
"errors"
"io"
"github.com/eat-pray-ai/yutu/pkg"
"github.com/eat-pray-ai/yutu/pkg/common"
"github.com/eat-pray-ai/yutu/pkg/utils"
"github.com/jedib0t/go-pretty/v6/table"
"google.golang.org/api/youtube/v3"
)
@@ -55,26 +53,14 @@ func (m *MembershipsLevel) Get() ([]*youtube.MembershipsLevel, error) {
}
func (m *MembershipsLevel) List(writer io.Writer) error {
membershipsLevels, err := m.Get()
levels, err := m.Get()
if err != nil {
return err
}
switch m.Output {
case "json":
utils.PrintJSON(membershipsLevels, writer)
case "yaml":
utils.PrintYAML(membershipsLevels, writer)
case "table":
tb := table.NewWriter()
defer tb.Render()
tb.SetOutputMirror(writer)
tb.SetStyle(pkg.TableStyle)
tb.AppendHeader(table.Row{"ID", "Display Name"})
for _, ml := range membershipsLevels {
tb.AppendRow(table.Row{ml.Id, ml.Snippet.LevelDetails.DisplayName})
}
}
common.PrintList(m.Output, levels, writer, table.Row{"ID", "Display Name"}, func(ml *youtube.MembershipsLevel) table.Row {
return table.Row{ml.Id, ml.Snippet.LevelDetails.DisplayName}
})
return nil
}
-2
View File
@@ -6,9 +6,7 @@ go_library(
importpath = "github.com/eat-pray-ai/yutu/pkg/playlist",
visibility = ["//visibility:public"],
deps = [
"//pkg",
"//pkg/common",
"//pkg/utils",
"@com_github_jedib0t_go_pretty_v6//table",
"@org_golang_google_api//youtube/v3:youtube",
],
+10 -40
View File
@@ -8,9 +8,7 @@ import (
"fmt"
"io"
"github.com/eat-pray-ai/yutu/pkg"
"github.com/eat-pray-ai/yutu/pkg/common"
"github.com/eat-pray-ai/yutu/pkg/utils"
"github.com/jedib0t/go-pretty/v6/table"
"google.golang.org/api/youtube/v3"
)
@@ -88,27 +86,15 @@ func (p *Playlist) List(writer io.Writer) error {
return err
}
switch p.Output {
case "json":
utils.PrintJSON(playlists, writer)
case "yaml":
utils.PrintYAML(playlists, writer)
case "table":
tb := table.NewWriter()
defer tb.Render()
tb.SetOutputMirror(writer)
tb.SetStyle(pkg.TableStyle)
tb.AppendHeader(table.Row{"ID", "Channel ID", "Title"})
for _, pl := range playlists {
channelId := ""
title := ""
if pl.Snippet != nil {
channelId = pl.Snippet.ChannelId
title = pl.Snippet.Title
}
tb.AppendRow(table.Row{pl.Id, channelId, title})
common.PrintList(p.Output, playlists, writer, table.Row{"ID", "Channel ID", "Title"}, func(pl *youtube.Playlist) table.Row {
channelId := ""
title := ""
if pl.Snippet != nil {
channelId = pl.Snippet.ChannelId
title = pl.Snippet.Title
}
}
return table.Row{pl.Id, channelId, title}
})
return err
}
@@ -141,15 +127,7 @@ func (p *Playlist) Insert(writer io.Writer) error {
return errors.Join(errInsertPlaylist, err)
}
switch p.Output {
case "json":
utils.PrintJSON(res, writer)
case "yaml":
utils.PrintYAML(res, writer)
case "silent":
default:
_, _ = fmt.Fprintf(writer, "Playlist inserted: %s\n", res.Id)
}
common.PrintResult(p.Output, res, writer, "Playlist inserted: %s\n", res.Id)
return nil
}
@@ -191,15 +169,7 @@ func (p *Playlist) Update(writer io.Writer) error {
return errors.Join(errUpdatePlaylist, err)
}
switch p.Output {
case "json":
utils.PrintJSON(res, writer)
case "yaml":
utils.PrintYAML(res, writer)
case "silent":
default:
_, _ = fmt.Fprintf(writer, "Playlist updated: %s\n", res.Id)
}
common.PrintResult(p.Output, res, writer, "Playlist updated: %s\n", res.Id)
return nil
}
-1
View File
@@ -8,7 +8,6 @@ go_library(
deps = [
"//pkg",
"//pkg/common",
"//pkg/utils",
"@com_github_jedib0t_go_pretty_v6//table",
"@org_golang_google_api//youtube/v3:youtube",
],
+5 -36
View File
@@ -11,7 +11,6 @@ import (
"github.com/eat-pray-ai/yutu/pkg"
"github.com/eat-pray-ai/yutu/pkg/common"
"github.com/eat-pray-ai/yutu/pkg/utils"
"github.com/jedib0t/go-pretty/v6/table"
"google.golang.org/api/youtube/v3"
)
@@ -80,23 +79,9 @@ func (pi *PlaylistImage) List(writer io.Writer) error {
return err
}
switch pi.Output {
case "json":
utils.PrintJSON(playlistImages, writer)
case "yaml":
utils.PrintYAML(playlistImages, writer)
case "table":
tb := table.NewWriter()
defer tb.Render()
tb.SetOutputMirror(writer)
tb.SetStyle(pkg.TableStyle)
tb.AppendHeader(table.Row{"ID", "Kind", "Playlist ID", "Type"})
for _, img := range playlistImages {
tb.AppendRow(
table.Row{img.Id, img.Kind, img.Snippet.PlaylistId, img.Snippet.Type},
)
}
}
common.PrintList(pi.Output, playlistImages, writer, table.Row{"ID", "Kind", "Playlist ID", "Type"}, func(img *youtube.PlaylistImage) table.Row {
return table.Row{img.Id, img.Kind, img.Snippet.PlaylistId, img.Snippet.Type}
})
return err
}
@@ -136,15 +121,7 @@ func (pi *PlaylistImage) Insert(writer io.Writer) error {
return errors.Join(errInsertPlaylistImage, err)
}
switch pi.Output {
case "json":
utils.PrintJSON(res, writer)
case "yaml":
utils.PrintYAML(res, writer)
case "silent":
default:
_, _ = fmt.Fprintf(writer, "PlaylistImage inserted: %s\n", res.Id)
}
common.PrintResult(pi.Output, res, writer, "PlaylistImage inserted: %s\n", res.Id)
return nil
}
@@ -196,15 +173,7 @@ func (pi *PlaylistImage) Update(writer io.Writer) error {
return errors.Join(errUpdatePlaylistImage, err)
}
switch pi.Output {
case "json":
utils.PrintJSON(res, writer)
case "yaml":
utils.PrintYAML(res, writer)
case "silent":
default:
_, _ = fmt.Fprintf(writer, "PlaylistImage updated: %s\n", res.Id)
}
common.PrintResult(pi.Output, res, writer, "PlaylistImage updated: %s\n", res.Id)
return nil
}
-2
View File
@@ -6,9 +6,7 @@ go_library(
importpath = "github.com/eat-pray-ai/yutu/pkg/playlistItem",
visibility = ["//visibility:public"],
deps = [
"//pkg",
"//pkg/common",
"//pkg/utils",
"@com_github_jedib0t_go_pretty_v6//table",
"@org_golang_google_api//youtube/v3:youtube",
],
+19 -53
View File
@@ -8,9 +8,7 @@ import (
"fmt"
"io"
"github.com/eat-pray-ai/yutu/pkg"
"github.com/eat-pray-ai/yutu/pkg/common"
"github.com/eat-pray-ai/yutu/pkg/utils"
"github.com/jedib0t/go-pretty/v6/table"
"google.golang.org/api/youtube/v3"
)
@@ -82,42 +80,26 @@ func (pi *PlaylistItem) List(writer io.Writer) error {
return err
}
switch pi.Output {
case "json":
utils.PrintJSON(playlistItems, writer)
case "yaml":
utils.PrintYAML(playlistItems, writer)
case "table":
tb := table.NewWriter()
defer tb.Render()
tb.SetOutputMirror(writer)
tb.SetStyle(pkg.TableStyle)
tb.AppendHeader(table.Row{"ID", "Title", "Kind", "Resource ID"})
for _, item := range playlistItems {
var resourceId string
var title string
var kind string
if item.Snippet != nil {
title = item.Snippet.Title
if item.Snippet.ResourceId != nil {
kind = item.Snippet.ResourceId.Kind
switch item.Snippet.ResourceId.Kind {
case "youtube#video":
resourceId = item.Snippet.ResourceId.VideoId
case "youtube#channel":
resourceId = item.Snippet.ResourceId.ChannelId
case "youtube#playlist":
resourceId = item.Snippet.ResourceId.PlaylistId
}
common.PrintList(pi.Output, playlistItems, writer, table.Row{"ID", "Title", "Kind", "Resource ID"}, func(item *youtube.PlaylistItem) table.Row {
title := ""
kind := ""
resourceId := ""
if item.Snippet != nil {
title = item.Snippet.Title
if item.Snippet.ResourceId != nil {
kind = item.Snippet.ResourceId.Kind
switch kind {
case "youtube#video":
resourceId = item.Snippet.ResourceId.VideoId
case "youtube#channel":
resourceId = item.Snippet.ResourceId.ChannelId
case "youtube#playlist":
resourceId = item.Snippet.ResourceId.PlaylistId
}
}
tb.AppendRow(
table.Row{
item.Id, title, kind, resourceId,
},
)
}
}
return table.Row{item.Id, title, kind, resourceId}
})
return err
}
@@ -169,15 +151,7 @@ func (pi *PlaylistItem) Insert(writer io.Writer) error {
return errors.Join(errInsertPlaylistItem, err)
}
switch pi.Output {
case "json":
utils.PrintJSON(res, writer)
case "yaml":
utils.PrintYAML(res, writer)
case "silent":
default:
_, _ = fmt.Fprintf(writer, "Playlist Item inserted: %s\n", res.Id)
}
common.PrintResult(pi.Output, res, writer, "Playlist Item inserted: %s\n", res.Id)
return nil
}
@@ -218,15 +192,7 @@ func (pi *PlaylistItem) Update(writer io.Writer) error {
return errors.Join(errUpdatePlaylistItem, err)
}
switch pi.Output {
case "json":
utils.PrintJSON(res, writer)
case "yaml":
utils.PrintYAML(res, writer)
case "silent":
default:
_, _ = fmt.Fprintf(writer, "Playlist Item updated: %s\n", res.Id)
}
common.PrintResult(pi.Output, res, writer, "Playlist Item updated: %s\n", res.Id)
return nil
}
-2
View File
@@ -6,9 +6,7 @@ go_library(
importpath = "github.com/eat-pray-ai/yutu/pkg/search",
visibility = ["//visibility:public"],
deps = [
"//pkg",
"//pkg/common",
"//pkg/utils",
"@com_github_jedib0t_go_pretty_v6//table",
"@org_golang_google_api//youtube/v3:youtube",
],
+11 -27
View File
@@ -7,9 +7,7 @@ import (
"errors"
"io"
"github.com/eat-pray-ai/yutu/pkg"
"github.com/eat-pray-ai/yutu/pkg/common"
"github.com/eat-pray-ai/yutu/pkg/utils"
"github.com/jedib0t/go-pretty/v6/table"
"google.golang.org/api/youtube/v3"
)
@@ -164,32 +162,18 @@ func (s *Search) List(writer io.Writer) error {
return err
}
switch s.Output {
case "json":
utils.PrintJSON(results, writer)
case "yaml":
utils.PrintYAML(results, writer)
case "table":
tb := table.NewWriter()
defer tb.Render()
tb.SetOutputMirror(writer)
tb.SetStyle(pkg.TableStyle)
tb.AppendHeader(table.Row{"Kind", "Title", "Resource ID"})
for _, result := range results {
var resourceId string
switch result.Id.Kind {
case "youtube#video":
resourceId = result.Id.VideoId
case "youtube#channel":
resourceId = result.Id.ChannelId
case "youtube#playlist":
resourceId = result.Id.PlaylistId
}
tb.AppendRow(
table.Row{result.Id.Kind, result.Snippet.Title, resourceId},
)
common.PrintList(s.Output, results, writer, table.Row{"Kind", "Title", "Resource ID"}, func(r *youtube.SearchResult) table.Row {
var resourceId string
switch r.Id.Kind {
case "youtube#video":
resourceId = r.Id.VideoId
case "youtube#channel":
resourceId = r.Id.ChannelId
case "youtube#playlist":
resourceId = r.Id.PlaylistId
}
}
return table.Row{r.Id.Kind, r.Snippet.Title, resourceId}
})
return err
}
-2
View File
@@ -6,9 +6,7 @@ go_library(
importpath = "github.com/eat-pray-ai/yutu/pkg/subscription",
visibility = ["//visibility:public"],
deps = [
"//pkg",
"//pkg/common",
"//pkg/utils",
"@com_github_jedib0t_go_pretty_v6//table",
"@org_golang_google_api//youtube/v3:youtube",
],
+12 -37
View File
@@ -8,9 +8,7 @@ import (
"fmt"
"io"
"github.com/eat-pray-ai/yutu/pkg"
"github.com/eat-pray-ai/yutu/pkg/common"
"github.com/eat-pray-ai/yutu/pkg/utils"
"github.com/jedib0t/go-pretty/v6/table"
"google.golang.org/api/youtube/v3"
)
@@ -96,34 +94,18 @@ func (s *Subscription) List(writer io.Writer) error {
return err
}
switch s.Output {
case "json":
utils.PrintJSON(subscriptions, writer)
case "yaml":
utils.PrintYAML(subscriptions, writer)
case "table":
tb := table.NewWriter()
defer tb.Render()
tb.SetOutputMirror(writer)
tb.SetStyle(pkg.TableStyle)
tb.AppendHeader(table.Row{"ID", "Kind", "Resource ID", "Channel Title"})
for _, sub := range subscriptions {
var resourceId string
switch sub.Snippet.ResourceId.Kind {
case "youtube#video":
resourceId = sub.Snippet.ResourceId.VideoId
case "youtube#channel":
resourceId = sub.Snippet.ResourceId.ChannelId
case "youtube#playlist":
resourceId = sub.Snippet.ResourceId.PlaylistId
}
tb.AppendRow(
table.Row{
sub.Id, sub.Snippet.ResourceId.Kind, resourceId, sub.Snippet.Title,
},
)
common.PrintList(s.Output, subscriptions, writer, table.Row{"ID", "Kind", "Resource ID", "Channel Title"}, func(sub *youtube.Subscription) table.Row {
var resourceId string
switch sub.Snippet.ResourceId.Kind {
case "youtube#video":
resourceId = sub.Snippet.ResourceId.VideoId
case "youtube#channel":
resourceId = sub.Snippet.ResourceId.ChannelId
case "youtube#playlist":
resourceId = sub.Snippet.ResourceId.PlaylistId
}
}
return table.Row{sub.Id, sub.Snippet.ResourceId.Kind, resourceId, sub.Snippet.Title}
})
return err
}
@@ -148,14 +130,7 @@ func (s *Subscription) Insert(writer io.Writer) error {
return errors.Join(errInsertSubscription, err)
}
switch s.Output {
case "json":
utils.PrintJSON(res, writer)
case "yaml":
utils.PrintYAML(res, writer)
default:
_, _ = fmt.Fprintf(writer, "Subscription inserted: %s\n", res.Id)
}
common.PrintResult(s.Output, res, writer, "Subscription inserted: %s\n", res.Id)
return nil
}
-2
View File
@@ -6,9 +6,7 @@ go_library(
importpath = "github.com/eat-pray-ai/yutu/pkg/superChatEvent",
visibility = ["//visibility:public"],
deps = [
"//pkg",
"//pkg/common",
"//pkg/utils",
"@com_github_jedib0t_go_pretty_v6//table",
"@org_golang_google_api//youtube/v3:youtube",
],
+3 -22
View File
@@ -7,9 +7,7 @@ import (
"errors"
"io"
"github.com/eat-pray-ai/yutu/pkg"
"github.com/eat-pray-ai/yutu/pkg/common"
"github.com/eat-pray-ai/yutu/pkg/utils"
"github.com/jedib0t/go-pretty/v6/table"
"google.golang.org/api/youtube/v3"
)
@@ -57,26 +55,9 @@ func (s *SuperChatEvent) List(writer io.Writer) error {
return err
}
switch s.Output {
case "json":
utils.PrintJSON(events, writer)
case "yaml":
utils.PrintYAML(events, writer)
case "table":
tb := table.NewWriter()
defer tb.Render()
tb.SetOutputMirror(writer)
tb.SetStyle(pkg.TableStyle)
tb.AppendHeader(table.Row{"ID", "Amount", "Comment", "Supporter"})
for _, event := range events {
tb.AppendRow(
table.Row{
event.Id, event.Snippet.DisplayString, event.Snippet.CommentText,
event.Snippet.SupporterDetails.DisplayName,
},
)
}
}
common.PrintList(s.Output, events, writer, table.Row{"ID", "Amount", "Comment", "Supporter"}, func(e *youtube.SuperChatEvent) table.Row {
return table.Row{e.Id, e.Snippet.DisplayString, e.Snippet.CommentText, e.Snippet.SupporterDetails.DisplayName}
})
return err
}
-1
View File
@@ -8,7 +8,6 @@ go_library(
deps = [
"//pkg",
"//pkg/common",
"//pkg/utils",
],
)
+1 -11
View File
@@ -5,12 +5,10 @@ package thumbnail
import (
"errors"
"fmt"
"io"
"github.com/eat-pray-ai/yutu/pkg"
"github.com/eat-pray-ai/yutu/pkg/common"
"github.com/eat-pray-ai/yutu/pkg/utils"
)
var (
@@ -52,15 +50,7 @@ func (t *Thumbnail) Set(writer io.Writer) error {
return errors.Join(errSetThumbnail, err)
}
switch t.Output {
case "json":
utils.PrintJSON(res, writer)
case "yaml":
utils.PrintYAML(res, writer)
case "silent":
default:
_, _ = fmt.Fprintf(writer, "Thumbnail set for video %s", t.VideoId)
}
common.PrintResult(t.Output, res, writer, "Thumbnail set for video %s", t.VideoId)
return nil
}
+14 -48
View File
@@ -130,37 +130,19 @@ func (v *Video) List(writer io.Writer) error {
return err
}
switch v.Output {
case "json":
utils.PrintJSON(videos, writer)
case "yaml":
utils.PrintYAML(videos, writer)
case "table":
tb := table.NewWriter()
defer tb.Render()
tb.SetOutputMirror(writer)
tb.SetStyle(pkg.TableStyle)
tb.AppendHeader(table.Row{"ID", "Title", "Channel ID", "Views"})
for _, video := range videos {
title := ""
channelId := ""
var views uint64
if video.Snippet != nil {
title = video.Snippet.Title
channelId = video.Snippet.ChannelId
}
if video.Statistics != nil {
views = video.Statistics.ViewCount
}
tb.AppendRow(
table.Row{
video.Id, title, channelId, views,
},
)
common.PrintList(v.Output, videos, writer, table.Row{"ID", "Title", "Channel ID", "Views"}, func(video *youtube.Video) table.Row {
title := ""
channelId := ""
var views uint64
if video.Snippet != nil {
title = video.Snippet.Title
channelId = video.Snippet.ChannelId
}
}
if video.Statistics != nil {
views = video.Statistics.ViewCount
}
return table.Row{video.Id, title, channelId, views}
})
return err
}
@@ -261,15 +243,7 @@ func (v *Video) Insert(writer io.Writer) error {
_ = pi.Insert(writer)
}
switch v.Output {
case "json":
utils.PrintJSON(res, writer)
case "yaml":
utils.PrintYAML(res, writer)
case "silent":
default:
_, _ = fmt.Fprintf(writer, "Video inserted: %s\n", res.Id)
}
common.PrintResult(v.Output, res, writer, "Video inserted: %s\n", res.Id)
return nil
}
@@ -353,15 +327,7 @@ func (v *Video) Update(writer io.Writer) error {
_ = pi.Insert(writer)
}
switch v.Output {
case "json":
utils.PrintJSON(res, writer)
case "yaml":
utils.PrintYAML(res, writer)
case "silent":
default:
_, _ = fmt.Fprintf(writer, "Video updated: %s\n", res.Id)
}
common.PrintResult(v.Output, res, writer, "Video updated: %s\n", res.Id)
return nil
}
-2
View File
@@ -6,9 +6,7 @@ go_library(
importpath = "github.com/eat-pray-ai/yutu/pkg/videoAbuseReportReason",
visibility = ["//visibility:public"],
deps = [
"//pkg",
"//pkg/common",
"//pkg/utils",
"@com_github_jedib0t_go_pretty_v6//table",
"@org_golang_google_api//youtube/v3:youtube",
],
@@ -7,9 +7,7 @@ import (
"errors"
"io"
"github.com/eat-pray-ai/yutu/pkg"
"github.com/eat-pray-ai/yutu/pkg/common"
"github.com/eat-pray-ai/yutu/pkg/utils"
"github.com/jedib0t/go-pretty/v6/table"
"google.golang.org/api/youtube/v3"
)
@@ -57,26 +55,14 @@ func (va *VideoAbuseReportReason) Get() (
}
func (va *VideoAbuseReportReason) List(writer io.Writer) error {
videoAbuseReportReasons, err := va.Get()
reasons, err := va.Get()
if err != nil {
return err
}
switch va.Output {
case "json":
utils.PrintJSON(videoAbuseReportReasons, writer)
case "yaml":
utils.PrintYAML(videoAbuseReportReasons, writer)
case "table":
tb := table.NewWriter()
defer tb.Render()
tb.SetOutputMirror(writer)
tb.SetStyle(pkg.TableStyle)
tb.AppendHeader(table.Row{"ID", "Label"})
for _, reason := range videoAbuseReportReasons {
tb.AppendRow(table.Row{reason.Id, reason.Snippet.Label})
}
}
common.PrintList(va.Output, reasons, writer, table.Row{"ID", "Label"}, func(r *youtube.VideoAbuseReportReason) table.Row {
return table.Row{r.Id, r.Snippet.Label}
})
return nil
}
-2
View File
@@ -6,9 +6,7 @@ go_library(
importpath = "github.com/eat-pray-ai/yutu/pkg/videoCategory",
visibility = ["//visibility:public"],
deps = [
"//pkg",
"//pkg/common",
"//pkg/utils",
"@com_github_jedib0t_go_pretty_v6//table",
"@org_golang_google_api//youtube/v3:youtube",
],
+4 -18
View File
@@ -7,9 +7,7 @@ import (
"errors"
"io"
"github.com/eat-pray-ai/yutu/pkg"
"github.com/eat-pray-ai/yutu/pkg/common"
"github.com/eat-pray-ai/yutu/pkg/utils"
"github.com/jedib0t/go-pretty/v6/table"
"google.golang.org/api/youtube/v3"
)
@@ -62,26 +60,14 @@ func (vc *VideoCategory) Get() ([]*youtube.VideoCategory, error) {
}
func (vc *VideoCategory) List(writer io.Writer) error {
videoCategories, err := vc.Get()
categories, err := vc.Get()
if err != nil {
return err
}
switch vc.Output {
case "json":
utils.PrintJSON(videoCategories, writer)
case "yaml":
utils.PrintYAML(videoCategories, writer)
case "table":
tb := table.NewWriter()
defer tb.Render()
tb.SetOutputMirror(writer)
tb.SetStyle(pkg.TableStyle)
tb.AppendHeader(table.Row{"ID", "Title", "Assignable"})
for _, cat := range videoCategories {
tb.AppendRow(table.Row{cat.Id, cat.Snippet.Title, cat.Snippet.Assignable})
}
}
common.PrintList(vc.Output, categories, writer, table.Row{"ID", "Title", "Assignable"}, func(c *youtube.VideoCategory) table.Row {
return table.Row{c.Id, c.Snippet.Title, c.Snippet.Assignable}
})
return nil
}