Add support for new SDK (0.37.*) and support for upgrading channels and claims to new metadata #28
2 changed files with 21 additions and 47 deletions
|
@ -614,6 +614,7 @@ func (s *Sync) startWorker(workerNum int) {
|
||||||
"no compatible format available for this video",
|
"no compatible format available for this video",
|
||||||
"Watch this video on YouTube.",
|
"Watch this video on YouTube.",
|
||||||
"have blocked it on copyright grounds",
|
"have blocked it on copyright grounds",
|
||||||
|
"the video must be republished as we can't get the right size",
|
||||||
}
|
}
|
||||||
if util.SubstringInSlice(err.Error(), errorsNoRetry) {
|
if util.SubstringInSlice(err.Error(), errorsNoRetry) {
|
||||||
log.Println("This error should not be retried at all")
|
log.Println("This error should not be retried at all")
|
||||||
|
|
|
@ -1,12 +1,8 @@
|
||||||
package sources
|
package sources
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"math"
|
"math"
|
||||||
"net/http"
|
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -42,6 +38,7 @@ type YoutubeVideo struct {
|
||||||
youtubeInfo *youtube.Video
|
youtubeInfo *youtube.Video
|
||||||
tags []string
|
tags []string
|
||||||
awsConfig aws.Config
|
awsConfig aws.Config
|
||||||
|
thumbnailURL string
|
||||||
}
|
}
|
||||||
|
|
||||||
const reflectorURL = "http://blobs.lbry.io/"
|
const reflectorURL = "http://blobs.lbry.io/"
|
||||||
|
@ -246,45 +243,10 @@ func (v *YoutubeVideo) delete() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *YoutubeVideo) triggerThumbnailSave() error {
|
func (v *YoutubeVideo) triggerThumbnailSave() (err error) {
|
||||||
client := &http.Client{Timeout: 30 * time.Second}
|
thumbnail := thumbs.GetBestThumbnail(v.youtubeInfo.Snippet.Thumbnails)
|
||||||
|
v.thumbnailURL, err = thumbs.MirrorThumbnail(thumbnail.Url, v.ID(), v.awsConfig)
|
||||||
params, err := json.Marshal(map[string]string{"videoid": v.id})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
|
||||||
|
|
||||||
request, err := http.NewRequest(http.MethodPut, "https://jgp4g1qoud.execute-api.us-east-1.amazonaws.com/prod/thumbnail", bytes.NewBuffer(params))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
response, err := client.Do(request)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer response.Body.Close()
|
|
||||||
|
|
||||||
contents, err := ioutil.ReadAll(response.Body)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
var decoded struct {
|
|
||||||
Error int `json:"error"`
|
|
||||||
Url string `json:"url,omitempty"`
|
|
||||||
Message string `json:"message,omitempty"`
|
|
||||||
}
|
|
||||||
err = json.Unmarshal(contents, &decoded)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if decoded.Error != 0 {
|
|
||||||
return errors.Err("error creating thumbnail: " + decoded.Message)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *YoutubeVideo) publish(daemon *jsonrpc.Client, claimAddress string, amount float64, channelID string, namer *namer.Namer) (*SyncSummary, error) {
|
func (v *YoutubeVideo) publish(daemon *jsonrpc.Client, claimAddress string, amount float64, channelID string, namer *namer.Namer) (*SyncSummary, error) {
|
||||||
|
@ -309,7 +271,7 @@ func (v *YoutubeVideo) publish(daemon *jsonrpc.Client, claimAddress string, amou
|
||||||
Description: v.getAbbrevDescription() + additionalDescription,
|
Description: v.getAbbrevDescription() + additionalDescription,
|
||||||
ClaimAddress: &claimAddress,
|
ClaimAddress: &claimAddress,
|
||||||
Languages: languages,
|
Languages: languages,
|
||||||
ThumbnailURL: util.PtrToString(thumbs.ThumbnailEndpoint + v.id),
|
ThumbnailURL: &v.thumbnailURL,
|
||||||
Tags: v.youtubeInfo.Snippet.Tags,
|
Tags: v.youtubeInfo.Snippet.Tags,
|
||||||
},
|
},
|
||||||
Author: util.PtrToString(v.channelTitle),
|
Author: util.PtrToString(v.channelTitle),
|
||||||
|
@ -409,11 +371,15 @@ func (v *YoutubeVideo) reprocess(daemon *jsonrpc.Client, params SyncParams, exis
|
||||||
videoSize = uint64(existingVideoData.Size)
|
videoSize = uint64(existingVideoData.Size)
|
||||||
} else {
|
} else {
|
||||||
log.Infof("%s: the video must be republished as we can't get the right size", v.ID())
|
log.Infof("%s: the video must be republished as we can't get the right size", v.ID())
|
||||||
return v.downloadAndPublish(daemon, params)
|
//return v.downloadAndPublish(daemon, params) //TODO: actually republish the video. NB: the current claim should be abandoned first
|
||||||
|
return nil, errors.Err("the video must be republished as we can't get the right size")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
videoDuration, err := duration.FromString(v.youtubeInfo.ContentDetails.Duration)
|
videoDuration, err := duration.FromString(v.youtubeInfo.ContentDetails.Duration)
|
||||||
_, err = daemon.StreamUpdate(existingVideoData.ClaimID, jsonrpc.StreamUpdateOptions{
|
if err != nil {
|
||||||
|
return nil, errors.Err(err)
|
||||||
|
}
|
||||||
|
pr, err := daemon.StreamUpdate(existingVideoData.ClaimID, jsonrpc.StreamUpdateOptions{
|
||||||
StreamCreateOptions: &jsonrpc.StreamCreateOptions{
|
StreamCreateOptions: &jsonrpc.StreamCreateOptions{
|
||||||
ClaimCreateOptions: jsonrpc.ClaimCreateOptions{
|
ClaimCreateOptions: jsonrpc.ClaimCreateOptions{
|
||||||
Title: v.title,
|
Title: v.title,
|
||||||
|
@ -431,5 +397,12 @@ func (v *YoutubeVideo) reprocess(daemon *jsonrpc.Client, params SyncParams, exis
|
||||||
},
|
},
|
||||||
FileSize: util.PtrToString(fmt.Sprintf("%d", videoSize)),
|
FileSize: util.PtrToString(fmt.Sprintf("%d", videoSize)),
|
||||||
})
|
})
|
||||||
return &SyncSummary{}, nil
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &SyncSummary{
|
||||||
|
ClaimID: pr.ClaimID,
|
||||||
|
ClaimName: pr.Output.Name,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue