Skip to content

Commit 1a47653

Browse files
author
Alex Zamai
committed
👷 Add credentials and token flags for all subcomands
1 parent 99faadd commit 1a47653

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+435
-104
lines changed

cmd/activity/activity.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ var (
1515
regionCode string
1616
parts []string
1717
output string
18+
credential string
19+
cacheToken string
1820
)
1921

2022
var activityCmd = &cobra.Command{
@@ -28,4 +30,11 @@ var activityCmd = &cobra.Command{
2830

2931
func init() {
3032
cmd.RootCmd.AddCommand(activityCmd)
33+
34+
activityCmd.PersistentFlags().StringVarP(
35+
&credential, "credential", "c", "client_secret.json", "Path to client secret file",
36+
)
37+
activityCmd.PersistentFlags().StringVarP(
38+
&cacheToken, "cacheToken", "t", "youtube.token.json", "Path to token cache file",
39+
)
3140
}

cmd/activity/list.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package activity
22

33
import (
44
"github.com/eat-pray-ai/yutu/pkg/activity"
5+
"github.com/eat-pray-ai/yutu/pkg/auth"
56
"github.com/spf13/cobra"
67
)
78

@@ -18,7 +19,10 @@ var listCmd = &cobra.Command{
1819
activity.WithPublishedAfter(publishedAfter),
1920
activity.WithPublishedBefore(publishedBefore),
2021
activity.WithRegionCode(regionCode),
21-
activity.WithService(nil),
22+
activity.WithService(auth.NewY2BService(
23+
auth.WithCredential(credential),
24+
auth.WithCacheToken(cacheToken),
25+
)),
2226
)
2327
a.List(parts, output)
2428
},

cmd/caption/caption.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ var (
2424
output string
2525
tfmt string
2626
tlang string
27+
credential string
28+
cacheToken string
2729
)
2830

2931
var captionCmd = &cobra.Command{
@@ -37,4 +39,11 @@ var captionCmd = &cobra.Command{
3739

3840
func init() {
3941
cmd.RootCmd.AddCommand(captionCmd)
42+
43+
captionCmd.PersistentFlags().StringVarP(
44+
&credential, "credential", "c", "client_secret.json", "Path to client secret file",
45+
)
46+
captionCmd.PersistentFlags().StringVarP(
47+
&cacheToken, "cacheToken", "t", "youtube.token.json", "Path to token cache file",
48+
)
4049
}

cmd/caption/delete.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package caption
22

33
import (
4+
"github.com/eat-pray-ai/yutu/pkg/auth"
45
"github.com/eat-pray-ai/yutu/pkg/caption"
56
"github.com/spf13/cobra"
67
)
@@ -14,7 +15,10 @@ var deleteCmd = &cobra.Command{
1415
caption.WithID(id),
1516
caption.WithOnBehalfOf(onBehalfOf),
1617
caption.WithOnBehalfOfContentOwner(onBehalfOfContentOwner),
17-
caption.WithService(nil),
18+
caption.WithService(auth.NewY2BService(
19+
auth.WithCredential(credential),
20+
auth.WithCacheToken(cacheToken),
21+
)),
1822
)
1923
c.Delete()
2024
},

cmd/caption/download.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package caption
22

33
import (
4+
"github.com/eat-pray-ai/yutu/pkg/auth"
45
"github.com/eat-pray-ai/yutu/pkg/caption"
56
"github.com/spf13/cobra"
67
)
@@ -17,7 +18,10 @@ var downloadCmd = &cobra.Command{
1718
caption.WithTlang(tlang),
1819
caption.WithOnBehalfOf(onBehalfOf),
1920
caption.WithOnBehalfOfContentOwner(onBehalfOfContentOwner),
20-
caption.WithService(nil),
21+
caption.WithService(auth.NewY2BService(
22+
auth.WithCredential(credential),
23+
auth.WithCacheToken(cacheToken),
24+
)),
2125
)
2226
c.Download()
2327
},
@@ -28,7 +32,7 @@ func init() {
2832

2933
downloadCmd.Flags().StringVarP(&id, "id", "i", "", "ID of the caption")
3034
downloadCmd.Flags().StringVarP(&file, "file", "f", "", "Path to save the caption file")
31-
downloadCmd.Flags().StringVarP(&tfmt, "tfmt", "t", "", "sbv, srt or vtt")
35+
downloadCmd.Flags().StringVarP(&tfmt, "tfmt", "T", "", "sbv, srt or vtt")
3236
downloadCmd.Flags().StringVarP(&tlang, "tlang", "l", "", "Translate the captions into this language")
3337
downloadCmd.Flags().StringVarP(&onBehalfOf, "onBehalfOf", "b", "", "")
3438
downloadCmd.Flags().StringVarP(&onBehalfOfContentOwner, "onBehalfOfContentOwner", "B", "", "")

cmd/caption/insert.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package caption
22

33
import (
4+
"github.com/eat-pray-ai/yutu/pkg/auth"
45
"github.com/eat-pray-ai/yutu/pkg/caption"
56
"github.com/spf13/cobra"
67
)
@@ -24,7 +25,10 @@ var insertCmd = &cobra.Command{
2425
caption.WithOnBehalfOf(onBehalfOf),
2526
caption.WithOnBehalfOfContentOwner(onBehalfOfContentOwner),
2627
caption.WithVideoId(videoId),
27-
caption.WithService(nil),
28+
caption.WithService(auth.NewY2BService(
29+
auth.WithCredential(credential),
30+
auth.WithCacheToken(cacheToken),
31+
)),
2832
)
2933
c.Insert(output)
3034
},
@@ -55,7 +59,7 @@ func init() {
5559
)
5660
insertCmd.Flags().StringVarP(&language, "language", "l", "", "Language of the caption track")
5761
insertCmd.Flags().StringVarP(&name, "name", "n", "", "Name of the caption track")
58-
insertCmd.Flags().StringVarP(&trackKind, "trackKind", "t", "standard", "standard, ASR or forced")
62+
insertCmd.Flags().StringVarP(&trackKind, "trackKind", "T", "standard", "standard, ASR or forced")
5963
insertCmd.Flags().StringVarP(&videoId, "videoId", "v", "", "ID of the video")
6064
insertCmd.Flags().StringVarP(&onBehalfOf, "onBehalfOf", "b", "", "")
6165
insertCmd.Flags().StringVarP(&onBehalfOfContentOwner, "onBehalfOfContentOwner", "B", "", "")

cmd/caption/list.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package caption
22

33
import (
4+
"github.com/eat-pray-ai/yutu/pkg/auth"
45
"github.com/eat-pray-ai/yutu/pkg/caption"
56
"github.com/spf13/cobra"
67
)
@@ -15,7 +16,10 @@ var listCmd = &cobra.Command{
1516
caption.WithVideoId(videoId),
1617
caption.WithOnBehalfOf(onBehalfOf),
1718
caption.WithOnBehalfOfContentOwner(onBehalfOfContentOwner),
18-
caption.WithService(nil),
19+
caption.WithService(auth.NewY2BService(
20+
auth.WithCredential(credential),
21+
auth.WithCacheToken(cacheToken),
22+
)),
1923
)
2024
c.List(parts, output)
2125
},

