From 5d230a6b54f0d011bd2b7040657f92bc64061932 Mon Sep 17 00:00:00 2001 From: Niko Storni Date: Thu, 6 Aug 2020 20:32:49 +0200 Subject: [PATCH] potentially fix looping add limits by db --- manager/manager.go | 6 ++++++ manager/ytsync.go | 3 ++- sdk/api.go | 3 +++ ytapi/ytapi.go | 10 +++++++++- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/manager/manager.go b/manager/manager.go index ac24ad7..9af86cb 100644 --- a/manager/manager.go +++ b/manager/manager.go @@ -127,6 +127,8 @@ func (s *SyncManager) Start() error { } lbryChannelName := channels[0].DesiredChannelName syncs = make([]Sync, 1) + s.maxVideoLength = time.Duration(channels[0].LengthLimit) * time.Minute + s.maxVideoSize = channels[0].SizeLimit syncs[0] = Sync{ APIConfig: s.apiConfig, YoutubeChannelID: s.syncProperties.YoutubeChannelID, @@ -147,6 +149,7 @@ func (s *SyncManager) Start() error { clientPublishAddress: channels[0].PublishAddress, publicKey: channels[0].PublicKey, transferState: channels[0].TransferState, + LastUploadedVideo: channels[0].LastUploadedVideo, } shouldInterruptLoop = true } else { @@ -174,6 +177,8 @@ func (s *SyncManager) Start() error { if c.TotalSubscribers < 1000 { maxVideoLength = 1 * time.Hour } + maxVideoLength = time.Duration(c.LengthLimit) * time.Minute + s.maxVideoSize = c.SizeLimit syncs = append(syncs, Sync{ APIConfig: s.apiConfig, YoutubeChannelID: c.ChannelId, @@ -194,6 +199,7 @@ func (s *SyncManager) Start() error { clientPublishAddress: c.PublishAddress, publicKey: c.PublicKey, transferState: c.TransferState, + LastUploadedVideo: c.LastUploadedVideo, }) if q != StatusFailed { continue queues diff --git a/manager/ytsync.go b/manager/ytsync.go index 0b45e02..b1611d3 100644 --- a/manager/ytsync.go +++ b/manager/ytsync.go @@ -68,6 +68,7 @@ type Sync struct { publicKey string defaultAccountID string MaxVideoLength time.Duration + LastUploadedVideo string } func (s *Sync) AppendSyncedVideo(videoID string, published bool, failureReason string, claimName string, claimID string, metadataVersion int8, size int64) { @@ -897,7 +898,7 @@ func (s *Sync) enqueueYoutubeVideos() error { S3Config: s.Manager.GetS3AWSConfig(), Stopper: s.grp, IPPool: ipPool, - }) + }, s.LastUploadedVideo) if err != nil { return err } diff --git a/sdk/api.go b/sdk/api.go index 233f463..c542cc8 100644 --- a/sdk/api.go +++ b/sdk/api.go @@ -63,6 +63,9 @@ type YoutubeChannel struct { TransferState int `json:"transfer_state"` PublishAddress string `json:"publish_address"` PublicKey string `json:"public_key"` + LengthLimit int `json:"length_limit"` + SizeLimit int `json:"size_limit"` + LastUploadedVideo string `json:"last_uploaded_video"` } func (a *APIConfig) FetchChannels(status string, cp *SyncProperties) ([]YoutubeChannel, error) { diff --git a/ytapi/ytapi.go b/ytapi/ytapi.go index ee43f88..2d19e58 100644 --- a/ytapi/ytapi.go +++ b/ytapi/ytapi.go @@ -53,7 +53,7 @@ type VideoParams struct { var mostRecentlyFailedChannel string // TODO: fix this hack! -func GetVideosToSync(config *sdk.APIConfig, channelID string, syncedVideos map[string]sdk.SyncedVideo, quickSync bool, maxVideos int, videoParams VideoParams) ([]Video, error) { +func GetVideosToSync(config *sdk.APIConfig, channelID string, syncedVideos map[string]sdk.SyncedVideo, quickSync bool, maxVideos int, videoParams VideoParams, lastUploadedVideo string) ([]Video, error) { var videos []Video if quickSync && maxVideos > 50 { @@ -70,6 +70,14 @@ func GetVideosToSync(config *sdk.APIConfig, channelID string, syncedVideos map[s for i, videoID := range videoIDs { playlistMap[videoID] = int64(i) } + //this will ensure that we at least try to sync the video that was marked as last uploaded video in the database. + if lastUploadedVideo != "" { + _, ok := playlistMap[lastUploadedVideo] + if !ok { + playlistMap[lastUploadedVideo] = 0 + videoIDs = append(videoIDs, lastUploadedVideo) + } + } if len(videoIDs) < 1 { if channelID == mostRecentlyFailedChannel {