reprocess videos that are no longer on youtube (part 1)
This commit is contained in:
parent
e73085b6bc
commit
6767fdcc40
2 changed files with 55 additions and 5 deletions
|
@ -702,7 +702,7 @@ func (s *Sync) enqueueYoutubeVideos() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
var videos []video
|
var videos []video
|
||||||
|
playlistMap := make(map[string]*youtube.PlaylistItemSnippet, 50)
|
||||||
nextPageToken := ""
|
nextPageToken := ""
|
||||||
for {
|
for {
|
||||||
req := service.PlaylistItems.List("snippet").
|
req := service.PlaylistItems.List("snippet").
|
||||||
|
@ -724,7 +724,7 @@ func (s *Sync) enqueueYoutubeVideos() error {
|
||||||
}
|
}
|
||||||
return errors.Err("playlist items not found")
|
return errors.Err("playlist items not found")
|
||||||
}
|
}
|
||||||
playlistMap := make(map[string]*youtube.PlaylistItemSnippet, 50)
|
//playlistMap := make(map[string]*youtube.PlaylistItemSnippet, 50)
|
||||||
videoIDs := make([]string, 50)
|
videoIDs := make([]string, 50)
|
||||||
for i, item := range playlistResponse.Items {
|
for i, item := range playlistResponse.Items {
|
||||||
// normally we'd send the video into the channel here, but youtube api doesn't have sorting
|
// normally we'd send the video into the channel here, but youtube api doesn't have sorting
|
||||||
|
@ -749,7 +749,17 @@ func (s *Sync) enqueueYoutubeVideos() error {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
notOnYoutube := make([]video, 0, len(s.syncedVideos))
|
||||||
|
for k, v := range s.syncedVideos {
|
||||||
|
if !v.Published {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
_, ok := playlistMap[k]
|
||||||
|
if !ok {
|
||||||
|
notOnYoutube = append(notOnYoutube, sources.NewMockedVideo(s.videoDirectory, k, s.Manager.GetS3AWSConfig()))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
sort.Sort(byPublishedAt(videos))
|
sort.Sort(byPublishedAt(videos))
|
||||||
//or sort.Sort(sort.Reverse(byPlaylistPosition(videos)))
|
//or sort.Sort(sort.Reverse(byPlaylistPosition(videos)))
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,6 @@ import (
|
||||||
|
|
||||||
type YoutubeVideo struct {
|
type YoutubeVideo struct {
|
||||||
id string
|
id string
|
||||||
channelTitle string
|
|
||||||
title string
|
title string
|
||||||
description string
|
description string
|
||||||
playlistPosition int64
|
playlistPosition int64
|
||||||
|
@ -44,6 +43,7 @@ type YoutubeVideo struct {
|
||||||
awsConfig aws.Config
|
awsConfig aws.Config
|
||||||
thumbnailURL string
|
thumbnailURL string
|
||||||
lbryChannelID string
|
lbryChannelID string
|
||||||
|
mocked bool
|
||||||
}
|
}
|
||||||
|
|
||||||
const reflectorURL = "http://blobs.lbry.io/"
|
const reflectorURL = "http://blobs.lbry.io/"
|
||||||
|
@ -89,12 +89,21 @@ func NewYoutubeVideo(directory string, videoData *youtube.Video, playlistPositio
|
||||||
id: videoData.Id,
|
id: videoData.Id,
|
||||||
title: videoData.Snippet.Title,
|
title: videoData.Snippet.Title,
|
||||||
description: videoData.Snippet.Description,
|
description: videoData.Snippet.Description,
|
||||||
channelTitle: videoData.Snippet.ChannelTitle,
|
|
||||||
playlistPosition: playlistPosition,
|
playlistPosition: playlistPosition,
|
||||||
publishedAt: publishedAt,
|
publishedAt: publishedAt,
|
||||||
dir: directory,
|
dir: directory,
|
||||||
youtubeInfo: videoData,
|
youtubeInfo: videoData,
|
||||||
awsConfig: awsConfig,
|
awsConfig: awsConfig,
|
||||||
|
mocked: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func NewMockedVideo(directory string, videoID string, awsConfig aws.Config) *YoutubeVideo {
|
||||||
|
return &YoutubeVideo{
|
||||||
|
id: videoID,
|
||||||
|
playlistPosition: 0,
|
||||||
|
dir: directory,
|
||||||
|
awsConfig: awsConfig,
|
||||||
|
mocked: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,6 +120,9 @@ func (v *YoutubeVideo) IDAndNum() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *YoutubeVideo) PublishedAt() time.Time {
|
func (v *YoutubeVideo) PublishedAt() time.Time {
|
||||||
|
if v.mocked {
|
||||||
|
return time.Unix(0, 0)
|
||||||
|
}
|
||||||
return v.publishedAt
|
return v.publishedAt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,7 +326,6 @@ func (v *YoutubeVideo) publish(daemon *jsonrpc.Client, claimAddress string, amou
|
||||||
Tags: tags,
|
Tags: tags,
|
||||||
Locations: locations,
|
Locations: locations,
|
||||||
},
|
},
|
||||||
Author: util.PtrToString(v.channelTitle),
|
|
||||||
License: util.PtrToString("Copyrighted (contact author)"),
|
License: util.PtrToString("Copyrighted (contact author)"),
|
||||||
ReleaseTime: util.PtrToInt64(v.publishedAt.Unix()),
|
ReleaseTime: util.PtrToInt64(v.publishedAt.Unix()),
|
||||||
ChannelID: &v.lbryChannelID,
|
ChannelID: &v.lbryChannelID,
|
||||||
|
@ -376,6 +387,9 @@ func (v *YoutubeVideo) downloadAndPublish(daemon *jsonrpc.Client, params SyncPar
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *YoutubeVideo) getMetadata() (languages []string, locations []jsonrpc.Location, tags []string) {
|
func (v *YoutubeVideo) getMetadata() (languages []string, locations []jsonrpc.Location, tags []string) {
|
||||||
|
if v.mocked {
|
||||||
|
return nil, nil, tagsManager.SanitizeTags([]string{})
|
||||||
|
}
|
||||||
languages = nil
|
languages = nil
|
||||||
if v.youtubeInfo.Snippet.DefaultLanguage != "" {
|
if v.youtubeInfo.Snippet.DefaultLanguage != "" {
|
||||||
languages = []string{v.youtubeInfo.Snippet.DefaultLanguage}
|
languages = []string{v.youtubeInfo.Snippet.DefaultLanguage}
|
||||||
|
@ -409,6 +423,9 @@ func (v *YoutubeVideo) reprocess(daemon *jsonrpc.Client, params SyncParams, exis
|
||||||
|
|
||||||
thumbnailURL := ""
|
thumbnailURL := ""
|
||||||
if currentClaim.Value.GetThumbnail() == nil {
|
if currentClaim.Value.GetThumbnail() == nil {
|
||||||
|
if v.mocked {
|
||||||
|
return nil, errors.Err("could not find thumbnail for mocked video")
|
||||||
|
}
|
||||||
thumbnail := thumbs.GetBestThumbnail(v.youtubeInfo.Snippet.Thumbnails)
|
thumbnail := thumbs.GetBestThumbnail(v.youtubeInfo.Snippet.Thumbnails)
|
||||||
thumbnailURL, err = thumbs.MirrorThumbnail(thumbnail.Url, v.ID(), v.awsConfig)
|
thumbnailURL, err = thumbs.MirrorThumbnail(thumbnail.Url, v.ID(), v.awsConfig)
|
||||||
} else {
|
} else {
|
||||||
|
@ -431,6 +448,29 @@ func (v *YoutubeVideo) reprocess(daemon *jsonrpc.Client, params SyncParams, exis
|
||||||
return nil, errors.Err(err)
|
return nil, errors.Err(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var description *string
|
||||||
|
if v.mocked {
|
||||||
|
pr, err := daemon.StreamUpdate(existingVideoData.ClaimID, jsonrpc.StreamUpdateOptions{
|
||||||
|
StreamCreateOptions: &jsonrpc.StreamCreateOptions{
|
||||||
|
ClaimCreateOptions: jsonrpc.ClaimCreateOptions{
|
||||||
|
Tags: tags,
|
||||||
|
ThumbnailURL: &thumbnailURL,
|
||||||
|
},
|
||||||
|
Author: util.PtrToString(""),
|
||||||
|
License: util.PtrToString("Copyrighted (contact author)"),
|
||||||
|
ChannelID: &v.lbryChannelID,
|
||||||
|
},
|
||||||
|
FileSize: &videoSize,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &SyncSummary{
|
||||||
|
ClaimID: pr.Outputs[0].ClaimID,
|
||||||
|
ClaimName: pr.Outputs[0].Name,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
pr, err := daemon.StreamUpdate(existingVideoData.ClaimID, jsonrpc.StreamUpdateOptions{
|
pr, err := daemon.StreamUpdate(existingVideoData.ClaimID, jsonrpc.StreamUpdateOptions{
|
||||||
ClearLanguages: util.PtrToBool(true),
|
ClearLanguages: util.PtrToBool(true),
|
||||||
ClearLocations: util.PtrToBool(true),
|
ClearLocations: util.PtrToBool(true),
|
||||||
|
|
Loading…
Reference in a new issue