Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions plugins/feed-discovery/src/feed-discovery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ describe("feed parsing", () => {
expect(atom.ok).toBe(true);
expect(json.ok).toBe(true);
});

it("classifies RSS feeds with audio enclosures as podcasts", () => {
const result = parseFeedDocument(
"https://example.com/podcast.xml",
`<?xml version="1.0"?>
<rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
<channel>
<title>Example Podcast</title>
<itunes:author>Example Host</itunes:author>
<item>
<title>Episode 1</title>
<enclosure url="https://example.com/episode-1.mp3" type="audio/mpeg" />
</item>
</channel>
</rss>`
);

expect(result.ok).toBe(true);
expect(result.kind).toBe("podcast");
});
});

describe("site probing helpers", () => {
Expand Down
15 changes: 13 additions & 2 deletions plugins/feed-discovery/src/feed-parsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function parseRss(feedUrl: string, rss: Record<string, unknown>): ValidationResu
title: title || "Untitled RSS Feed",
description: stringValue(channel.description),
homepageUrl: linkValue(channel.link),
kind: detectRssKind(channel),
kind: detectRssKind(channel, items),
language: stringValue(channel.language),
imageUrl: imageValue(channel.image),
lastPublishedAt: newestDate([stringValue(channel.lastBuildDate), stringValue(channel.pubDate), ...sampleItems.map((item) => item.publishedAt)]),
Expand Down Expand Up @@ -132,10 +132,21 @@ function parseAtom(feedUrl: string, feed: Record<string, unknown>): ValidationRe
};
}

function detectRssKind(channel: Record<string, unknown>): FeedKind {
function detectRssKind(channel: Record<string, unknown>, items: Record<string, unknown>[]): FeedKind {
if (channel.itunes || channel["itunes:author"] || channel.enclosure) {
return "podcast";
}
const hasMediaEnclosure = items.some((item) =>
asArray(item.enclosure)
.filter(isRecord)
.some((enclosure) => {
const type = stringValue(enclosure.type)?.toLowerCase();
return type?.startsWith("audio/") || type?.startsWith("video/");
})
);
if (hasMediaEnclosure) {
return "podcast";
}
return "blog";
}

Expand Down