From fe24f1ea0d338dc11d43b69422971c5706d082df Mon Sep 17 00:00:00 2001 From: Rico Berger Date: Mon, 2 Oct 2023 19:59:52 +0200 Subject: [PATCH] [podcast] Improve Parsing (#17) This commit improves the parsing of the RSS feeds for a podcast, because some podcasts were not working as expected: - The "https://gotime.fm/rss" podcast uses the "itunes:image" field for the podcast icon instead of "image", so that we now looking at both fields to add the podcast icon. - The "https://itsallwidgets.com/podcast/feed" podcast didn't contain a link in the entries, so that all entries were skipped. For that a podcast must not contain a link anymore to be parsed, but most contain a media file which can be played within the app. --- supabase/functions/_shared/feed/podcast.ts | 25 +++++++++++++--------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/supabase/functions/_shared/feed/podcast.ts b/supabase/functions/_shared/feed/podcast.ts index aff9cb2..083ca6b 100644 --- a/supabase/functions/_shared/feed/podcast.ts +++ b/supabase/functions/_shared/feed/podcast.ts @@ -68,8 +68,12 @@ export const getPodcastFeed = async ( if (feed.links.length > 0) { source.link = feed.links[0]; } - if (feed.image?.url) { - source.icon = feed.image?.url; + if ( + // deno-lint-ignore no-explicit-any + !source.icon && (feed.image?.url || (feed as any)["itunes:image"]?.href) + ) { + // deno-lint-ignore no-explicit-any + source.icon = feed.image?.url || (feed as any)["itunes:image"]?.href; source.icon = await uploadSourceIcon(supabaseClient, source); } @@ -85,13 +89,12 @@ export const getPodcastFeed = async ( break; } + const media = getMedia(entry); + /** - * If the entry does not contain a title, a link or a published date we skip it. + * If the entry does not contain a title, a published date or a media file we skip it. */ - if ( - !entry.title?.value || - (entry.links.length === 0 || !entry.links[0].href) || !entry.published - ) { + if (!entry.title?.value || !entry.published || !media) { continue; } @@ -103,7 +106,7 @@ export const getPodcastFeed = async ( let itemId = ""; if (entry.id != "") { itemId = generateItemId(source.id, entry.id); - } else if (entry.links.length > 0 && entry.links[0].href) { + } else if (entry.links && entry.links.length > 0 && entry.links[0].href) { itemId = generateItemId(source.id, entry.links[0].href); } else { continue; @@ -115,8 +118,10 @@ export const getPodcastFeed = async ( columnId: source.columnId, sourceId: source.id, title: entry.title.value, - link: entry.links[0].href, - media: getMedia(entry), + link: entry.links && entry.links.length > 0 && entry.links[0].href + ? entry.links[0].href + : media, + media: media, description: entry.description?.value ? unescape(entry.description.value) : undefined,