From e8ad98e8957b0ec11497bb635b4ef9f9c0e604c6 Mon Sep 17 00:00:00 2001 From: Andrei <41676929+drejleeo@users.noreply.github.com> Date: Wed, 23 Jul 2025 14:31:52 +0300 Subject: [PATCH 1/2] Update configuration.md --- docs/configuration.md | 4 ++++ 1 file changed, 4 insertions(+) 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: From 86392dcfef84b1b5ffb73bc7878a4b43f93a7b4a Mon Sep 17 00:00:00 2001 From: Andrei <41676929+drejleeo@users.noreply.github.com> Date: Wed, 23 Jul 2025 14:36:13 +0300 Subject: [PATCH 2/2] Update widget-videos.go Add option to videos widget to display only videos published in the last number of days mentioned through the provided value. --- internal/glance/widget-videos.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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), }) }