lbry.go/cmd/ytsync.go

60 lines
1.3 KiB
Go
Raw Normal View History

2017-09-27 14:10:41 -04:00
package cmd
2017-09-15 07:58:54 -04:00
2017-09-15 18:13:13 -04:00
import (
2017-10-10 22:02:16 -04:00
sync "github.com/lbryio/lbry.go/ytsync"
2017-09-15 07:58:54 -04:00
2017-09-15 18:13:13 -04:00
log "github.com/sirupsen/logrus"
2017-09-27 14:10:41 -04:00
"github.com/spf13/cobra"
2017-09-15 18:13:13 -04:00
)
2017-09-27 14:10:41 -04:00
func init() {
var ytSyncCmd = &cobra.Command{
Use: "ytsync <youtube_api_key> <youtube_channel_id> [<lbry_channel_name>]",
Args: cobra.RangeArgs(2, 3),
Short: "Publish youtube channel into LBRY network.",
Run: ytsync,
}
ytSyncCmd.Flags().BoolVar(&stopOnError, "stop-on-error", false, "If a publish fails, stop all publishing and exit")
ytSyncCmd.Flags().IntVar(&maxTries, "max-tries", defaultMaxTries, "Number of times to try a publish that fails")
2017-09-27 14:10:41 -04:00
RootCmd.AddCommand(ytSyncCmd)
}
2017-10-10 22:02:16 -04:00
const defaultMaxTries = 1
2017-09-26 19:48:10 -04:00
2017-09-15 18:13:13 -04:00
var (
2017-10-10 22:02:16 -04:00
stopOnError bool
maxTries int
2017-09-15 18:13:13 -04:00
)
2017-09-27 14:10:41 -04:00
func ytsync(cmd *cobra.Command, args []string) {
2017-10-10 22:02:16 -04:00
ytAPIKey := args[0]
channelID := args[1]
lbryChannelName := ""
2017-09-27 14:10:41 -04:00
if len(args) > 2 {
lbryChannelName = args[2]
2017-09-15 18:13:13 -04:00
}
if stopOnError && maxTries != defaultMaxTries {
log.Errorln("--stop-on-error and --max-tries are mutually exclusive")
return
}
if maxTries < 1 {
log.Errorln("setting --max-tries less than 1 doesn't make sense")
return
}
2017-10-10 22:02:16 -04:00
s := sync.Sync{
YoutubeAPIKey: ytAPIKey,
YoutubeChannelID: channelID,
LbryChannelName: lbryChannelName,
StopOnError: stopOnError,
MaxTries: maxTries,
ConcurrentVideos: 1,
2017-09-19 14:14:52 -04:00
}
2017-10-10 22:02:16 -04:00
err := s.Go()
2017-09-15 18:13:13 -04:00
if err != nil {
2017-09-22 09:24:43 -04:00
panic(err)
2017-09-15 18:13:13 -04:00
}
2017-09-15 07:58:54 -04:00
}