mirror of
https://github.com/nkanaev/yarr.git
synced 2025-05-24 00:33:14 +00:00
podcasts
This commit is contained in:
parent
5335863488
commit
51cbdea31f
@ -71,13 +71,13 @@ func ParseAtom(r io.Reader) (*Feed, error) {
|
|||||||
}
|
}
|
||||||
for _, srcitem := range srcfeed.Entries {
|
for _, srcitem := range srcfeed.Entries {
|
||||||
dstfeed.Items = append(dstfeed.Items, Item{
|
dstfeed.Items = append(dstfeed.Items, Item{
|
||||||
GUID: firstNonEmpty(srcitem.ID),
|
GUID: firstNonEmpty(srcitem.ID),
|
||||||
Date: dateParse(firstNonEmpty(srcitem.Published, srcitem.Updated)),
|
Date: dateParse(firstNonEmpty(srcitem.Published, srcitem.Updated)),
|
||||||
URL: firstNonEmpty(srcitem.Links.First("alternate"), srcfeed.Links.First("")),
|
URL: firstNonEmpty(srcitem.Links.First("alternate"), srcfeed.Links.First("")),
|
||||||
Title: srcitem.Title.String(),
|
Title: srcitem.Title.String(),
|
||||||
Content: firstNonEmpty(srcitem.Content.String(), srcitem.firstMediaDescription()),
|
Content: firstNonEmpty(srcitem.Content.String(), srcitem.firstMediaDescription()),
|
||||||
ImageURL: srcitem.firstMediaThumbnail(),
|
ImageURL: srcitem.firstMediaThumbnail(),
|
||||||
PodcastURL: "",
|
AudioURL: "",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return dstfeed, nil
|
return dstfeed, nil
|
||||||
|
@ -40,13 +40,13 @@ func TestAtom(t *testing.T) {
|
|||||||
SiteURL: "http://example.org/",
|
SiteURL: "http://example.org/",
|
||||||
Items: []Item{
|
Items: []Item{
|
||||||
{
|
{
|
||||||
GUID: "urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a",
|
GUID: "urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a",
|
||||||
Date: time.Unix(1071340202, 0).UTC(),
|
Date: time.Unix(1071340202, 0).UTC(),
|
||||||
URL: "http://example.org/2003/12/13/atom03.html",
|
URL: "http://example.org/2003/12/13/atom03.html",
|
||||||
Title: "Atom-Powered Robots Run Amok",
|
Title: "Atom-Powered Robots Run Amok",
|
||||||
Content: `<div xmlns="http://www.w3.org/1999/xhtml"><p>This is the entry content.</p></div>`,
|
Content: `<div xmlns="http://www.w3.org/1999/xhtml"><p>This is the entry content.</p></div>`,
|
||||||
ImageURL: "",
|
ImageURL: "",
|
||||||
PodcastURL: "",
|
AudioURL: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ type Item struct {
|
|||||||
URL string
|
URL string
|
||||||
Title string
|
Title string
|
||||||
|
|
||||||
Content string
|
Content string
|
||||||
ImageURL string
|
ImageURL string
|
||||||
PodcastURL string
|
AudioURL string
|
||||||
}
|
}
|
||||||
|
@ -18,12 +18,12 @@ type rssFeed struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type rssItem struct {
|
type rssItem struct {
|
||||||
GUID string `xml:"guid"`
|
GUID string `xml:"guid"`
|
||||||
Title string `xml:"title"`
|
Title string `xml:"title"`
|
||||||
Link string `xml:"link"`
|
Link string `xml:"link"`
|
||||||
Description string `xml:"rss description"`
|
Description string `xml:"rss description"`
|
||||||
PubDate string `xml:"pubDate"`
|
PubDate string `xml:"pubDate"`
|
||||||
EnclosureLinks []rssEnclosure `xml:"enclosure"`
|
Enclosures []rssEnclosure `xml:"enclosure"`
|
||||||
|
|
||||||
DublinCoreDate string `xml:"http://purl.org/dc/elements/1.1/ date"`
|
DublinCoreDate string `xml:"http://purl.org/dc/elements/1.1/ date"`
|
||||||
ContentEncoded string `xml:"http://purl.org/rss/1.0/modules/content/ encoded"`
|
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,
|
SiteURL: srcfeed.Link,
|
||||||
}
|
}
|
||||||
for _, srcitem := range srcfeed.Items {
|
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{
|
dstfeed.Items = append(dstfeed.Items, Item{
|
||||||
GUID: firstNonEmpty(srcitem.GUID, srcitem.Link),
|
GUID: firstNonEmpty(srcitem.GUID, srcitem.Link),
|
||||||
Date: dateParse(firstNonEmpty(srcitem.DublinCoreDate, srcitem.PubDate)),
|
Date: dateParse(firstNonEmpty(srcitem.DublinCoreDate, srcitem.PubDate)),
|
||||||
URL: srcitem.Link,
|
URL: srcitem.Link,
|
||||||
Title: srcitem.Title,
|
Title: srcitem.Title,
|
||||||
Content: srcitem.Description,
|
Content: srcitem.Description,
|
||||||
|
AudioURL: podcastURL,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return dstfeed, nil
|
return dstfeed, nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user