mirror of
https://github.com/nkanaev/yarr.git
synced 2026-06-16 21:15:03 +00:00
golines -w src
This commit is contained in:
@@ -91,13 +91,22 @@ func ParseAtom(r io.Reader) (*Feed, error) {
|
||||
|
||||
mediaLinks := srcitem.mediaLinks()
|
||||
|
||||
link := firstNonEmpty(srcitem.OrigLink, srcitem.Links.First("alternate"), srcitem.Links.First(""), linkFromID)
|
||||
link := firstNonEmpty(
|
||||
srcitem.OrigLink,
|
||||
srcitem.Links.First("alternate"),
|
||||
srcitem.Links.First(""),
|
||||
linkFromID,
|
||||
)
|
||||
dstfeed.Items = append(dstfeed.Items, Item{
|
||||
GUID: firstNonEmpty(guidFromID, srcitem.ID, link),
|
||||
Date: dateParse(firstNonEmpty(srcitem.Published, srcitem.Updated)),
|
||||
URL: link,
|
||||
Title: srcitem.Title.Text(),
|
||||
Content: firstNonEmpty(srcitem.Content.String(), srcitem.Summary.String(), srcitem.firstMediaDescription()),
|
||||
GUID: firstNonEmpty(guidFromID, srcitem.ID, link),
|
||||
Date: dateParse(firstNonEmpty(srcitem.Published, srcitem.Updated)),
|
||||
URL: link,
|
||||
Title: srcitem.Title.Text(),
|
||||
Content: firstNonEmpty(
|
||||
srcitem.Content.String(),
|
||||
srcitem.Summary.String(),
|
||||
srcitem.firstMediaDescription(),
|
||||
),
|
||||
MediaLinks: mediaLinks,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -40,7 +40,12 @@ func TestSniff(t *testing.T) {
|
||||
want := testcase.want
|
||||
have := sniff(testcase.input)
|
||||
if want.encoding != have.encoding || want.feedType != have.feedType {
|
||||
t.Errorf("Invalid output\n---\n%s\n---\n\nwant=%#v\nhave=%#v", testcase.input, want, have)
|
||||
t.Errorf(
|
||||
"Invalid output\n---\n%s\n---\n\nwant=%#v\nhave=%#v",
|
||||
testcase.input,
|
||||
want,
|
||||
have,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,10 @@ func (m *media) mediaLinks() []MediaLink {
|
||||
} else if strings.HasPrefix(content.MediaType, "video/") {
|
||||
links = append(links, MediaLink{URL: url, Type: "video", Description: description})
|
||||
} else if content.MediaMedium == "image" || content.MediaMedium == "audio" || content.MediaMedium == "video" {
|
||||
links = append(links, MediaLink{URL: url, Type: content.MediaMedium, Description: description})
|
||||
links = append(
|
||||
links,
|
||||
MediaLink{URL: url, Type: content.MediaMedium, Description: description},
|
||||
)
|
||||
} else {
|
||||
if len(content.MediaThumbnails) > 0 {
|
||||
links = append(links, MediaLink{
|
||||
|
||||
@@ -42,8 +42,16 @@ func TestRDFFeed(t *testing.T) {
|
||||
Title: "Mozilla Dot Org",
|
||||
SiteURL: "http://www.mozilla.org",
|
||||
Items: []Item{
|
||||
{GUID: "http://www.mozilla.org/status/", URL: "http://www.mozilla.org/status/", Title: "New Status Updates"},
|
||||
{GUID: "http://www.mozilla.org/bugs/", URL: "http://www.mozilla.org/bugs/", Title: "Bugzilla Reorganized"},
|
||||
{
|
||||
GUID: "http://www.mozilla.org/status/",
|
||||
URL: "http://www.mozilla.org/status/",
|
||||
Title: "New Status Updates",
|
||||
},
|
||||
{
|
||||
GUID: "http://www.mozilla.org/bugs/",
|
||||
URL: "http://www.mozilla.org/bugs/",
|
||||
Title: "Bugzilla Reorganized",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,8 @@ func ParseRSS(r io.Reader) (*Feed, error) {
|
||||
for _, e := range srcitem.Enclosures {
|
||||
if strings.HasPrefix(e.Type, "audio/") {
|
||||
podcastURL := e.URL
|
||||
if srcitem.OrigEnclosureLink != "" && strings.Contains(podcastURL, path.Base(srcitem.OrigEnclosureLink)) {
|
||||
if srcitem.OrigEnclosureLink != "" &&
|
||||
strings.Contains(podcastURL, path.Base(srcitem.OrigEnclosureLink)) {
|
||||
podcastURL = srcitem.OrigEnclosureLink
|
||||
}
|
||||
mediaLinks = append(mediaLinks, MediaLink{URL: podcastURL, Type: "audio"})
|
||||
@@ -97,11 +98,15 @@ func ParseRSS(r io.Reader) (*Feed, error) {
|
||||
}
|
||||
|
||||
dstfeed.Items = append(dstfeed.Items, Item{
|
||||
GUID: firstNonEmpty(srcitem.GUID.GUID, srcitem.Link),
|
||||
Date: dateParse(firstNonEmpty(srcitem.DublinCoreDate, srcitem.PubDate)),
|
||||
URL: firstNonEmpty(srcitem.OrigLink, srcitem.Link, permalink),
|
||||
Title: srcitem.Title,
|
||||
Content: firstNonEmpty(srcitem.ContentEncoded, srcitem.Description, srcitem.firstMediaDescription()),
|
||||
GUID: firstNonEmpty(srcitem.GUID.GUID, srcitem.Link),
|
||||
Date: dateParse(firstNonEmpty(srcitem.DublinCoreDate, srcitem.PubDate)),
|
||||
URL: firstNonEmpty(srcitem.OrigLink, srcitem.Link, permalink),
|
||||
Title: srcitem.Title,
|
||||
Content: firstNonEmpty(
|
||||
srcitem.ContentEncoded,
|
||||
srcitem.Description,
|
||||
srcitem.firstMediaDescription(),
|
||||
),
|
||||
MediaLinks: mediaLinks,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -303,9 +303,21 @@ func TestRSSMultipleMedia(t *testing.T) {
|
||||
GUID: "http://example.com/posts/1",
|
||||
URL: "http://example.com/posts/1",
|
||||
MediaLinks: []MediaLink{
|
||||
{URL: "https://example.com/path/to/image1.png", Type: "image", Description: "description 1"},
|
||||
{URL: "https://example.com/path/to/image2.png", Type: "image", Description: "description 2"},
|
||||
{URL: "https://example.com/path/to/video1.mp4", Type: "video", Description: "video description"},
|
||||
{
|
||||
URL: "https://example.com/path/to/image1.png",
|
||||
Type: "image",
|
||||
Description: "description 1",
|
||||
},
|
||||
{
|
||||
URL: "https://example.com/path/to/image2.png",
|
||||
Type: "image",
|
||||
Description: "description 2",
|
||||
},
|
||||
{
|
||||
URL: "https://example.com/path/to/video1.mp4",
|
||||
Type: "video",
|
||||
Description: "video description",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user