Skip to content

A self-hosted dashboard that puts all your feeds in one place

feat: add no_shorts option for YouTube feeds

3rd09eedc08c18c
diff --git a/internal/feed/youtube.go b/internal/feed/youtube.go
index e478259..6cc424a 100644
--- a/internal/feed/youtube.go
+++ b/internal/feed/youtube.go
@@ -39,11 +39,19 @@ func parseYoutubeFeedTime(t string) time.Time {
return parsedTime
}
-func FetchYoutubeChannelUploads(channelIds []string, videoUrlTemplate string) (Videos, error) {
+func FetchYoutubeChannelUploads(channelIds []string, videoUrlTemplate string, noShorts bool) (Videos, error) {
requests := make([]*http.Request, 0, len(channelIds))
for i := range channelIds {
- request, _ := http.NewRequest("GET", "https://www.youtube.com/feeds/videos.xml?channel_id="+channelIds[i], nil)
+ var feedUrl string
+ if noShorts && strings.HasPrefix(channelIds[i], "UC") {
+ playlistId := strings.Replace(channelIds[i], "UC", "UULF", 1)
+ feedUrl = "https://www.youtube.com/feeds/videos.xml?playlist_id=" + playlistId
+ } else {
+ feedUrl = "https://www.youtube.com/feeds/videos.xml?channel_id=" + channelIds[i]
+ }
+
+ request, _ := http.NewRequest("GET", feedUrl, nil)
requests = append(requests, request)
}
diff --git a/internal/widget/videos.go b/internal/widget/videos.go
index 717f302..e47db09 100644
--- a/internal/widget/videos.go
+++ b/internal/widget/videos.go
@@ -17,6 +17,7 @@ type Videos struct {
CollapseAfterRows int `yaml:"collapse-after-rows"`
Channels []string `yaml:"channels"`
Limit int `yaml:"limit"`
+ NoShorts bool `yaml:"no_shorts"`
}
func (widget *Videos) Initialize() error {
@@ -34,7 +35,7 @@ func (widget *Videos) Initialize() error {
}
func (widget *Videos) Update(ctx context.Context) {
- videos, err := feed.FetchYoutubeChannelUploads(widget.Channels, widget.VideoUrlTemplate)
+ videos, err := feed.FetchYoutubeChannelUploads(widget.Channels, widget.VideoUrlTemplate, widget.NoShorts)
if !widget.canContinueUpdateAfterHandlingErr(err) {
return