Add support for new SDK (0.37.*) and support for upgrading channels and claims to new metadata #28

Merged
nikooo777 merged 37 commits from metadata_upgrade into master 2019-06-13 20:14:14 +02:00
3 changed files with 15 additions and 10 deletions
Showing only changes of commit 74d5e2606d - Show all commits

View file

@ -317,7 +317,7 @@ func (s *Sync) ensureChannelOwnership() error {
return errors.Prefix("error creating YouTube service", err) return errors.Prefix("error creating YouTube service", err)
} }
response, err := service.Channels.List("snippet,branding").Id(s.YoutubeChannelID).Do() response, err := service.Channels.List("snippet,brandingSettings").Id(s.YoutubeChannelID).Do()
if err != nil { if err != nil {
return errors.Prefix("error getting channel details", err) return errors.Prefix("error getting channel details", err)
} }
@ -335,7 +335,7 @@ func (s *Sync) ensureChannelOwnership() error {
return err return err
} }
var bannerURL *string = nil var bannerURL *string
if channelBranding.Image != nil && channelBranding.Image.BannerImageUrl != "" { if channelBranding.Image != nil && channelBranding.Image.BannerImageUrl != "" {
bURL, err := thumbs.MirrorThumbnail(channelBranding.Image.BannerImageUrl, "banner-"+s.YoutubeChannelID, s.Manager.GetS3AWSConfig()) bURL, err := thumbs.MirrorThumbnail(channelBranding.Image.BannerImageUrl, "banner-"+s.YoutubeChannelID, s.Manager.GetS3AWSConfig())
if err != nil { if err != nil {
@ -379,6 +379,7 @@ func (s *Sync) ensureChannelOwnership() error {
Locations: locations, Locations: locations,
ThumbnailURL: &thumbnailURL, ThumbnailURL: &thumbnailURL,
}, },
CoverURL: bannerURL,
}) })
} }

View file

@ -6,6 +6,7 @@ import (
"math" "math"
"os" "os"
"os/exec" "os/exec"
"path/filepath"
"regexp" "regexp"
"strconv" "strconv"
"strings" "strings"
@ -156,14 +157,15 @@ func (v *YoutubeVideo) getAbbrevDescription() string {
func (v *YoutubeVideo) fallbackDownload() error { func (v *YoutubeVideo) fallbackDownload() error {
cmd := exec.Command("youtube-dl", cmd := exec.Command("youtube-dl",
"--id "+v.ID(), v.ID(),
"--no-progress", "--no-progress",
"-f \"bestvideo[ext=mp4,height<=1080,filesize<1000M]+bestaudio/best[ext=mp4,height<=1080,filesize<1000M]\"", "-fbestvideo[ext=mp4,height<=1080,filesize<2000M]+bestaudio/best[ext=mp4,height<=1080,filesize<2000M]",
"-o"+strings.TrimRight(v.getFullPath(), ".mp4")) "-o"+strings.TrimRight(v.getFullPath(), ".mp4"))
log.Printf("Running command and waiting for it to finish...") log.Printf("Running command and waiting for it to finish...")
err := cmd.Run() output, err := cmd.CombinedOutput()
log.Debugln(string(output))
if err != nil { if err != nil {
log.Printf("Command finished with error: %v", err) log.Printf("Command finished with error: %v", errors.Err(string(output)))
return errors.Err(err) return errors.Err(err)
} }
return nil return nil
@ -257,6 +259,7 @@ func (v *YoutubeVideo) videoDir() string {
} }
func (v *YoutubeVideo) getDownloadedPath() (string, error) { func (v *YoutubeVideo) getDownloadedPath() (string, error) {
files, err := ioutil.ReadDir(v.videoDir()) files, err := ioutil.ReadDir(v.videoDir())
log.Infoln(v.videoDir())
if err != nil { if err != nil {
err = errors.Prefix("list error", err) err = errors.Prefix("list error", err)
log.Errorln(err) log.Errorln(err)
@ -267,7 +270,7 @@ func (v *YoutubeVideo) getDownloadedPath() (string, error) {
if f.IsDir() { if f.IsDir() {
continue continue
} }
if strings.Contains(v.getFullPath(), f.Name()) { if strings.Contains(v.getFullPath(), strings.TrimSuffix(f.Name(), filepath.Ext(f.Name()))) {
return v.videoDir() + "/" + f.Name(), nil return v.videoDir() + "/" + f.Name(), nil
} }
} }
@ -353,7 +356,7 @@ func (v *YoutubeVideo) downloadAndPublish(daemon *jsonrpc.Client, params SyncPar
log.Errorf("standard downloader failed: %s. Trying fallback downloader\n", err.Error()) log.Errorf("standard downloader failed: %s. Trying fallback downloader\n", err.Error())
fallBackErr := v.fallbackDownload() fallBackErr := v.fallbackDownload()
if fallBackErr != nil { if fallBackErr != nil {
log.Errorf("fallback downloader failed: %s\n", err.Error()) log.Errorf("fallback downloader failed: %s\n", fallBackErr.Error())
return nil, errors.Prefix("download error", err) //return original error return nil, errors.Prefix("download error", err) //return original error
} }
} }

View file

@ -46,7 +46,7 @@ func (u *thumbnailUploader) downloadThumbnail() error {
} }
func (u *thumbnailUploader) uploadThumbnail() error { func (u *thumbnailUploader) uploadThumbnail() error {
key := aws.String("/thumbnails/" + u.name) key := &u.name
thumb, err := os.Open("/tmp/ytsync_thumbnails/" + u.name) thumb, err := os.Open("/tmp/ytsync_thumbnails/" + u.name)
if err != nil { if err != nil {
return errors.Err(err) return errors.Err(err)
@ -64,6 +64,7 @@ func (u *thumbnailUploader) uploadThumbnail() error {
Bucket: aws.String("thumbnails.lbry.com"), Bucket: aws.String("thumbnails.lbry.com"),
Key: key, Key: key,
Body: thumb, Body: thumb,
ACL: aws.String("public-read"),
}) })
u.mirroredUrl = ThumbnailEndpoint + u.name u.mirroredUrl = ThumbnailEndpoint + u.name
return errors.Err(err) return errors.Err(err)