From 0c2eb4e8082ff4257fbf648fe88986df507f8d1e Mon Sep 17 00:00:00 2001 From: fqx Date: Mon, 1 Jul 2024 16:12:11 +0800 Subject: [PATCH] ignore video if video.ContentDetails.Duration is empty, usually upcoming live broadcast. --- pkg/builder/youtube.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/pkg/builder/youtube.go b/pkg/builder/youtube.go index b2841684..6b7a9dec 100644 --- a/pkg/builder/youtube.go +++ b/pkg/builder/youtube.go @@ -317,19 +317,16 @@ func (yt *YouTubeBuilder) queryVideoDescriptions(ctx context.Context, playlist m // Sometimes YouTube retrun empty content defailt, use arbitrary one var seconds int64 = 1 - if video.ContentDetails != nil { + if video.ContentDetails.Duration != "" { // Parse duration d, err := duration.FromString(video.ContentDetails.Duration) if err != nil { - // If parsing fails, log the error and use the default value - log.Printf("Warning: Failed to parse duration %s: %v. Using default value.", video.ContentDetails.Duration, err) - // seconds is already set to 1, so we don't need to set it again - } else { - // If parsing succeeds, set seconds to the parsed duration - seconds = int64(d.ToDuration().Seconds()) + return errors.Wrapf(err, "failed to parse duration %s", video.ContentDetails.Duration) } - // seconds = int64(d.ToDuration().Seconds()) + seconds = int64(d.ToDuration().Seconds()) + } else { + continue } var (