From b55cb252872b1ad718d9de661986d3f5bdb0d413 Mon Sep 17 00:00:00 2001 From: Andvari <31068367+dzx-dzx@users.noreply.github.com> Date: Sat, 27 Apr 2024 20:18:29 +0800 Subject: [PATCH 1/7] fix(route/sjtu/yzb): Correct title and date. (#15387) --- lib/routes/sjtu/yzb/zkxx.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/routes/sjtu/yzb/zkxx.ts b/lib/routes/sjtu/yzb/zkxx.ts index a90cbb62904a02..69ee5f8f943e30 100644 --- a/lib/routes/sjtu/yzb/zkxx.ts +++ b/lib/routes/sjtu/yzb/zkxx.ts @@ -47,8 +47,8 @@ async function handler(ctx) { .toArray() .map((elem) => ({ link: new URL(elem.attribs.href, pageUrl).href, - title: elem.attribs.title, - pubDate: parseDate($(elem.next).text().trim()), + title: $(elem).text(), + pubDate: parseDate($(elem.next?.next).text().trim()), })), }; } From 43c041ef11e0e91f437ca2bc3a8ff1e9b7e0dc63 Mon Sep 17 00:00:00 2001 From: CaoMeiYouRen <40430746+CaoMeiYouRen@users.noreply.github.com> Date: Sat, 27 Apr 2024 21:36:40 +0800 Subject: [PATCH 2/7] =?UTF-8?q?fix(route):=20=E4=BF=AE=E5=A4=8D=20hellogit?= =?UTF-8?q?hub=20=E8=B7=AF=E7=94=B1=E9=94=99=E8=AF=AF=20(#15388)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(route): 修复 全国气象预警 为空的问题 * fix(route): 修复 hellogithub 路由错误 * fix(route): 优化 HelloGitHub title * fix(route): 修复 hellogithub 路由 * fix: revert changes on readable-social --------- --- lib/routes/hellogithub/index.ts | 4 +- lib/routes/hellogithub/report.ts | 3 +- lib/routes/hellogithub/volume.ts | 63 ++++++++++++++++++++------------ 3 files changed, 43 insertions(+), 27 deletions(-) diff --git a/lib/routes/hellogithub/index.ts b/lib/routes/hellogithub/index.ts index 7050f35d50fbec..c5093e5e3524fe 100644 --- a/lib/routes/hellogithub/index.ts +++ b/lib/routes/hellogithub/index.ts @@ -15,7 +15,7 @@ const sorts = { }; export const route: Route = { - path: ['/article/:sort?/:id?', '/:sort?/:id?'], + path: ['/article/:sort?/:id?'], categories: ['programming'], example: '/hellogithub/article', parameters: { sort: '排序方式,见下表,默认为 `hot`,即热门', id: '标签 id,可在对应标签页 URL 中找到,默认为全部标签' }, @@ -61,7 +61,7 @@ async function handler(ctx) { const $ = load(tagResponse.data); - tag = $('meta[property="og:title"]').attr('content').split(' ').pop(); + tag = $('meta[property="og:title"]')?.attr('content')?.split(' ').pop(); buildId = tagResponse.data.match(/"buildId":"(.*?)",/)[1]; } diff --git a/lib/routes/hellogithub/report.ts b/lib/routes/hellogithub/report.ts index 9b9e77ccdea5ec..734e98e3b8bdc9 100644 --- a/lib/routes/hellogithub/report.ts +++ b/lib/routes/hellogithub/report.ts @@ -15,7 +15,8 @@ const types = { export const route: Route = { path: ['/ranking/:type?', '/report/:type?'], - name: 'Unknown', + example: '/hellogithub/ranking', + name: '榜单报告', maintainers: ['moke8', 'nczitzk'], handler, description: `| 编程语言 | 服务器 | 数据库 | diff --git a/lib/routes/hellogithub/volume.ts b/lib/routes/hellogithub/volume.ts index 8f675c7f622375..34bd20a219b2b0 100644 --- a/lib/routes/hellogithub/volume.ts +++ b/lib/routes/hellogithub/volume.ts @@ -10,6 +10,8 @@ const md = MarkdownIt({ html: true, }); import { load } from 'cheerio'; +import cache from '@/utils/cache'; +import { config } from '@/config'; art.defaults.imports.render = function (string) { return md.render(string); @@ -17,12 +19,14 @@ art.defaults.imports.render = function (string) { export const route: Route = { path: ['/month', '/volume'], - name: 'Unknown', - maintainers: ['moke8', 'nczitzk'], + example: '/hellogithub/volume', + name: '月刊', + maintainers: ['moke8', 'nczitzk', 'CaoMeiYouRen'], handler, }; -async function handler() { +async function handler(ctx) { + const limit: number = Number.parseInt(ctx.req.query('limit')) || 10; const rootUrl = 'https://hellogithub.com'; const apiUrl = 'https://api.hellogithub.com/v1/periodical/'; @@ -30,33 +34,44 @@ async function handler() { method: 'get', url: apiUrl, }); - const current = periodicalResponse.data.volumes[0].num; - const currentUrl = `${rootUrl}/periodical/volume/${current}`; - const buildResponse = await got({ - method: 'get', - url: currentUrl, - }); + const volumes = periodicalResponse.data.volumes.slice(0, limit); - const $ = load(buildResponse.data); + const items = await Promise.all( + volumes.map(async (volume) => { + const current = volume.num; + const currentUrl = `${rootUrl}/periodical/volume/${current}`; + const key = `hellogithub:${currentUrl}`; + return await cache.tryGet( + key, + async () => { + const buildResponse = await got({ + method: 'get', + url: currentUrl, + }); - const text = $('#__NEXT_DATA__').text(); - const response = JSON.parse(text); - const data = response.props; - const id = data.pageProps.volume.current_num; + const $ = load(buildResponse.data); - const items = [ - { - title: `No.${id}`, - link: `${rootUrl}/periodical/volume/${id}`, - description: art(path.join(__dirname, 'templates/volume.art'), { - data: data.pageProps.volume.data, - }), - }, - ]; + const text = $('#__NEXT_DATA__').text(); + const response = JSON.parse(text); + const data = response.props; + const id = data.pageProps.volume.current_num; + return { + title: `《HelloGitHub》第 ${id} 期`, + link: `${rootUrl}/periodical/volume/${id}`, + description: art(path.join(__dirname, 'templates/volume.art'), { + data: data.pageProps.volume.data, + }), + }; + }, + config.cache.routeExpire, + false + ); + }) + ); return { title: 'HelloGithub - 月刊', - link: currentUrl, + link: 'https://hellogithub.com/periodical', item: items, }; } From 1c6981297e9b1e723f510d69d9ce091a4262049f Mon Sep 17 00:00:00 2001 From: Tony Date: Sun, 28 Apr 2024 05:55:46 +0800 Subject: [PATCH 3/7] fix(route): sohu mp (#15390) * fix(route): sohu mp * fix: remove unwanted element --- lib/routes/sohu/mp.ts | 246 +++++++++++++++++++++++++++++++----------- 1 file changed, 183 insertions(+), 63 deletions(-) diff --git a/lib/routes/sohu/mp.ts b/lib/routes/sohu/mp.ts index 8a6ca2f05c6123..b822b5f7f6eff3 100644 --- a/lib/routes/sohu/mp.ts +++ b/lib/routes/sohu/mp.ts @@ -3,88 +3,208 @@ import { getCurrentPath } from '@/utils/helpers'; const __dirname = getCurrentPath(import.meta.url); import cache from '@/utils/cache'; -import got from '@/utils/got'; -import { load } from 'cheerio'; +import ofetch from '@/utils/ofetch'; +import * as cheerio from 'cheerio'; import { parseDate } from '@/utils/parse-date'; import path from 'node:path'; import { art } from '@/utils/render'; export const route: Route = { - path: '/mp/:id', + path: '/mp/:xpt', categories: ['new-media'], - example: '/sohu/mp/119097', - parameters: { id: '搜狐号 ID' }, - features: { - requireConfig: false, - requirePuppeteer: false, - antiCrawler: false, - supportBT: false, - supportPodcast: false, - supportScihub: false, - }, - name: '更新', + example: '/sohu/mp/c29odXptdGhnbjZ3NEBzb2h1LmNvbQ==', + parameters: { xpt: '搜狐号 xpt ,可在URL中找到或搜狐号 ID' }, + radar: [ + { + source: ['mp.sohu.com/profile'], + target: (_params, url) => `/sohu/mp/${new URL(url).searchParams.get('xpt')}`, + }, + ], + name: '最新', maintainers: ['HenryQW'], handler, - description: `1. 通过浏览器搜索相关搜狐号 \`果壳 site: mp.sohu.com\`。 - 2. 通过浏览器控制台执行 \`contentData.mkey\`,返回的即为搜狐号 ID。`, + description: `搜狐号 ID 可以通过以下方式获取: + 1. 通过浏览器搜索相关搜狐号 \`果壳 site: mp.sohu.com\`。 + 2. 通过浏览器控制台执行 \`window.globalConst.mkeyConst_mkey\`,返回的即为搜狐号 ID。`, }; +function randomString(length = 32) { + let r = ''; + const e = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'; + const n = e.length; + for (let i = 0; i < length; i++) { + r += e.charAt(Math.floor(Math.random() * n)); + } + return r; +} +const defaultSUV = '1612268936507kas0gk'; + +function fetchArticle(item) { + return cache.tryGet(item.link, async () => { + const response = await ofetch(item.link); + const $ = cheerio.load(response); + + $('.original-title, .lookall-box').remove(); + item.author = item.author || $('span[data-role="original-link"] a').text(); + + if (/window\.sohu_mp\.article_video/.test($('script').text())) { + const videoSrc = $('script') + .text() + .match(/\s*url: "(.*?)",/)?.[1]; + item.description = art(path.join(__dirname, 'templates/video.art'), { + poster: $('script') + .text() + .match(/cover: "(.*?)",/)?.[1], + src: videoSrc, + type: videoSrc?.split('.').pop()?.toLowerCase(), + }); + } else { + const article = $('#mp-editor'); + + article.find('#backsohucom, p[data-role="editor-name"]').each((i, e) => { + $(e).remove(); + }); + + item.description = article.html(); + } + + return item; + }); +} + async function handler(ctx) { - const id = ctx.req.param('id'); + const xpt = ctx.req.param('xpt'); + const isPureNumber = /^\d+$/.test(xpt); + if (isPureNumber) { + return legacyIdHandler(ctx); + } + + const pageResponse = await ofetch.raw('https://mp.sohu.com/profile', { + query: { + xpt, + }, + }); + const suv = pageResponse.headers + ?.getSetCookie() + .find((e) => e.startsWith('SUV')) + ?.split(';')[0]; + const $ = cheerio.load(pageResponse._data); + + const CBDRenderConst = JSON.parse( + $('script:contains("CBDRenderConst")') + .text() + .trim() + .match(/CBDRenderConst\s=\s(.*)/)?.[1] || '{}' + ); + const contentData = JSON.parse( + $('script:contains("contentData")') + .toArray() + .map( + (e) => + $(e) + .text() + .match(/contentData = (.*)/)?.[1] + ) + .sort((a: any, b: any) => b.length - a.length)[0] || '{}' + ); + const renderData = JSON.parse( + $('script:contains("column_2_text")') + .text() + .match(/renderData:\s(.*)/)?.[1] || '{}' + ); + const globalConst = JSON.parse( + $('script:contains("globalConst")') + .text() + .match(/globalConst\s=\s(.*)/)?.[1] || '{}' + ); + const originalRequest = JSON.parse( + $('script:contains("originalRequest")') + .text() + .match(/originalRequest\s=\s(.*)/)?.[1] || '{}' + ); + + const blockData = await ofetch('https://odin.sohu.com/odin/api/blockdata', { + method: 'POST', + headers: { + Cookie: Object.entries({ + SUV: suv, + itssohu: 'true', + reqtype: 'pc', + t: Date.now(), + }) + .map(([key, value]) => `${key}=${value}`) + .join('; '), + }, + body: { + pvId: CBDRenderConst.COMMONCONFIG.pvId || `${Date.now()}_${randomString(7)}`, + pageId: `${Date.now()}_${defaultSUV.slice(0, -5)}_${randomString(3)}`, + mainContent: { + productType: contentData.businessType || '13', + productId: contentData.id || '324', + secureScore: contentData.secureScore || '5', + categoryId: contentData.categoryId || '47', + adTags: contentData.adTags || '11111111', + authorId: contentData.account.id || 121_135_924, + }, + resourceList: [ + { + tplCompKey: renderData.param.data2.reqParam.tplCompKey || 'FeedSlideloadAuthor_2_0_pc_1655965929143_data2', + isServerRender: renderData.param.data2.reqParam.isServerRender || false, + isSingleAd: renderData.param.data2.reqParam.isSingleAd || false, + configSource: renderData.param.data2.reqParam.configSource || 'mp', + content: { + productId: renderData.param.data2.reqParam.content.productId || '325', + productType: renderData.param.data2.reqParam.content.productType || '13', + size: 20, + pro: renderData.param.pro || '0,1,3,4,5', + feedType: renderData.param.feedType || 'XTOPIC_SYNTHETICAL', + view: '', + innerTag: renderData.param.data2.reqParam.content.innerTag || 'work', + spm: renderData.param.data2.reqParam.content.spm || 'smpc.channel_248.block3_308_hHsK47_2_fd', + page: 1, + requestId: `${Date.now()}_${randomString(13)}_${contentData.id}`, + }, + adInfo: {}, + context: { + mkey: globalConst.mkeyConst_mkey, // legacy ID + }, + }, + ], + }, + }); + + const list = blockData.data[renderData.param.data2.reqParam.tplCompKey].list.map((item) => ({ + title: item.title, + description: item.brief, + link: `https://www.sohu.com/a/${item.id}_${item.authorId}`, + author: item.authorName, + pubDate: parseDate(item.postTime, 'x'), + })); + + const items = await Promise.all(list.map((e) => fetchArticle(e))); + + return { + title: `搜狐号 - ${globalConst.title}`, + link: originalRequest.url, + item: items, + }; +} + +async function legacyIdHandler(ctx) { + const id = ctx.req.param('xpt'); const authorArticleAPI = `https://v2.sohu.com/author-page-api/author-articles/pc/${id}`; - const response = await got(authorArticleAPI); - const list = response.data.data.pcArticleVOS.map((item) => ({ + const response = await ofetch(authorArticleAPI); + const list = response.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((e) => - cache.tryGet(e.link, async () => { - const { data: response } = await got(e.link); - const $ = 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 (/window\.sohu_mp\.article_video/.test($('script').text())) { - const videoSrc = $('script') - .text() - .match(/\s*url: "(.*?)",/)?.[1]; - e.description = art(path.join(__dirname, 'templates/video.art'), { - poster: $('script') - .text() - .match(/cover: "(.*?)",/)?.[1], - src: videoSrc, - type: videoSrc?.split('.').pop().toLowerCase(), - }); - } else { - const article = $('#mp-editor'); - - article.find('#backsohucom, p[data-role="editor-name"]').each((i, e) => { - $(e).remove(); - }); - - e.description = article.html(); - } - - e.author = author; - - return e; - }) - ) - ); + + const items = await Promise.all(list.map((e) => fetchArticle(e))); return { - title: `搜狐号 - ${author}`, - link, + title: `搜狐号 - ${id}`, item: items, }; } From b566ebbe3a5d2ada3b2d7710b64d6de4d943d976 Mon Sep 17 00:00:00 2001 From: karasu Date: Sun, 28 Apr 2024 17:27:18 +0800 Subject: [PATCH 4/7] fix(route): weibo (#15398) --- lib/routes/weibo/keyword.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/routes/weibo/keyword.ts b/lib/routes/weibo/keyword.ts index b56e926c221731..df8b1b2cd27bab 100644 --- a/lib/routes/weibo/keyword.ts +++ b/lib/routes/weibo/keyword.ts @@ -53,15 +53,17 @@ async function handler(ctx) { title: `又有人在微博提到${keyword}了`, link: `http://s.weibo.com/weibo/${encodeURIComponent(keyword)}&b=1&nodup=1`, description: `又有人在微博提到${keyword}了`, - item: data.map((item) => { - item.mblog.created_at = timezone(item.mblog.created_at, +8); - if (item.mblog.retweeted_status && item.mblog.retweeted_status.created_at) { - item.mblog.retweeted_status.created_at = timezone(item.mblog.retweeted_status.created_at, +8); - } - return weiboUtils.formatExtended(ctx, item.mblog, undefined, { - showAuthorInTitle: fallback(undefined, queryToBoolean(routeParams.showAuthorInTitle), true), - showAuthorInDesc: fallback(undefined, queryToBoolean(routeParams.showAuthorInDesc), true), - }); - }), + item: data + .filter((i) => i.mblog) + .map((item) => { + item.mblog.created_at = timezone(item.mblog.created_at, +8); + if (item.mblog.retweeted_status && item.mblog.retweeted_status.created_at) { + item.mblog.retweeted_status.created_at = timezone(item.mblog.retweeted_status.created_at, +8); + } + return weiboUtils.formatExtended(ctx, item.mblog, undefined, { + showAuthorInTitle: fallback(undefined, queryToBoolean(routeParams.showAuthorInTitle), true), + showAuthorInDesc: fallback(undefined, queryToBoolean(routeParams.showAuthorInDesc), true), + }); + }), }); } From d4a88c731a155f2eaa690be7b8dd7e1cd1c07ee7 Mon Sep 17 00:00:00 2001 From: flameleaf <18636550+flameleaf@users.noreply.github.com> Date: Sun, 28 Apr 2024 16:57:33 -0700 Subject: [PATCH 5/7] feat(route): Add Chub (#15298) * Create characters.ts * Create namespace.ts * Update characters.ts * remove uncessary ctx * Update lib/routes/chub/characters.ts Co-authored-by: Tony * Update lib/routes/chub/characters.ts Co-authored-by: Tony * Update lib/routes/chub/characters.ts Co-authored-by: Tony * Update lib/routes/chub/characters.ts Co-authored-by: Tony * Moved topics to category field * replaced got with ofetch + query * Update characters.ts * Update lib/routes/chub/characters.ts Co-authored-by: Tony --------- --- lib/routes/chub/characters.ts | 68 +++++++++++++++++++++++++++++++++++ lib/routes/chub/namespace.ts | 6 ++++ 2 files changed, 74 insertions(+) create mode 100644 lib/routes/chub/characters.ts create mode 100644 lib/routes/chub/namespace.ts diff --git a/lib/routes/chub/characters.ts b/lib/routes/chub/characters.ts new file mode 100644 index 00000000000000..bf9732eff706fb --- /dev/null +++ b/lib/routes/chub/characters.ts @@ -0,0 +1,68 @@ +import { Route } from '@/types'; +import ofetch from '@/utils/ofetch'; +import { parseDate } from '@/utils/parse-date'; + +export const route: Route = { + path: '/characters', + categories: ['new-media'], + example: '/chub/characters', + name: 'Characters', + maintainers: ['flameleaf'], + handler, +}; + + +async function handler() { + const hostURL = 'https://www.chub.ai/characters'; + const apiURL = 'https://api.chub.ai/api/characters/search'; + const data = await ofetch(apiURL, { + headers: { Accept: 'application/json' }, + query: { + query: '', + first: 200, + page: 1, + sort: 'last_activity_at', + asc: 'false', + include_forks: 'false', + nsfw: 'true', + nsfl: 'true', + nsfw_only: 'false', + require_images: 'false', + require_example_dialogues: 'false', + require_alternate_greetings: 'false', + require_custom_prompt: 'false', + exclude_mine: 'false', + venus: 'true', + chub: 'true', + min_tokens: 50, + require_expressions: 'false', + require_lore: 'false', + mine_first: 'false', + require_lore_embedded: 'false', + require_lore_linked: 'false', + inclusive_or: 'false', + recommended_verified: 'false', + }, + }); + const nodes = data.nodes; + + return { + allowEmpty: true, + title: 'Chub', + link: hostURL, + item: nodes + .map((item) => ({ + title: item.name, + description: `${item.tagline}

${item.description}`, + pubDate: parseDate(item.createdAt), + updated: parseDate(item.lastActivityAt), + link: `${hostURL}/${item.fullPath}`, + author: String(item.fullPath.split('/', 1)), + enclosure_url: item.avatar_url, + enclosure_type: `image/webp`, + category: item.topics, + })), + }; +} + + diff --git a/lib/routes/chub/namespace.ts b/lib/routes/chub/namespace.ts new file mode 100644 index 00000000000000..c9d38725fd3095 --- /dev/null +++ b/lib/routes/chub/namespace.ts @@ -0,0 +1,6 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'Chub', + url: 'chub.ai', +}; From cc044ac53380f8c7ba210398577319d86307561a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 28 Apr 2024 23:59:06 +0000 Subject: [PATCH 6/7] style: auto format --- lib/routes/chub/characters.ts | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/lib/routes/chub/characters.ts b/lib/routes/chub/characters.ts index bf9732eff706fb..0f34350658848c 100644 --- a/lib/routes/chub/characters.ts +++ b/lib/routes/chub/characters.ts @@ -11,7 +11,6 @@ export const route: Route = { handler, }; - async function handler() { const hostURL = 'https://www.chub.ai/characters'; const apiURL = 'https://api.chub.ai/api/characters/search'; @@ -50,19 +49,16 @@ async function handler() { allowEmpty: true, title: 'Chub', link: hostURL, - item: nodes - .map((item) => ({ - title: item.name, - description: `${item.tagline}

${item.description}`, - pubDate: parseDate(item.createdAt), - updated: parseDate(item.lastActivityAt), - link: `${hostURL}/${item.fullPath}`, - author: String(item.fullPath.split('/', 1)), - enclosure_url: item.avatar_url, - enclosure_type: `image/webp`, - category: item.topics, - })), + item: nodes.map((item) => ({ + title: item.name, + description: `${item.tagline}

${item.description}`, + pubDate: parseDate(item.createdAt), + updated: parseDate(item.lastActivityAt), + link: `${hostURL}/${item.fullPath}`, + author: String(item.fullPath.split('/', 1)), + enclosure_url: item.avatar_url, + enclosure_type: `image/webp`, + category: item.topics, + })), }; } - - From e54a5f1083d91783d2c34cdd42e55cc48f5de70c Mon Sep 17 00:00:00 2001 From: tong chao Date: Mon, 29 Apr 2024 21:44:09 +0800 Subject: [PATCH 7/7] feat(route): douyu room api update with fallback (#15401) * feat(route): douyu room api update with fallback * style: auto format --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- lib/routes/douyu/room.ts | 76 ++++++++++++++++++++++++++++++---------- 1 file changed, 58 insertions(+), 18 deletions(-) diff --git a/lib/routes/douyu/room.ts b/lib/routes/douyu/room.ts index 7cad249a74a7e6..bd0a36c6cd9d3c 100644 --- a/lib/routes/douyu/room.ts +++ b/lib/routes/douyu/room.ts @@ -20,37 +20,77 @@ export const route: Route = { }, ], name: '直播间开播', - maintainers: ['DIYgod'], + maintainers: ['DIYgod', 'ChaosTong'], handler, }; async function handler(ctx) { const id = ctx.req.param('id'); - const response = await got({ - method: 'get', - url: `http://open.douyucdn.cn/api/RoomApi/room/${id}`, - headers: { - Referer: `https://www.douyu.com/${id}`, - }, - }); + let data; + let item; + let room_thumb; + try { + const response = await got({ + method: 'get', + url: `https://www.douyu.com/betard/${id}`, + }); - const data = response.data.data; + if (!response.data.room) { + throw new Error('Invalid response'); + } - let item; - if (data.online !== 0) { - item = [ - { - title: `开播: ${data.room_name}`, - pubDate: new Date(data.start_time).toUTCString(), - guid: data.start_time, - link: `https://www.douyu.com/${id}`, + data = response.data.room; + room_thumb = data.room_pic; + + if (data.show_status === 1) { + item = + data.videoLoop === 1 + ? [ + { + title: `视频轮播: ${data.room_name}`, + pubDate: new Date(data.show_time * 1000).toUTCString(), + guid: data.show_time, + link: `https://www.douyu.com/${id}`, + }, + ] + : [ + { + title: `开播: ${data.room_name}`, + pubDate: new Date(data.show_time * 1000).toUTCString(), + guid: data.show_time, + link: `https://www.douyu.com/${id}`, + }, + ]; + } + // make a fallback to the old api + } catch { + const response = await got({ + method: 'get', + url: `http://open.douyucdn.cn/api/RoomApi/room/${id}`, + headers: { + Referer: `https://www.douyu.com/${id}`, }, - ]; + }); + + data = response.data.data; + room_thumb = data.room_thumb; + + if (data.online !== 0) { + item = [ + { + title: `开播: ${data.room_name}`, + pubDate: new Date(data.start_time).toUTCString(), + guid: data.start_time, + link: `https://www.douyu.com/${id}`, + }, + ]; + } } return { title: `${data.owner_name}的斗鱼直播间`, + image: room_thumb, link: `https://www.douyu.com/${id}`, item, allowEmpty: true,