fix(route): sohu mp video (#13796)
This commit is contained in:
parent
affbabb937
commit
e18ee53bbc
|
|
@ -1,56 +1,69 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const { join } = require('path');
|
||||
const { art } = require('@/utils/render');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { id } = ctx.params;
|
||||
const authorArticleAPI = `https://v2.sohu.com/author-page-api/author-articles/pc/${id}`;
|
||||
|
||||
const response = await got.get(authorArticleAPI);
|
||||
const list = response.data.data.pcArticleVOS.splice(0, 10);
|
||||
const response = await got(authorArticleAPI);
|
||||
const list = response.data.data.pcArticleVOS.map((item) => ({
|
||||
title: item.title,
|
||||
link: item.link.startsWith('http') ? item.link : `https://${item.link}`,
|
||||
pubDate: parseDate(item.publicTime),
|
||||
}));
|
||||
let author, link;
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(async (e) => {
|
||||
if (e.link && !e.link.match(/^https?:\/\//)) {
|
||||
if (e.link.match(/^\/\//)) {
|
||||
e.link = 'http:' + e.link;
|
||||
} else {
|
||||
e.link = 'http://' + e.link;
|
||||
list.map((e) =>
|
||||
ctx.cache.tryGet(e.link, async () => {
|
||||
const { data: response } = await got(e.link);
|
||||
const $ = cheerio.load(response);
|
||||
|
||||
if (!author) {
|
||||
const meta = $('span[data-role="original-link"]');
|
||||
author = meta.find('a').text();
|
||||
// can't get author's link on server, so use the RSSHub link
|
||||
// link = meta.attr('href').split('==')[0];
|
||||
}
|
||||
}
|
||||
const response = await ctx.cache.tryGet(e.link, async () => (await got.get(e.link)).data);
|
||||
const $ = cheerio.load(response);
|
||||
|
||||
if (!author) {
|
||||
const meta = $('span[data-role="original-link"]');
|
||||
author = meta.find('a').text();
|
||||
// can't get author's link on server, so use the RSSHub link
|
||||
// link = meta.attr('href').split('==')[0];
|
||||
}
|
||||
if (
|
||||
$('script')
|
||||
.text()
|
||||
.match(/window\.sohu_mp\.article_video/)
|
||||
) {
|
||||
const videoSrc = $('script')
|
||||
.text()
|
||||
.match(/\s*url: "(.*?)",/)?.[1];
|
||||
e.description = art(join(__dirname, 'templates/video.art'), {
|
||||
poster: $('script')
|
||||
.text()
|
||||
.match(/cover: "(.*?)",/)?.[1],
|
||||
src: videoSrc,
|
||||
type: videoSrc?.split('.').pop().toLowerCase(),
|
||||
});
|
||||
} else {
|
||||
const article = $('#mp-editor');
|
||||
|
||||
const article = $('#mp-editor');
|
||||
article.find('#backsohucom, p[data-role="editor-name"]').each((i, e) => {
|
||||
$(e).remove();
|
||||
});
|
||||
|
||||
article.find('#backsohucom, p[data-role="editor-name"]').each((i, e) => {
|
||||
$(e).remove();
|
||||
});
|
||||
e.description = article.html();
|
||||
}
|
||||
|
||||
const single = {
|
||||
title: e.title,
|
||||
link: e.link,
|
||||
description: article.html(),
|
||||
pubDate: parseDate(e.publicTime),
|
||||
author,
|
||||
};
|
||||
e.author = author;
|
||||
|
||||
return single;
|
||||
})
|
||||
return e;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `搜狐号 - ${author}`,
|
||||
link,
|
||||
description: '',
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
<video controls
|
||||
{{ if poster }}
|
||||
poster="{{ poster }}"
|
||||
{{ /if }}
|
||||
>
|
||||
<source src="{{ src }}" type="video/{{ type }}"/>
|
||||
</video>
|
||||
Loading…
Reference in New Issue