From a3958dba21b777892bf199d54971f2bd80e677e4 Mon Sep 17 00:00:00 2001 From: Evan Date: Sun, 9 Apr 2023 07:09:06 -0700 Subject: [PATCH] feat(route/inoreader): add podcast support (#12201) * feat(route/inoreader): add podcast support * fix: null value * fix: null value * chore: add itunes support --- lib/v2/inoreader/rss.js | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/lib/v2/inoreader/rss.js b/lib/v2/inoreader/rss.js index 0357cae16..39f0d9bc3 100644 --- a/lib/v2/inoreader/rss.js +++ b/lib/v2/inoreader/rss.js @@ -1,4 +1,5 @@ const parser = require('@/utils/rss-parser'); +const cheerio = require('cheerio'); module.exports = async (ctx) => { const user = ctx.params.user; @@ -6,15 +7,39 @@ module.exports = async (ctx) => { const rootUrl = 'https://www.inoreader.com/stream'; const rssUrl = `${rootUrl}/user/${user}/tag/${tag}`; const feed = await parser.parseURL(rssUrl); - feed.items = feed.items.map((item) => ({ - title: item.title, - pubDate: item.pubDate, - link: item.link, - description: item.content, - category: item.categories, - })); + feed.items = feed.items.map((item) => { + if (item && item.enclosure && item.enclosure.type.includes('audio')) { + // output podcast rss + // get first image in content + let firstImgSrc = ''; + if (item.content !== null) { + const $ = cheerio.load(item.content); + firstImgSrc = $('img').first().attr('src'); + } + return { + title: item.title, + pubDate: item.pubDate, + link: item.link, + description: item.content, + category: item.categories, + itunes_item_image: firstImgSrc, + enclosure_url: item.enclosure.url, + enclosure_length: item.enclosure.length, + enclosure_type: item.enclosure.type, + }; + } + return { + title: item?.title ?? '', + pubDate: item?.pubDate ?? '', + link: item?.link ?? '', + description: item?.content ?? '', + category: item?.categories ?? [], + }; + }); ctx.state.data = { title: feed.title, + itunes_author: 'Inoreader', + image: 'https://www.inoreader.com/brand/img/ino_app_icon.png', link: feed.link, description: feed.description, item: feed.items,