Add support for new SDK (0.37.*) and support for upgrading channels and claims to new metadata #28
2 changed files with 35 additions and 2 deletions
|
@ -82,6 +82,15 @@ func (s *Sync) walletSetup() error {
|
|||
}
|
||||
|
||||
minBalance := (float64(numOnSource)-float64(numPublished))*(publishAmount+0.1) + channelClaimAmount
|
||||
if s.Manager.syncStatus == StatusPendingUpgrade {
|
||||
videosToUpgrade := 0
|
||||
for _, v := range s.syncedVideos {
|
||||
if v.Published && v.MetadataVersion < 2 {
|
||||
videosToUpgrade++
|
||||
}
|
||||
}
|
||||
minBalance += float64(videosToUpgrade) * 0.001
|
||||
}
|
||||
if numPublished > numOnSource && balance < minimumRefillAmount {
|
||||
SendErrorToSlack("something is going on as we published more videos than those available on source: %d/%d", numPublished, numOnSource)
|
||||
minBalance = minimumRefillAmount
|
||||
|
@ -308,7 +317,7 @@ func (s *Sync) ensureChannelOwnership() error {
|
|||
return errors.Prefix("error creating YouTube service", err)
|
||||
}
|
||||
|
||||
response, err := service.Channels.List("snippet").Id(s.YoutubeChannelID).Do()
|
||||
response, err := service.Channels.List("snippet,branding").Id(s.YoutubeChannelID).Do()
|
||||
if err != nil {
|
||||
return errors.Prefix("error getting channel details", err)
|
||||
}
|
||||
|
@ -318,12 +327,23 @@ func (s *Sync) ensureChannelOwnership() error {
|
|||
}
|
||||
|
||||
channelInfo := response.Items[0].Snippet
|
||||
channelBranding := response.Items[0].BrandingSettings
|
||||
|
||||
thumbnail := thumbs.GetBestThumbnail(channelInfo.Thumbnails)
|
||||
thumbnailURL, err := thumbs.MirrorThumbnail(thumbnail.Url, s.YoutubeChannelID, s.Manager.GetS3AWSConfig())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var bannerURL *string = nil
|
||||
if channelBranding.Image != nil && channelBranding.Image.BannerImageUrl != "" {
|
||||
bURL, err := thumbs.MirrorThumbnail(channelBranding.Image.BannerImageUrl, "banner-"+s.YoutubeChannelID, s.Manager.GetS3AWSConfig())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
bannerURL = &bURL
|
||||
}
|
||||
|
||||
var languages []string = nil
|
||||
if channelInfo.DefaultLanguage != "" {
|
||||
languages = []string{channelInfo.DefaultLanguage}
|
||||
|
@ -346,6 +366,7 @@ func (s *Sync) ensureChannelOwnership() error {
|
|||
Locations: locations,
|
||||
ThumbnailURL: &thumbnailURL,
|
||||
},
|
||||
CoverURL: bannerURL,
|
||||
},
|
||||
})
|
||||
} else {
|
||||
|
|
|
@ -650,8 +650,20 @@ func (s *Sync) startWorker(workerNum int) {
|
|||
}
|
||||
SendErrorToSlack("Video failed after %d retries, skipping. Stack: %s", tryCount, logMsg)
|
||||
}
|
||||
existingClaim, ok := s.syncedVideos[v.ID()]
|
||||
existingClaimID := ""
|
||||
existingClaimName := ""
|
||||
existingClaimSize := v.Size()
|
||||
if ok {
|
||||
existingClaimID = existingClaim.ClaimID
|
||||
existingClaimName = existingClaim.ClaimName
|
||||
if existingClaim.Size > 0 {
|
||||
existingClaimSize = &existingClaim.Size
|
||||
}
|
||||
}
|
||||
|
||||
s.AppendSyncedVideo(v.ID(), false, err.Error(), "")
|
||||
err = s.Manager.apiConfig.MarkVideoStatus(s.YoutubeChannelID, v.ID(), VideoStatusFailed, "", "", err.Error(), v.Size())
|
||||
err = s.Manager.apiConfig.MarkVideoStatus(s.YoutubeChannelID, v.ID(), VideoStatusFailed, existingClaimID, existingClaimName, err.Error(), existingClaimSize)
|
||||
if err != nil {
|
||||
SendErrorToSlack("Failed to mark video on the database: %s", err.Error())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue