Add check for already published videos using new video-state api.
This commit is contained in:
parent
357aebbcce
commit
d99e200178
3 changed files with 51 additions and 4 deletions
|
@ -995,7 +995,7 @@ func (s *Sync) enqueueYoutubeVideos() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
videos, err := ytapi.GetVideosToSync(s.YoutubeChannelID, s.syncedVideos, s.Manager.SyncFlags.QuickSync, s.Manager.videosLimit, ytapi.VideoParams{
|
videos, err := ytapi.GetVideosToSync(s.APIConfig, s.YoutubeChannelID, s.syncedVideos, s.Manager.SyncFlags.QuickSync, s.Manager.videosLimit, ytapi.VideoParams{
|
||||||
VideoDir: s.videoDirectory,
|
VideoDir: s.videoDirectory,
|
||||||
S3Config: s.Manager.GetS3AWSConfig(),
|
S3Config: s.Manager.GetS3AWSConfig(),
|
||||||
Stopper: s.grp,
|
Stopper: s.grp,
|
||||||
|
|
40
sdk/api.go
40
sdk/api.go
|
@ -368,3 +368,43 @@ func (a *APIConfig) MarkVideoStatus(status VideoStatus) error {
|
||||||
}
|
}
|
||||||
return errors.Err("invalid API response. Status code: %d", res.StatusCode)
|
return errors.Err("invalid API response. Status code: %d", res.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *APIConfig) VideoState(videoID string) (string, error) {
|
||||||
|
endpoint := a.ApiURL + "/yt/video_state"
|
||||||
|
vals := url.Values{
|
||||||
|
"video_id": {videoID},
|
||||||
|
"auth_token": {a.ApiToken},
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := http.PostForm(endpoint, vals)
|
||||||
|
if err != nil {
|
||||||
|
return "", errors.Err(err)
|
||||||
|
}
|
||||||
|
defer res.Body.Close()
|
||||||
|
body, _ := ioutil.ReadAll(res.Body)
|
||||||
|
if res.StatusCode == http.StatusNotFound {
|
||||||
|
return "not_found", nil
|
||||||
|
}
|
||||||
|
if res.StatusCode != http.StatusOK {
|
||||||
|
util.SendErrorToSlack("Error %d while trying to call %s. Waiting to retry", res.StatusCode, endpoint)
|
||||||
|
log.Debugln(string(body))
|
||||||
|
time.Sleep(30 * time.Second)
|
||||||
|
return a.VideoState(videoID)
|
||||||
|
}
|
||||||
|
var response struct {
|
||||||
|
Success bool `json:"success"`
|
||||||
|
Error null.String `json:"error"`
|
||||||
|
Data null.String `json:"data"`
|
||||||
|
}
|
||||||
|
err = json.Unmarshal(body, &response)
|
||||||
|
if err != nil {
|
||||||
|
return "", errors.Err(err)
|
||||||
|
}
|
||||||
|
if !response.Error.IsNull() {
|
||||||
|
return "", errors.Err(response.Error.String)
|
||||||
|
}
|
||||||
|
if !response.Data.IsNull() {
|
||||||
|
return response.Data.String, nil
|
||||||
|
}
|
||||||
|
return "", errors.Err("invalid API response. Status code: %d", res.StatusCode)
|
||||||
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ type VideoParams struct {
|
||||||
|
|
||||||
var mostRecentlyFailedChannel string // TODO: fix this hack!
|
var mostRecentlyFailedChannel string // TODO: fix this hack!
|
||||||
|
|
||||||
func GetVideosToSync(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) ([]Video, error) {
|
||||||
|
|
||||||
var videos []Video
|
var videos []Video
|
||||||
if quickSync {
|
if quickSync {
|
||||||
|
@ -76,7 +76,7 @@ func GetVideosToSync(channelID string, syncedVideos map[string]sdk.SyncedVideo,
|
||||||
mostRecentlyFailedChannel = channelID
|
mostRecentlyFailedChannel = channelID
|
||||||
}
|
}
|
||||||
|
|
||||||
vids, err := getVideos(videoIDs, videoParams.Stopper.Ch(), videoParams.IPPool)
|
vids, err := getVideos(config, videoIDs, videoParams.Stopper.Ch(), videoParams.IPPool)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -161,7 +161,7 @@ func ChannelInfo(apiKey, channelID string) (*ytlib.ChannelSnippet, *ytlib.Channe
|
||||||
return response.Items[0].Snippet, response.Items[0].BrandingSettings, nil
|
return response.Items[0].Snippet, response.Items[0].BrandingSettings, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getVideos(videoIDs []string, stopChan stop.Chan, ipPool *ip_manager.IPPool) ([]*ytdl.YtdlVideo, error) {
|
func getVideos(config *sdk.APIConfig, videoIDs []string, stopChan stop.Chan, ipPool *ip_manager.IPPool) ([]*ytdl.YtdlVideo, error) {
|
||||||
var videos []*ytdl.YtdlVideo
|
var videos []*ytdl.YtdlVideo
|
||||||
for _, videoID := range videoIDs {
|
for _, videoID := range videoIDs {
|
||||||
select {
|
select {
|
||||||
|
@ -175,6 +175,13 @@ func getVideos(videoIDs []string, stopChan stop.Chan, ipPool *ip_manager.IPPool)
|
||||||
// return nil, err
|
// return nil, err
|
||||||
//}
|
//}
|
||||||
//video, err := downloader.GetVideoInformation(videoID, &net.TCPAddr{IP: net.ParseIP(ip)})
|
//video, err := downloader.GetVideoInformation(videoID, &net.TCPAddr{IP: net.ParseIP(ip)})
|
||||||
|
state, err := config.VideoState(videoID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Err(err)
|
||||||
|
}
|
||||||
|
if state == "published" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
video, err := downloader.GetVideoInformation(videoID, stopChan, nil)
|
video, err := downloader.GetVideoInformation(videoID, stopChan, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
//ipPool.ReleaseIP(ip)
|
//ipPool.ReleaseIP(ip)
|
||||||
|
|
Loading…
Add table
Reference in a new issue