diff --git a/src/parser/atom.go b/src/parser/atom.go index 9a76d0f..b943e62 100644 --- a/src/parser/atom.go +++ b/src/parser/atom.go @@ -71,13 +71,13 @@ func ParseAtom(r io.Reader) (*Feed, error) { } for _, srcitem := range srcfeed.Entries { dstfeed.Items = append(dstfeed.Items, Item{ - GUID: firstNonEmpty(srcitem.ID), - Date: dateParse(firstNonEmpty(srcitem.Published, srcitem.Updated)), - URL: firstNonEmpty(srcitem.Links.First("alternate"), srcfeed.Links.First("")), - Title: srcitem.Title.String(), - Content: firstNonEmpty(srcitem.Content.String(), srcitem.firstMediaDescription()), - ImageURL: srcitem.firstMediaThumbnail(), - PodcastURL: "", + GUID: firstNonEmpty(srcitem.ID), + Date: dateParse(firstNonEmpty(srcitem.Published, srcitem.Updated)), + URL: firstNonEmpty(srcitem.Links.First("alternate"), srcfeed.Links.First("")), + Title: srcitem.Title.String(), + Content: firstNonEmpty(srcitem.Content.String(), srcitem.firstMediaDescription()), + ImageURL: srcitem.firstMediaThumbnail(), + AudioURL: "", }) } return dstfeed, nil diff --git a/src/parser/atom_test.go b/src/parser/atom_test.go index bd14d79..d3aa05f 100644 --- a/src/parser/atom_test.go +++ b/src/parser/atom_test.go @@ -40,13 +40,13 @@ func TestAtom(t *testing.T) { SiteURL: "http://example.org/", Items: []Item{ { - GUID: "urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a", - Date: time.Unix(1071340202, 0).UTC(), - URL: "http://example.org/2003/12/13/atom03.html", - Title: "Atom-Powered Robots Run Amok", - Content: `

This is the entry content.

`, - ImageURL: "", - PodcastURL: "", + GUID: "urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a", + Date: time.Unix(1071340202, 0).UTC(), + URL: "http://example.org/2003/12/13/atom03.html", + Title: "Atom-Powered Robots Run Amok", + Content: `

This is the entry content.

`, + ImageURL: "", + AudioURL: "", }, }, } diff --git a/src/parser/models.go b/src/parser/models.go index 7d2a28f..7587b77 100644 --- a/src/parser/models.go +++ b/src/parser/models.go @@ -14,7 +14,7 @@ type Item struct { URL string Title string - Content string - ImageURL string - PodcastURL string + Content string + ImageURL string + AudioURL string } diff --git a/src/parser/rss.go b/src/parser/rss.go index 8cb88cd..9619437 100644 --- a/src/parser/rss.go +++ b/src/parser/rss.go @@ -18,12 +18,12 @@ type rssFeed struct { } type rssItem struct { - GUID string `xml:"guid"` - Title string `xml:"title"` - Link string `xml:"link"` - Description string `xml:"rss description"` - PubDate string `xml:"pubDate"` - EnclosureLinks []rssEnclosure `xml:"enclosure"` + GUID string `xml:"guid"` + Title string `xml:"title"` + Link string `xml:"link"` + Description string `xml:"rss description"` + PubDate string `xml:"pubDate"` + Enclosures []rssEnclosure `xml:"enclosure"` DublinCoreDate string `xml:"http://purl.org/dc/elements/1.1/ date"` ContentEncoded string `xml:"http://purl.org/rss/1.0/modules/content/ encoded"` @@ -69,12 +69,21 @@ func ParseRSS(r io.Reader) (*Feed, error) { SiteURL: srcfeed.Link, } for _, srcitem := range srcfeed.Items { + podcastURL := "" + for _, e := range srcitem.Enclosures { + if e.Type == "audio/mpeg" || e.Type == "audio/x-m4a" { + podcastURL = e.URL + break + } + } + dstfeed.Items = append(dstfeed.Items, Item{ - GUID: firstNonEmpty(srcitem.GUID, srcitem.Link), - Date: dateParse(firstNonEmpty(srcitem.DublinCoreDate, srcitem.PubDate)), - URL: srcitem.Link, - Title: srcitem.Title, - Content: srcitem.Description, + GUID: firstNonEmpty(srcitem.GUID, srcitem.Link), + Date: dateParse(firstNonEmpty(srcitem.DublinCoreDate, srcitem.PubDate)), + URL: srcitem.Link, + Title: srcitem.Title, + Content: srcitem.Description, + AudioURL: podcastURL, }) } return dstfeed, nil