diff --git a/docs/social-media.md b/docs/social-media.md index 7f50bcaade..51caf69251 100644 --- a/docs/social-media.md +++ b/docs/social-media.md @@ -634,7 +634,7 @@ pageClass: routes ### 博主 - + ### 关键词 diff --git a/lib/router.js b/lib/router.js index 2f4d84f6c2..fa8783a7b0 100644 --- a/lib/router.js +++ b/lib/router.js @@ -52,7 +52,7 @@ router.get('/bangumi/group/:id', require('./routes/bangumi/group/topic')); router.get('/bangumi/subject/:id', require('./routes/bangumi/subject')); // 微博 -router.get('/weibo/user/:uid', require('./routes/weibo/user')); +router.get('/weibo/user/:uid/:displayVideo?', require('./routes/weibo/user')); router.get('/weibo/keyword/:keyword', require('./routes/weibo/keyword')); router.get('/weibo/search/hot', require('./routes/weibo/search/hot')); router.get('/weibo/super_index/:id', require('./routes/weibo/super_index')); diff --git a/lib/routes/weibo/user.js b/lib/routes/weibo/user.js index acff92e4d6..12ca09a6cb 100644 --- a/lib/routes/weibo/user.js +++ b/lib/routes/weibo/user.js @@ -4,6 +4,7 @@ const date = require('@/utils/date'); module.exports = async (ctx) => { const uid = ctx.params.uid; + const displayVideo = ctx.params.displayVideo || '0'; const containerResponse = await got({ method: 'get', @@ -57,14 +58,21 @@ module.exports = async (ctx) => { item.mblog.retweeted_status.text = retweetData.text; } } - const description = weiboUtils.format(item.mblog); + + const link = `https://weibo.com/${uid}/${item.mblog.bid}`; + let description = weiboUtils.format(item.mblog); const title = description.replace(//g, '[图片]').replace(/<.*?>/g, ''); const pubDate = isDataOK ? new Date(data.created_at).toUTCString() : date(item.mblog.created_at, 8); + // 视频的处理 + if (displayVideo === '1') { + description = weiboUtils.formatVideo(description, item.mblog); + } + const it = { title: title, description: description, - link: `https://weibo.com/${uid}/${item.mblog.bid}`, + link: link, pubDate: pubDate, }; return Promise.resolve(it); diff --git a/lib/routes/weibo/utils.js b/lib/routes/weibo/utils.js index 985d685de3..080a58c76a 100644 --- a/lib/routes/weibo/utils.js +++ b/lib/routes/weibo/utils.js @@ -50,6 +50,20 @@ const weiboUtils = { }); resolve(itemResponse.data.data); }), + formatVideo: (itemDesc, status) => { + const pageInfo = status.page_info; + if (pageInfo && pageInfo.type === 'video') { + const pagePic = pageInfo.page_pic; + const mediaInfo = pageInfo.media_info; + const posterUrl = pagePic ? pagePic.url : ''; + const videoUrl = mediaInfo ? mediaInfo.stream_url_hd || mediaInfo.stream_url || mediaInfo.mp4_hd_url || mediaInfo.mp4_sd_url || mediaInfo.mp4_720p_mp4 : ''; + if (videoUrl) { + const video = `
`; + itemDesc += video; + } + } + return itemDesc; + }, }; module.exports = weiboUtils;