From 6adb38d23fd7d3048bd99352e3de977d46671b50 Mon Sep 17 00:00:00 2001 From: Alex Grintsvayg Date: Fri, 22 Sep 2017 09:24:43 -0400 Subject: [PATCH] rearrange a bit --- .gitignore | 1 + jsonrpc/daemon.go | 9 +++++++++ jsonrpc/daemon_types.go | 3 +++ main.go | 16 ++++++++++++---- ytsync.go | 18 ++++++++---------- 5 files changed, 33 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index a09c56d..cf3b21d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /.idea +/bin diff --git a/jsonrpc/daemon.go b/jsonrpc/daemon.go index a8e27b7..67b571d 100644 --- a/jsonrpc/daemon.go +++ b/jsonrpc/daemon.go @@ -299,3 +299,12 @@ func (d *Client) Publish(name, filePath string, bid float64, options PublishOpti "change_address": options.ChangeAddress, }) } + +func (d *Client) BlobAnnounce(blobHash, sdHash, streamHash *string) (*BlobAnnounceResponse, error) { + response := new(BlobAnnounceResponse) + return response, d.call(response, "blob_announce", map[string]interface{}{ + "blob_hash": blobHash, + "stream_hash": streamHash, + "sd_hash": sdHash, + }) +} diff --git a/jsonrpc/daemon_types.go b/jsonrpc/daemon_types.go index f0af43f..5d90e5e 100644 --- a/jsonrpc/daemon_types.go +++ b/jsonrpc/daemon_types.go @@ -263,4 +263,7 @@ type ChannelListMineResponse []struct { type WalletListResponse []string type PublishResponse struct { + // TODO } + +type BlobAnnounceResponse bool diff --git a/main.go b/main.go index db0406d..085dd08 100644 --- a/main.go +++ b/main.go @@ -1,16 +1,24 @@ package main import ( + "os" + log "github.com/sirupsen/logrus" ) func main() { log.SetLevel(log.DebugLevel) - //franklin() + if len(os.Args) < 2 { + log.Errorln("Usage: " + os.Args[0] + " COMMAND [options]") + } - err := ytsync() - if err != nil { - panic(err) + switch os.Args[1] { + case "ytsync": + ytsync() + case "franklin": + franklin() + default: + log.Errorln("Unknown command: " + os.Args[1]) } } diff --git a/ytsync.go b/ytsync.go index 807828f..d641f95 100644 --- a/ytsync.go +++ b/ytsync.go @@ -50,9 +50,8 @@ var ( redisPool *redis.Pool ) -func ytsync() error { +func ytsync() { var err error - flag.StringVar(&ytAPIKey, "ytApiKey", "", "Youtube API key (required)") flag.StringVar(&channelID, "channelID", "", "ID of the youtube channel to sync (required)") flag.StringVar(&lbryChannelName, "lbryChannel", "", "Publish videos into this channel") @@ -60,7 +59,7 @@ func ytsync() error { if channelID == "" || ytAPIKey == "" { flag.Usage() - return nil + return } redisPool = &redis.Pool{ @@ -82,25 +81,25 @@ func ytsync() error { daemon = jsonrpc.NewClient("") videoDirectory, err = ioutil.TempDir("", "ytsync") if err != nil { - return err + panic(err) } if lbryChannelName != "" { err = ensureChannelOwnership() if err != nil { - return err + panic(err) } } addresses, err := daemon.WalletList() if err != nil { - return err + panic(err) } else if addresses == nil || len(*addresses) == 0 { - return fmt.Errorf("Could not find an address in wallet") + panic(fmt.Errorf("Could not find an address in wallet")) } claimAddress = (*addresses)[0] if claimAddress == "" { - return fmt.Errorf("Found blank claim address") + panic(fmt.Errorf("Found blank claim address")) } for i := 0; i < concurrentVideos; i++ { @@ -123,12 +122,11 @@ func ytsync() error { err = enqueueVideosFromChannel(channelID, &videoQueue) if err != nil { - return err + panic(err) } close(videoQueue) wg.Wait() - return nil } func ensureChannelOwnership() error {