initial commit

This commit is contained in:
2026-05-12 16:36:17 +02:00
commit fca89420e4
13 changed files with 397 additions and 0 deletions

43
lib/youtube.go Normal file
View File

@@ -0,0 +1,43 @@
package lib
import (
"fmt"
"github.com/mmcdole/gofeed"
)
type Video struct {
ID string
Title string
URL string
}
type Youtube struct {
channelID string
parser *gofeed.Parser
}
func NewYoutube(channelID string) *Youtube {
return &Youtube{
channelID: channelID,
parser: gofeed.NewParser(),
}
}
func (y *Youtube) FetchLatest() ([]Video, error) {
feedURL := fmt.Sprintf("https://www.youtube.com/feeds/videos.xml?channel_id=%s", y.channelID)
feed, err := y.parser.ParseURL(feedURL)
if err != nil {
return nil, fmt.Errorf("parse feed: %w", err)
}
videos := make([]Video, 0, len(feed.Items))
for _, item := range feed.Items {
videos = append(videos, Video{
ID: item.GUID,
Title: item.Title,
URL: item.Link,
})
}
return videos, nil
}