require channel name, read channel ids from file
This commit is contained in:
parent
4942de8992
commit
af01d1626d
5 changed files with 48 additions and 23 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,4 +1,4 @@
|
||||||
/.idea
|
/.idea
|
||||||
/lbry
|
/lbry
|
||||||
/vendor
|
/vendor
|
||||||
tmp.sh
|
/tmp.sh
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
var ytSyncCmd = &cobra.Command{
|
var ytSyncCmd = &cobra.Command{
|
||||||
Use: "ytsync <youtube_api_key> <youtube_channel_id> [<lbry_channel_name>]",
|
Use: "ytsync <youtube_api_key> <lbry_channel_name> [<youtube_channel_id>]",
|
||||||
Args: cobra.RangeArgs(2, 3),
|
Args: cobra.RangeArgs(2, 3),
|
||||||
Short: "Publish youtube channel into LBRY network.",
|
Short: "Publish youtube channel into LBRY network.",
|
||||||
Run: ytsync,
|
Run: ytsync,
|
||||||
|
@ -21,7 +21,7 @@ func init() {
|
||||||
RootCmd.AddCommand(ytSyncCmd)
|
RootCmd.AddCommand(ytSyncCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultMaxTries = 1
|
const defaultMaxTries = 3
|
||||||
|
|
||||||
var (
|
var (
|
||||||
stopOnError bool
|
stopOnError bool
|
||||||
|
@ -31,14 +31,15 @@ var (
|
||||||
|
|
||||||
func ytsync(cmd *cobra.Command, args []string) {
|
func ytsync(cmd *cobra.Command, args []string) {
|
||||||
ytAPIKey := args[0]
|
ytAPIKey := args[0]
|
||||||
channelID := args[1]
|
lbryChannelName := args[1]
|
||||||
lbryChannelName := ""
|
|
||||||
if len(args) > 2 {
|
|
||||||
lbryChannelName = args[2]
|
|
||||||
if string(lbryChannelName[0]) != "@" {
|
if string(lbryChannelName[0]) != "@" {
|
||||||
log.Errorln("LBRY channel name must start with an @")
|
log.Errorln("LBRY channel name must start with an @")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
channelID := ""
|
||||||
|
if len(args) > 2 {
|
||||||
|
channelID = args[2]
|
||||||
}
|
}
|
||||||
|
|
||||||
if stopOnError && maxTries != defaultMaxTries {
|
if stopOnError && maxTries != defaultMaxTries {
|
||||||
|
@ -61,6 +62,7 @@ func ytsync(cmd *cobra.Command, args []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
err := s.FullCycle()
|
err := s.FullCycle()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if wrappedError, ok := err.(*errors.Error); ok {
|
if wrappedError, ok := err.(*errors.Error); ok {
|
||||||
log.Error(wrappedError.Error() + "\n" + string(wrappedError.Stack()))
|
log.Error(wrappedError.Error() + "\n" + string(wrappedError.Stack()))
|
||||||
|
|
|
@ -3,8 +3,7 @@
|
||||||
- make sure you don't have a `.lbryum/wallets/default_wallet`
|
- make sure you don't have a `.lbryum/wallets/default_wallet`
|
||||||
- delete existing wallet if there's nothing you need there, or better yet, move it somewhere else in case you need it later
|
- delete existing wallet if there's nothing you need there, or better yet, move it somewhere else in case you need it later
|
||||||
- make sure daemon is stopped and can be controlled with `systemctl`
|
- make sure daemon is stopped and can be controlled with `systemctl`
|
||||||
- run `lbry ytsync YOUTUBE_KEY YOUTUBE_CHANNEL_ID LBRY_CHANNEL_NAME --max-tries=5`
|
- run `lbry ytsync YOUTUBE_KEY LBRY_CHANNEL_NAME YOUTUBE_CHANNEL_ID`
|
||||||
- `max-tries` will retry errors that you will probably get (e.g. failed publishes)
|
|
||||||
- after sync is complete, daemon will be stopped and wallet will be moved to `~/wallets/`
|
- after sync is complete, daemon will be stopped and wallet will be moved to `~/wallets/`
|
||||||
- now mark content as synced in doc
|
- now mark content as synced in doc
|
||||||
|
|
||||||
|
|
|
@ -28,13 +28,10 @@ func (s *Sync) walletSetup() error {
|
||||||
}
|
}
|
||||||
log.Debugf("Source channel has %d videos", numOnSource)
|
log.Debugf("Source channel has %d videos", numOnSource)
|
||||||
|
|
||||||
numPublished := uint64(0)
|
numPublished, err := s.daemon.NumClaimsInChannel(s.LbryChannelName)
|
||||||
if s.LbryChannelName != "" {
|
|
||||||
numPublished, err = s.daemon.NumClaimsInChannel(s.LbryChannelName)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
|
||||||
log.Debugf("We already published %d videos", numPublished)
|
log.Debugf("We already published %d videos", numPublished)
|
||||||
|
|
||||||
minBalance := (float64(numOnSource)-float64(numPublished))*publishAmount + channelClaimAmount
|
minBalance := (float64(numOnSource)-float64(numPublished))*publishAmount + channelClaimAmount
|
||||||
|
@ -88,12 +85,10 @@ func (s *Sync) walletSetup() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.LbryChannelName != "" {
|
|
||||||
err = s.ensureChannelOwnership()
|
err = s.ensureChannelOwnership()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
balanceResp, err = s.daemon.WalletBalance()
|
balanceResp, err = s.daemon.WalletBalance()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package ytsync
|
package ytsync
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
@ -69,6 +70,14 @@ func (s *Sync) FullCycle() error {
|
||||||
return errors.New("no $HOME env var found")
|
return errors.New("no $HOME env var found")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if s.YoutubeChannelID == "" {
|
||||||
|
channelID, err := getChannelIDFromFile(s.LbryChannelName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
s.YoutubeChannelID = channelID
|
||||||
|
}
|
||||||
|
|
||||||
defaultWalletDir := os.Getenv("HOME") + "/.lbryum/wallets/default_wallet"
|
defaultWalletDir := os.Getenv("HOME") + "/.lbryum/wallets/default_wallet"
|
||||||
walletBackupDir := os.Getenv("HOME") + "/wallets/" + strings.Replace(s.LbryChannelName, "@", "", 1)
|
walletBackupDir := os.Getenv("HOME") + "/wallets/" + strings.Replace(s.LbryChannelName, "@", "", 1)
|
||||||
|
|
||||||
|
@ -341,3 +350,23 @@ func stopDaemonViaSystemd() error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getChannelIDFromFile(channelName string) (string, error) {
|
||||||
|
channelsJSON, err := ioutil.ReadFile("./channels")
|
||||||
|
if err != nil {
|
||||||
|
return "", errors.Wrap(err, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
var channels map[string]string
|
||||||
|
err = json.Unmarshal(channelsJSON, &channels)
|
||||||
|
if err != nil {
|
||||||
|
return "", errors.Wrap(err, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
channelID, ok := channels[channelName]
|
||||||
|
if !ok {
|
||||||
|
return "", errors.New("channel not in list")
|
||||||
|
}
|
||||||
|
|
||||||
|
return channelID, nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue