diff options
author | siddharth ravikumar <s@ricketyspace.net> | 2022-11-26 07:49:26 -0500 |
---|---|---|
committer | siddharth ravikumar <s@ricketyspace.net> | 2022-11-26 07:49:26 -0500 |
commit | f06da1815748cbad110e817097c7bc14e32b1055 (patch) | |
tree | 36ca13efb99d63fe1291ed40e209c947b94e8fa3 /feed/feed.go | |
parent | fac1158a67ce41809a69feb76c88bfae0a0b4bfa (diff) |
feed: add `podcastUnmarshal`
Diffstat (limited to 'feed/feed.go')
-rw-r--r-- | feed/feed.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/feed/feed.go b/feed/feed.go index 1223195..3a3fa30 100644 --- a/feed/feed.go +++ b/feed/feed.go @@ -297,3 +297,38 @@ func youtubeUnmarshal(bs []byte) ([]schema.Entry, error) { } return entries, nil } + +// Unmarshal a Podcast feed. +func podcastUnmarshal(bs []byte) ([]schema.Entry, error) { + pcFeed := new(schema.PodcastFeed) + err := xml.Unmarshal(bs, pcFeed) + if err != nil { + return nil, err + } + + // Get all entries. + entries := make([]schema.Entry, 0) + for _, e := range pcFeed.Entries { + layout := time.RFC1123Z + if e.Pub[len(e.Pub)-1:] == "T" { + // Textual time zone. like 'EDT'. + if e.Pub[6:7] == " " { + layout = "Mon, 2 Jan 2006 15:04:05 MST" + } else { + layout = time.RFC1123 + } + } + t, err := time.Parse(layout, e.Pub) + if err != nil { + return nil, err + } + entry := schema.Entry{ + Id: e.Id, + Title: e.Title, + PubTime: t, + Link: e.Link.Url, + } + entries = append(entries, entry) + } + return entries, nil +} |