mirror of
https://github.com/nkanaev/yarr.git
synced 2026-03-18 09:57:42 +00:00
parse rss 2.0 image enclosures
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
- (fix) articles not resetting immediately after feed/filter selection (thank to @scratchmex for the report)
|
||||
- (fix) crash on empty article list with article is selected (thanks to @rksvc)
|
||||
- (fix) invalid article title in RSS feeds with media containing titles (thanks to @bwwu-git for the report)
|
||||
- (fix) missing image enclosures in certain RSS feeds (thanks to @palinek for the report)
|
||||
|
||||
# v2.6 (2025-11-24)
|
||||
|
||||
|
||||
@@ -85,6 +85,11 @@ func ParseRSS(r io.Reader) (*Feed, error) {
|
||||
break
|
||||
}
|
||||
}
|
||||
for _, e := range srcitem.Enclosures {
|
||||
if strings.HasPrefix(e.Type, "image/") {
|
||||
mediaLinks = append(mediaLinks, MediaLink{URL: e.URL, Type: "image"})
|
||||
}
|
||||
}
|
||||
|
||||
permalink := ""
|
||||
if srcitem.GUID.IsPermaLink == "true" {
|
||||
|
||||
@@ -248,6 +248,35 @@ func TestRSSIsPermalink(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// https://github.com/nkanaev/yarr/issues/284
|
||||
func TestRSSEnclosureImage(t *testing.T) {
|
||||
feed, _ := Parse(strings.NewReader(`
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<rss version="2.0">
|
||||
<channel>
|
||||
<item>
|
||||
<title>Post with image</title>
|
||||
<link>http://example.com/post/1</link>
|
||||
<enclosure url="http://example.com/photo.jpg" type="image/jpeg" length="123456"/>
|
||||
</item>
|
||||
</channel>
|
||||
</rss>
|
||||
`))
|
||||
if len(feed.Items[0].MediaLinks) != 1 {
|
||||
t.Fatalf("Expected 1 media link, got %d: %#v", len(feed.Items[0].MediaLinks), feed.Items[0].MediaLinks)
|
||||
}
|
||||
have := feed.Items[0].MediaLinks[0]
|
||||
want := MediaLink{
|
||||
URL: "http://example.com/photo.jpg",
|
||||
Type: "image",
|
||||
}
|
||||
if !reflect.DeepEqual(want, have) {
|
||||
t.Logf("want: %#v", want)
|
||||
t.Logf("have: %#v", have)
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
func TestRSSMultipleMedia(t *testing.T) {
|
||||
feed, _ := Parse(strings.NewReader(`
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
Reference in New Issue
Block a user