From e5017892d8e9268fbdda572c9047c71c4bd20176 Mon Sep 17 00:00:00 2001 From: Niko Storni Date: Wed, 1 Aug 2018 08:56:04 -0400 Subject: [PATCH] add more startup parameters --- manager.go | 2 ++ setup.go | 4 ++-- sources/ucbVideo.go | 2 +- sources/youtubeVideo.go | 6 +++--- ytsync.go | 13 ++++++------- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/manager.go b/manager.go index a9bc274..d64958c 100644 --- a/manager.go +++ b/manager.go @@ -37,6 +37,8 @@ type SyncManager struct { ApiURL string ApiToken string BlobsDir string + VideosLimit int + MaxVideoSize int } const ( diff --git a/setup.go b/setup.go index 8ff85af..0046d8a 100644 --- a/setup.go +++ b/setup.go @@ -50,8 +50,8 @@ func (s *Sync) walletSetup() error { } log.Debugf("We already published %d videos", numPublished) - if float64(numOnSource)-float64(numPublished) > maximumVideosToPublish { - numOnSource = maximumVideosToPublish + if float64(numOnSource)-float64(numPublished) > float64(s.Manager.VideosLimit) { + numOnSource = uint64(s.Manager.VideosLimit) } minBalance := (float64(numOnSource)-float64(numPublished))*(publishAmount+0.1) + channelClaimAmount if numPublished > numOnSource { diff --git a/sources/ucbVideo.go b/sources/ucbVideo.go index ea220a5..514b676 100644 --- a/sources/ucbVideo.go +++ b/sources/ucbVideo.go @@ -188,7 +188,7 @@ func (v ucbVideo) publish(daemon *jsonrpc.Client, claimAddress string, amount fl return publishAndRetryExistingNames(daemon, v.title, v.getFilename(), amount, options) } -func (v ucbVideo) Sync(daemon *jsonrpc.Client, claimAddress string, amount float64, channelName string) (*SyncSummary, error) { +func (v ucbVideo) Sync(daemon *jsonrpc.Client, claimAddress string, amount float64, channelName string, maxVideoSize int) (*SyncSummary, error) { //download and thumbnail can be done in parallel err := v.download() if err != nil { diff --git a/sources/youtubeVideo.go b/sources/youtubeVideo.go index 9e28f14..0f24419 100644 --- a/sources/youtubeVideo.go +++ b/sources/youtubeVideo.go @@ -203,7 +203,7 @@ func (v YoutubeVideo) publish(daemon *jsonrpc.Client, claimAddress string, amoun return publishAndRetryExistingNames(daemon, v.title, v.getFilename(), amount, options) } -func (v YoutubeVideo) Sync(daemon *jsonrpc.Client, claimAddress string, amount float64, channelName string) (*SyncSummary, error) { +func (v YoutubeVideo) Sync(daemon *jsonrpc.Client, claimAddress string, amount float64, channelName string, maxVideoSize int) (*SyncSummary, error) { //download and thumbnail can be done in parallel err := v.download() if err != nil { @@ -215,10 +215,10 @@ func (v YoutubeVideo) Sync(daemon *jsonrpc.Client, claimAddress string, amount f if err != nil { return nil, err } - if fi.Size() > 2*1024*1024*1024 { + if fi.Size() > int64(maxVideoSize)*1024*1024 { //delete the video and ignore the error _ = v.delete() - return nil, errors.Err("video is bigger than 2GB, skipping for now") + return nil, errors.Err("the video is too big to sync, skipping for now") } err = v.triggerThumbnailSave() diff --git a/ytsync.go b/ytsync.go index 4ad2d14..af08d0e 100644 --- a/ytsync.go +++ b/ytsync.go @@ -30,9 +30,8 @@ import ( ) const ( - channelClaimAmount = 0.01 - publishAmount = 0.01 - maximumVideosToPublish = 1000 + channelClaimAmount = 0.01 + publishAmount = 0.01 ) type video interface { @@ -40,7 +39,7 @@ type video interface { IDAndNum() string PlaylistPosition() int PublishedAt() time.Time - Sync(*jsonrpc.Client, string, float64, string) (*sources.SyncSummary, error) + Sync(*jsonrpc.Client, string, float64, string, int) (*sources.SyncSummary, error) } // sorting videos @@ -315,7 +314,7 @@ func (s *Sync) startWorker(workerNum int) { "Error in daemon: Cannot publish empty file", "Error extracting sts from embedded url response", "Client.Timeout exceeded while awaiting headers)", - "video is bigger than 2GB, skipping for now", + "the video is too big to sync, skipping for now", } if util.SubstringInSlice(err.Error(), errorsNoRetry) { log.Println("This error should not be retried at all") @@ -504,11 +503,11 @@ func (s *Sync) processVideo(v video) (err error) { return nil } - if v.PlaylistPosition() > maximumVideosToPublish { + if v.PlaylistPosition() > s.Manager.VideosLimit { log.Println(v.ID() + " is old: skipping") return nil } - summary, err := v.Sync(s.daemon, s.claimAddress, publishAmount, s.LbryChannelName) + summary, err := v.Sync(s.daemon, s.claimAddress, publishAmount, s.LbryChannelName, s.Manager.MaxVideoSize) if err != nil { return err }