feat(route): line today publisher (#12208)

* feat(route): line today publisher

* fix: th parsing
This commit is contained in:
Tony
2023-03-31 01:34:51 +08:00
committed by GitHub
parent 2aa81d9490
commit e17a1ae316
8 changed files with 123 additions and 41 deletions
+7 -3
View File
@@ -454,11 +454,11 @@ Provides a better reading experience (full text articles) over the official one.
<RouteEn author="loganrockmore" example="/letterboxd/user/followingdiary/demiadejuyigbe" path="/letterboxd/user/followingdiary/:username" :paramsDesc="['username']" />
## Line
## LINE
### Today
### TODAY
<RouteEn author="nczitzk" example="/line/today" path="/line/today/:edition?/:tab?" :paramsDesc="['Edition, see below, Taiwan by default', 'Tag, can be found in URL, top by default']">
<RouteEn author="nczitzk" example="/line/today" path="/line/today/:edition?/:tab?" :paramsDesc="['Edition, see below, Taiwan by default', 'Tag, can be found in URL, `top` by default']">
Edition
@@ -468,6 +468,10 @@ Edition
</RouteEn>
### TODAY - Channel
<RouteEn author="TonyRL" example="/line/today/th/publisher/101048" path="/line/today/:edition/publisher/:id" :paramsDesc="['Edition, see table above', 'Channel ID, can be found in URL']" radar="1" />
## Macfilos
### Blog
+7 -3
View File
@@ -816,11 +816,11 @@ Tag
<Route author="loganrockmore" example="/letterboxd/user/followingdiary/demiadejuyigbe" path="/letterboxd/user/followingdiary/:username" :paramsDesc="['username']" />
## Line
## LINE
### Today
### TODAY
<Route author="nczitzk" example="/line/today" path="/line/today/:edition?/:tab?" :paramsDesc="['版本,见下表,默认为 Taiwan', '标签, 可在对应标签页的地址中找到, 默认为 top']">
<Route author="nczitzk" example="/line/today" path="/line/today/:edition?/:tab?" :paramsDesc="['版本,见下表,默认为 Taiwan', '标签, 可在对应标签页的地址中找到, 默认为 `top`']" radar="1">
Edition
@@ -830,6 +830,10 @@ Edition
</Route>
### TODAY - 频道
<Route author="TonyRL" example="/line/today/tw/publisher/101286" path="/line/today/:edition/publisher/:id" :paramsDesc="['版本,见上表', '频道 ID,可在 URL 中找到']" radar="1"/>
## LVV2
### 频道
+1
View File
@@ -1,3 +1,4 @@
module.exports = {
'/today/:edition?/:tab?': ['nczitzk'],
'/today/:edition/publisher/:id': ['TonyRL'],
};
+53
View File
@@ -0,0 +1,53 @@
const got = require('@/utils/got');
const { baseUrl, parseList, parseItems } = require('./utils');
module.exports = async (ctx) => {
const { edition, id } = ctx.params;
const { data: publisherInfo } = await got(`${baseUrl}/webapi/portal/page/setting`, {
searchParams: {
entityId: id,
country: edition,
pageType: 'CP',
},
});
let cpLatest;
if (edition === 'th') {
const { data } = await got(`${baseUrl}/webapi/portal/embedded/page/cplatest`, {
searchParams: {
entityId: id,
pageType: 'CP',
country: edition,
},
});
cpLatest = data;
}
const modules = edition !== 'th' ? publisherInfo.modules : cpLatest.modules;
const mod = modules.find((item) => item.source === 'CP_LATEST');
const listing = mod.listings[0];
const { data: listResponse } = await got(`${baseUrl}/webapi/trending/cp/latest/listings/${mod.id}`, {
searchParams: {
offset: listing.offset,
length: listing.length,
country: edition,
targetContent: listing.params.targetContent,
cps: listing.params.cps,
publishedWithin: listing.params.publishedWithin,
},
});
const list = parseList(listResponse.items);
const items = await parseItems(list, ctx.cache.tryGet);
ctx.state.data = {
title: `${publisherInfo.data.name} - Line Today`,
description: publisherInfo.data.introduction,
image: `https://obs.line-scdn.net/${publisherInfo.data.icon.hash}`,
link: `${baseUrl}/${edition}/v2/publisher/${id}`,
item: items,
};
};
+8 -2
View File
@@ -1,13 +1,19 @@
module.exports = {
'line.me': {
_name: 'LINE Today',
_name: 'LINE',
'.': [
{
title: 'LINE Today',
title: 'Today',
docs: 'https://docs.rsshub.app/new-media.html#line-today',
source: ['/'],
target: '/line/today/:edition?/:tab?',
},
{
title: 'Today - 频道',
docs: 'https://docs.rsshub.app/new-media.html#line-today',
source: ['/:edition/v2/publisher/:id'],
target: '/line/today/:edition/publisher/:id',
},
],
},
};
+1
View File
@@ -1,3 +1,4 @@
module.exports = function (router) {
router.get('/today/:edition?/:tab?', require('./today'));
router.get('/today/:edition/publisher/:id', require('./publisher'));
};
+3 -33
View File
@@ -1,12 +1,10 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const { baseUrl: rootUrl, parseList, parseItems } = require('./utils');
module.exports = async (ctx) => {
const edition = ctx.params.edition || 'tw';
const tab = ctx.params.tab || 'top';
const rootUrl = 'https://today.line.me';
const tabUrl = `${rootUrl}/webapi/portal/page/${tab}?country=${edition}`;
const recommendationUrl = `${rootUrl}/webapi/api/v6/recommendation/articles/listings/mytoday_rec:id?offset=0&length=50&country=${edition}&gender=&age=&excludeNoThumbnail=0&containMainSnapshot=0`;
const currentUrl = `${rootUrl}/${edition}/v2/tab/${tab}`;
@@ -34,37 +32,9 @@ module.exports = async (ctx) => {
url: tab === 'recommendation' ? recommendationUrl : moduleUrl,
});
const list = response.data.items.map((item) => ({
title: item.title,
link: `${rootUrl}/${edition}/v2/article/${item.url.hash}`,
pubDate: parseDate(item.publishTimeUnix),
hash: item.url.hash,
category: item.categoryName,
}));
const list = parseList(response.data.items);
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data } = await got({
method: 'get',
url: `${rootUrl}/webapi/portal/page/setting/article?country=${edition}&hash=${item.hash}&group=NA`,
});
const $ = cheerio.load(data.data.content, null, false);
$('img').each((_, img) => {
delete img.attribs['data-hashid'];
img.attribs.src = img.attribs.src.replace(/\/w\d+$/, '');
});
item.description = $.html();
item.author = data.data.author;
item.category = [...new Set([item.category, ...data.data.exploreLinks.map((link) => link.name)])];
return item;
})
)
);
const items = await parseItems(list, ctx.cache.tryGet);
ctx.state.data = {
title: `${title} - Line Today`,
+43
View File
@@ -0,0 +1,43 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const baseUrl = 'https://today.line.me';
const parseList = (items) =>
items.map((item) => ({
title: item.title,
link: item.url.url,
pubDate: parseDate(item.publishTimeUnix),
hash: item.url.hash,
category: item.categoryName,
}));
const parseItems = (list, tryGet) =>
Promise.all(
list.map((item) =>
tryGet(item.link, async () => {
const edition = item.link.match(/today\.line\.me\/(\w+?)\/v2\/.*$/)[1];
const { data } = await got(`${baseUrl}/webapi/portal/page/setting/article?country=${edition}&hash=${item.hash}&group=NA`);
const $ = cheerio.load(data.data.content, null, false);
$('img').each((_, img) => {
delete img.attribs['data-hashid'];
img.attribs.src = img.attribs.src.replace(/\/w\d+$/, '');
});
item.description = $.html();
item.author = data.data.author;
item.category = [...new Set([item.category, ...data.data.exploreLinks.map((link) => link.name)])];
return item;
})
)
);
module.exports = {
baseUrl,
parseList,
parseItems,
};