Detect podcast RSS item enclosures (#50)

This commit is contained in:
RissRIce 2026-06-13 23:55:06 -06:00 committed by GitHub
parent be530ab687
commit aa3fdba277
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 2 deletions

View file

@ -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)]),
@ -132,13 +132,30 @@ 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";
}
if (items.some(hasPodcastEnclosure)) {
return "podcast";
}
return "blog";
}
function hasPodcastEnclosure(item: Record<string, unknown>) {
return asArray(item.enclosure)
.filter(isRecord)
.some((enclosure) => {
const type = stringValue(enclosure.type)?.toLowerCase();
const url = stringValue(enclosure.url);
return (
type?.startsWith("audio/") ||
type?.startsWith("video/") ||
/\.(mp3|m4a|mp4|m4v|ogg|oga|wav|aac|flac)(?:[?#].*)?$/i.test(url ?? "")
);
});
}
function imageValue(value: unknown) {
if (isRecord(value)) {
return stringValue(value.url);