diff --git a/docs/configuration.md b/docs/configuration.md index 70e76def..d2439d2d 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -874,6 +874,7 @@ Preview: | collapse-after | integer | no | 7 | | collapse-after-rows | integer | no | 4 | | include-shorts | boolean | no | false | +| publish-threshold | int | no | 0 | | video-url-template | string | no | https://www.youtube.com/watch?v={VIDEO-ID} | ##### `channels` @@ -927,6 +928,9 @@ Preview of `grid-cards`: ![](images/videos-widget-grid-cards-preview.png) +##### `publish-threshold` +Used to display only videos published in the last number of days specified through the provided value. + ##### `video-url-template` Used to replace the default link for videos. Useful when you're running your own YouTube front-end. Example: diff --git a/internal/glance/widget-videos.go b/internal/glance/widget-videos.go index ecf77fab..51dc1736 100644 --- a/internal/glance/widget-videos.go +++ b/internal/glance/widget-videos.go @@ -31,6 +31,7 @@ type videosWidget struct { Playlists []string `yaml:"playlists"` Limit int `yaml:"limit"` IncludeShorts bool `yaml:"include-shorts"` + PublishThreshold int `yaml:"publish-threshold"` SortBy string `yaml:"sort-by"` } @@ -65,7 +66,7 @@ func (widget *videosWidget) initialize() error { } func (widget *videosWidget) update(ctx context.Context) { - videos, err := fetchYoutubeChannelUploads(widget.Channels, widget.VideoUrlTemplate, widget.IncludeShorts, widget.SortBy) + videos, err := fetchYoutubeChannelUploads(widget.Channels, widget.VideoUrlTemplate, widget.IncludeShorts, widget.PublishThreshold, widget.SortBy) if !widget.canContinueUpdateAfterHandlingErr(err) { return @@ -149,7 +150,7 @@ func (v videoList) sortByUpdated() videoList { return v } -func fetchYoutubeChannelUploads(channelOrPlaylistIDs []string, videoUrlTemplate string, includeShorts bool, sortBy string) (videoList, error) { +func fetchYoutubeChannelUploads(channelOrPlaylistIDs []string, videoUrlTemplate string, includeShorts bool, publishThreshold int, sortBy string) (videoList, error) { requests := make([]*http.Request, 0, len(channelOrPlaylistIDs)) for i := range channelOrPlaylistIDs { @@ -202,13 +203,19 @@ func fetchYoutubeChannelUploads(channelOrPlaylistIDs []string, videoUrlTemplate } } + published := parseYoutubeFeedTime(v.Published) + dateThreshold := time.Now().AddDate(0, 0, -publishThreshold) + if publishThreshold > 0 && published.Before(dateThreshold) { + continue + } + videos = append(videos, video{ ThumbnailUrl: v.Group.Thumbnail.Url, Title: v.Title, Url: videoUrl, Author: response.Channel, AuthorUrl: response.ChannelLink + "/videos", - TimePosted: parseYoutubeFeedTime(v.Published), + TimePosted: published, TimeUpdated: parseYoutubeFeedTime(v.Updated), }) }