feat(route): add 抖音 (#9604)

* feat(route): add 抖音

* Update lib/v2/douyin/user.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/v2/douyin/user.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* fix substring and add config require

Co-authored-by: Tony <TonyRL@users.noreply.github.com>
This commit is contained in:
Max-Tortoise
2022-04-24 17:14:27 +11:00
committed by GitHub
co-authored by Tony
parent c7aa447100
commit c9bb12fc34
5 changed files with 84 additions and 0 deletions
+6
View File
@@ -840,6 +840,12 @@ YouTube 官方亦有提供频道 RSS,形如 <https://www.youtube.com/feeds/vid
<Route author="brilon" example="/dianping/user/35185271" path="/dianping/user/:id" :paramsDesc="['用户id,可在 URL 中找到']"/>
## 抖音
### 博主
<Route author="Max-Tortoise" example="/douyin/user/MS4wLjABAAAARcAHmmF9mAG3JEixq_CdP72APhBlGlLVbN-1eBcPqao" path="/douyin/user/:uid" :paramsDesc="['用户的uid']"/>
## 豆瓣
### 正在上映的电影
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
'/user/:uid': ['Max-Tortoise'],
};
+13
View File
@@ -0,0 +1,13 @@
module.exports = {
'douyin.com': {
_name: '抖音',
'.': [
{
title: '博主',
docs: 'https://docs.rsshub.app/social-media.html#dou-yin',
source: '/user/:uid',
target: '/douyin/user/:uid',
},
],
},
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/user/:uid', require('./user'));
};
+59
View File
@@ -0,0 +1,59 @@
const cheerio = require('cheerio');
const config = require('@/config').value;
module.exports = async (ctx) => {
// 获取 uid
const { uid } = ctx.params;
const url = 'https://www.douyin.com/user/' + uid;
// 访问 url
const response = await ctx.cache.tryGet(
url,
async () => {
const browser = await require('@/utils/puppeteer')();
const page = await browser.newPage();
await page.goto(url);
const html = await page.evaluate(() => document.documentElement.innerHTML);
browser.close();
return html;
},
config.cache.routeExpire,
false
);
// 解析 html
const $ = cheerio.load(response);
// 博主名称
const spanlist = $('h1.OKOabD2C > span');
const author = $(spanlist[spanlist.length - 1]).text();
// 作品列表
const list = $('li.ECMy_Zdt');
ctx.state.data = {
title: author,
link: url,
item:
list &&
list
.filter((index, item) => $('img', item)[0])
.map((index, item) => {
// 封面图片
const videoThumb = 'https:' + $('img', item)[0].attribs.src;
// 视频链接
const videoUrl = 'https:' + $('a', item)[0].attribs.href;
// 视频标题
let videoName = $('img', item)[0].attribs.alt;
videoName = videoName.substring(videoName.search(':') + 1);
return {
title: videoName,
description: `<img src="${videoThumb}">`,
link: videoUrl,
author,
};
})
.get(),
};
};