mirror of
https://github.com/nkanaev/yarr.git
synced 2025-07-09 00:10:09 +00:00
feedburner
This commit is contained in:
parent
3512350a22
commit
0a0db68905
@ -24,6 +24,8 @@ type atomEntry struct {
|
|||||||
Updated string `xml:"updated"`
|
Updated string `xml:"updated"`
|
||||||
Links atomLinks `xml:"link"`
|
Links atomLinks `xml:"link"`
|
||||||
Content atomText `xml:"http://www.w3.org/2005/Atom content"`
|
Content atomText `xml:"http://www.w3.org/2005/Atom content"`
|
||||||
|
OrigLink string `xml:"http://rssnamespace.org/feedburner/ext/1.0 origLink"`
|
||||||
|
|
||||||
media
|
media
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,9 +75,9 @@ func ParseAtom(r io.Reader) (*Feed, error) {
|
|||||||
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.OrigLink, srcitem.Links.First("alternate"), srcitem.Links.First("")),
|
||||||
Title: srcitem.Title.String(),
|
Title: srcitem.Title.String(),
|
||||||
Content: firstNonEmpty(srcitem.Content.String(), srcitem.firstMediaDescription()),
|
Content: firstNonEmpty(srcitem.Content.String(), srcitem.Summary.String(), srcitem.firstMediaDescription()),
|
||||||
ImageURL: srcitem.firstMediaThumbnail(),
|
ImageURL: srcitem.firstMediaThumbnail(),
|
||||||
AudioURL: "",
|
AudioURL: "",
|
||||||
})
|
})
|
||||||
|
@ -7,6 +7,8 @@ package parser
|
|||||||
import (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"io"
|
"io"
|
||||||
|
"path"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type rssFeed struct {
|
type rssFeed struct {
|
||||||
@ -28,8 +30,8 @@ type rssItem struct {
|
|||||||
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"`
|
||||||
|
|
||||||
FeedBurnerLink string `xml:"http://rssnamespace.org/feedburner/ext/1.0 origLink"`
|
OrigLink string `xml:"http://rssnamespace.org/feedburner/ext/1.0 origLink"`
|
||||||
FeedBurnerEnclosureLink string `xml:"http://rssnamespace.org/feedburner/ext/1.0 origEnclosureLink"`
|
OrigEnclosureLink string `xml:"http://rssnamespace.org/feedburner/ext/1.0 origEnclosureLink"`
|
||||||
|
|
||||||
ItunesSubtitle string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd subtitle"`
|
ItunesSubtitle string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd subtitle"`
|
||||||
ItunesSummary string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd summary"`
|
ItunesSummary string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd summary"`
|
||||||
@ -74,6 +76,12 @@ func ParseRSS(r io.Reader) (*Feed, error) {
|
|||||||
for _, e := range srcitem.Enclosures {
|
for _, e := range srcitem.Enclosures {
|
||||||
if e.Type == "audio/mpeg" || e.Type == "audio/x-m4a" {
|
if e.Type == "audio/mpeg" || e.Type == "audio/x-m4a" {
|
||||||
podcastURL = e.URL
|
podcastURL = e.URL
|
||||||
|
|
||||||
|
origBase := path.Base(srcitem.OrigEnclosureLink)
|
||||||
|
if origBase != "" && strings.Contains(podcastURL, origBase) {
|
||||||
|
podcastURL = srcitem.OrigEnclosureLink
|
||||||
|
}
|
||||||
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -81,7 +89,7 @@ func ParseRSS(r io.Reader) (*Feed, error) {
|
|||||||
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: firstNonEmpty(srcitem.OrigLink, srcitem.Link),
|
||||||
Title: srcitem.Title,
|
Title: srcitem.Title,
|
||||||
Content: firstNonEmpty(srcitem.ContentEncoded, srcitem.Description),
|
Content: firstNonEmpty(srcitem.ContentEncoded, srcitem.Description),
|
||||||
AudioURL: podcastURL,
|
AudioURL: podcastURL,
|
||||||
|
@ -12,8 +12,9 @@ import (
|
|||||||
|
|
||||||
func firstNonEmpty(vals ...string) string {
|
func firstNonEmpty(vals ...string) string {
|
||||||
for _, val := range vals {
|
for _, val := range vals {
|
||||||
if len(val) > 0 {
|
valTrimmed := strings.TrimSpace(val)
|
||||||
return val
|
if len(valTrimmed) > 0 {
|
||||||
|
return valTrimmed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user