diff --git a/lib/routes/bilibili/danmaku.js b/lib/routes/bilibili/danmaku.js index 8d1f1fba4..25b323559 100644 --- a/lib/routes/bilibili/danmaku.js +++ b/lib/routes/bilibili/danmaku.js @@ -1,6 +1,7 @@ const cheerio = require('cheerio'); const cache = require('./cache'); -const fetch = require('node-fetch'); +const got = require('@/utils/got'); +const zlib = require('zlib'); module.exports = async (ctx) => { const aid = ctx.params.aid; @@ -10,8 +11,19 @@ module.exports = async (ctx) => { const videoName = await cache.getVideoNameFromAid(ctx, aid); - const danmakuResponse = await fetch(`https://comment.bilibili.com/${cid}.xml`); - const danmakuText = await danmakuResponse.text(); + const danmakuResponse = await got.get(`https://comment.bilibili.com/${cid}.xml`, { + decompress: false, + responseType: 'buffer', + }); + + let danmakuText = danmakuResponse.body; + + if ((danmakuText[0] & 0x0f) === 0x08) { + danmakuText = await zlib.inflateSync(danmakuText); + } else { + danmakuText = await zlib.inflateRawSync(danmakuText); + } + let danmakuList = []; const $ = cheerio.load(danmakuText, { xmlMode: true }); $('d').each((index, item) => { diff --git a/package.json b/package.json index 076363e6f..ca58bea38 100644 --- a/package.json +++ b/package.json @@ -78,7 +78,6 @@ "mailparser": "2.7.1", "markdown-it": "9.1.0", "module-alias": "2.2.1", - "node-fetch": "2.6.0", "path-to-regexp": "3.0.0", "pidusage": "2.0.17", "plist": "3.0.1", diff --git a/yarn.lock b/yarn.lock index b8e4fddab..f4c4231c7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7283,7 +7283,7 @@ node-abi@^2.7.0: dependencies: semver "^5.4.1" -node-fetch@2.6.0, node-fetch@^2.3.0: +node-fetch@^2.3.0: version "2.6.0" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd" integrity sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==