Skip to content

Commit

Permalink
ignore video if video.ContentDetails.Duration is empty, usually upcom…
Browse files Browse the repository at this point in the history
…ing live broadcast.
  • Loading branch information
fqx committed Jul 1, 2024
1 parent 0429af0 commit 0c2eb4e
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions pkg/builder/youtube.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 0c2eb4e

Please sign in to comment.