From 3047b9266833f61ad112fefc9169efd199daaa54 Mon Sep 17 00:00:00 2001 From: siddharth Date: Sat, 27 Nov 2021 18:58:33 -0500 Subject: feed: add youtubeUnmarshal Unmarshler for a YouTube Feed. --- feed/feed.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'feed') diff --git a/feed/feed.go b/feed/feed.go index b20a281..3f82096 100644 --- a/feed/feed.go +++ b/feed/feed.go @@ -105,3 +105,20 @@ func nprUnmarshal(bs []byte) (schema.NPRFeed, error) { return *nprFeed, nil } +// Unmarshal a YouTube feed. +func youtubeUnmarshal(bs []byte) (schema.YouTubeFeed, error) { + ytFeed := new(schema.YouTubeFeed) + err := xml.Unmarshal(bs, ytFeed) + if err != nil { + return *ytFeed, err + } + + // Parse time for all entries. + for i, entry := range ytFeed.Entries { + ytFeed.Entries[i].PubTime, err = time.Parse(time.RFC3339, entry.Pub) + if err != nil { + return *ytFeed, err + } + } + return *ytFeed, nil +} -- cgit v1.2.3