feat(route/inoreader): add podcast support (#12201)
* feat(route/inoreader): add podcast support * fix: null value * fix: null value * chore: add itunes support
This commit is contained in:
+32
-7
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user