cmd/caption/update.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package caption
22

33
import (
4+
"github.com/eat-pray-ai/yutu/pkg/auth"
45
"github.com/eat-pray-ai/yutu/pkg/caption"
56
"github.com/spf13/cobra"
67
)
@@ -24,7 +25,10 @@ var updateCmd = &cobra.Command{
2425
caption.WithOnBehalfOf(onBehalfOf),
2526
caption.WithOnBehalfOfContentOwner(onBehalfOfContentOwner),
2627
caption.WithVideoId(videoId),
27-
caption.WithService(nil),
28+
caption.WithService(auth.NewY2BService(
29+
auth.WithCredential(credential),
30+
auth.WithCacheToken(cacheToken),
31+
)),
2832
)
2933
c.Update(output)
3034
},
@@ -55,7 +59,7 @@ func init() {
5559
)
5660
updateCmd.Flags().StringVarP(&language, "language", "l", "", "Language of the caption track")
5761
updateCmd.Flags().StringVarP(&name, "name", "n", "", "Name of the caption track")
58-
updateCmd.Flags().StringVarP(&trackKind, "trackKind", "t", "standard", "standard, ASR or forced")
62+
updateCmd.Flags().StringVarP(&trackKind, "trackKind", "T", "standard", "standard, ASR or forced")
5963
updateCmd.Flags().StringVarP(&videoId, "videoId", "v", "", "ID of the video")
6064
updateCmd.Flags().StringVarP(&onBehalfOf, "onBehalfOf", "b", "", "")
6165
updateCmd.Flags().StringVarP(&onBehalfOfContentOwner, "onBehalfOfContentOwner", "B", "", "")

cmd/channel/channel.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ var (
2525
title string
2626
output string
2727
parts []string
28+
credential string
29+
cacheToken string
2830
)
2931

3032
var channelCmd = &cobra.Command{
@@ -39,13 +41,6 @@ var channelCmd = &cobra.Command{
3941
func init() {
4042
cmd.RootCmd.AddCommand(channelCmd)
4143

42-
// Here you will define your flags and configuration settings.
43-
44-
// Cobra supports Persistent Flags which will work for this command
45-
// and all subcommands, e.g.:
46-
// channelCmd.PersistentFlags().String("foo", "", "A help for foo")
47-
48-
// Cobra supports local flags which will only run when this command
49-
// is called directly, e.g.:
50-
// channelCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
44+
channelCmd.PersistentFlags().StringVarP(&credential, "credential", "c", "client_secret.json", "Path to client secret file")
45+
channelCmd.PersistentFlags().StringVarP(&cacheToken, "cacheToken", "t", "youtube.token.json", "Path to token cache file")
5146
}

cmd/channel/list.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package channel
22

33
import (
4+
"github.com/eat-pray-ai/yutu/pkg/auth"
45
"github.com/eat-pray-ai/yutu/pkg/channel"
56
"github.com/spf13/cobra"
67
)
@@ -21,7 +22,10 @@ var listCmd = &cobra.Command{
2122
channel.WithMine(mine, true),
2223
channel.WithMySubscribers(mySubscribers, true),
2324
channel.WithOnBehalfOfContentOwner(onBehalfOfContentOwner),
24-
channel.WithService(nil),
25+
channel.WithService(auth.NewY2BService(
26+
auth.WithCredential(credential),
27+
auth.WithCacheToken(cacheToken),
28+
)),
2529
)
2630
c.List(parts, output)
2731
},

0 commit comments

Comments
 (0)