rearrange a bit

This commit is contained in:
Alex Grintsvayg 2017-09-22 09:24:43 -04:00
parent 09cafcba40
commit 6adb38d23f
No known key found for this signature in database
GPG key ID: AEB3F089F86A22B5
5 changed files with 33 additions and 14 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
/.idea /.idea
/bin

View file

@ -299,3 +299,12 @@ func (d *Client) Publish(name, filePath string, bid float64, options PublishOpti
"change_address": options.ChangeAddress, "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,
})
}

View file

@ -263,4 +263,7 @@ type ChannelListMineResponse []struct {
type WalletListResponse []string type WalletListResponse []string
type PublishResponse struct { type PublishResponse struct {
// TODO
} }
type BlobAnnounceResponse bool

16
main.go
View file

@ -1,16 +1,24 @@
package main package main
import ( import (
"os"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
func main() { func main() {
log.SetLevel(log.DebugLevel) log.SetLevel(log.DebugLevel)
//franklin() if len(os.Args) < 2 {
log.Errorln("Usage: " + os.Args[0] + " COMMAND [options]")
}
err := ytsync() switch os.Args[1] {
if err != nil { case "ytsync":
panic(err) ytsync()
case "franklin":
franklin()
default:
log.Errorln("Unknown command: " + os.Args[1])
} }
} }

View file

@ -50,9 +50,8 @@ var (
redisPool *redis.Pool redisPool *redis.Pool
) )
func ytsync() error { func ytsync() {
var err error var err error
flag.StringVar(&ytAPIKey, "ytApiKey", "", "Youtube API key (required)") flag.StringVar(&ytAPIKey, "ytApiKey", "", "Youtube API key (required)")
flag.StringVar(&channelID, "channelID", "", "ID of the youtube channel to sync (required)") flag.StringVar(&channelID, "channelID", "", "ID of the youtube channel to sync (required)")
flag.StringVar(&lbryChannelName, "lbryChannel", "", "Publish videos into this channel") flag.StringVar(&lbryChannelName, "lbryChannel", "", "Publish videos into this channel")
@ -60,7 +59,7 @@ func ytsync() error {
if channelID == "" || ytAPIKey == "" { if channelID == "" || ytAPIKey == "" {
flag.Usage() flag.Usage()
return nil return
} }
redisPool = &redis.Pool{ redisPool = &redis.Pool{
@ -82,25 +81,25 @@ func ytsync() error {
daemon = jsonrpc.NewClient("") daemon = jsonrpc.NewClient("")
videoDirectory, err = ioutil.TempDir("", "ytsync") videoDirectory, err = ioutil.TempDir("", "ytsync")
if err != nil { if err != nil {
return err panic(err)
} }
if lbryChannelName != "" { if lbryChannelName != "" {
err = ensureChannelOwnership() err = ensureChannelOwnership()
if err != nil { if err != nil {
return err panic(err)
} }
} }
addresses, err := daemon.WalletList() addresses, err := daemon.WalletList()
if err != nil { if err != nil {
return err panic(err)
} else if addresses == nil || len(*addresses) == 0 { } 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] claimAddress = (*addresses)[0]
if claimAddress == "" { if claimAddress == "" {
return fmt.Errorf("Found blank claim address") panic(fmt.Errorf("Found blank claim address"))
} }
for i := 0; i < concurrentVideos; i++ { for i := 0; i < concurrentVideos; i++ {
@ -123,12 +122,11 @@ func ytsync() error {
err = enqueueVideosFromChannel(channelID, &videoQueue) err = enqueueVideosFromChannel(channelID, &videoQueue)
if err != nil { if err != nil {
return err panic(err)
} }
close(videoQueue) close(videoQueue)
wg.Wait() wg.Wait()
return nil
} }
func ensureChannelOwnership() error { func ensureChannelOwnership() error {