Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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:

Expand Down
13 changes: 10 additions & 3 deletions internal/glance/widget-videos.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
})
}
Expand Down