From 7903abf6c33742852e7ef0c18d334f80e1678b4d Mon Sep 17 00:00:00 2001 From: HCLonely Date: Fri, 5 Jul 2024 16:08:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E8=8E=B7=E5=8F=96ba?= =?UTF-8?q?ngumi=E7=94=A8=E6=88=B7=E7=9A=84=E6=B8=B8=E6=88=8F=E5=88=97?= =?UTF-8?q?=E8=A1=A8(=E4=BB=85=E6=94=AF=E6=8C=81`source:=20bgmv0`)(#391);?= =?UTF-8?q?=20=E6=96=B0=E5=A2=9E=EF=BC=9A=E8=BF=BD=E7=95=AA=E8=BF=9B?= =?UTF-8?q?=E5=BA=A6=E6=9D=A1(=E4=BB=85=E6=94=AF=E6=8C=81`source:=20bgmv0`?= =?UTF-8?q?=E6=88=96`source:=20bili`,=20=E4=BD=BF=E7=94=A8bili=E6=BA=90?= =?UTF-8?q?=E6=97=B6=E9=9C=80=E6=8F=90=E4=BE=9Bcookie,=20=E5=85=B7?= =?UTF-8?q?=E4=BD=93=E7=9C=8B=E8=AF=B4=E6=98=8E=E6=96=87=E6=A1=A3)(#454);?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=EF=BC=9Ai18n.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 36 +++- index.js | 78 ++++++++- lib/bangumi-generator.js | 2 +- lib/get-bgm-data.js | 53 +++--- lib/get-bgmv0-data.js | 273 +++++++++++++++++++++++++++++++ lib/get-bili-data.js | 35 ++-- lib/templates/bangumi.ejs | 19 +-- lib/templates/bgm-template.ejs | 24 +-- lib/templates/bgmv0-template.ejs | 47 ++++++ lib/templates/bili-template.ejs | 25 ++- lib/templates/index.css | 2 +- lib/util.js | 68 +++++++- package.json | 4 +- src/index.js | 61 ++++++- src/lib/bangumi-generator.js | 2 +- src/lib/get-bgm-data.js | 38 +++-- src/lib/get-bgmv0-data.js | 139 ++++++++++++++++ src/lib/get-bili-data.js | 25 ++- src/lib/templates/index.css | 27 +++ src/lib/util.js | 68 +++++++- 20 files changed, 906 insertions(+), 120 deletions(-) create mode 100644 lib/get-bgmv0-data.js create mode 100644 lib/templates/bgmv0-template.ejs create mode 100644 src/lib/get-bgmv0-data.js diff --git a/README.md b/README.md index fd47884..2388ba8 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ $ npm install hexo-bilibili-bangumi --save bangumi: # 追番设置 enable: true source: bili - bgmInfoSource: 'bgmApi' + bgmInfoSource: 'bgmv0' path: vmid: title: '追番列表' @@ -68,16 +68,37 @@ cinema: # 追剧设置 extra_options: key: value coverMirror: +game: # 游戏设置,仅支持source: bgmv0 + enable: true + path: + source: bgmv0 + vmid: + title: '游戏列表' + quote: '生命不息,游戏不止!' + show: 1 + lazyload: true + srcValue: '__image__' + lazyloadAttrName: 'data-src=__image__' + loading: + metaColor: + color: + webp: + progress: + extraOrder: + order: + extra_options: + key: value + coverMirror: ``` > 带*为必填选项! - **enable**: 是否启用 -- **source**: 数据源,仅支持追番,追剧仅支持哔哩哔哩源。`bili`: [哔哩哔哩源](https://www.bilibili.com/), `bangumi`: [Bangumi源(bangumi.tv)](https://bangumi.tv/), `bgm`: [Bangumi源(bgm.tv)](https://bgm.tv/) +- **source**: 数据源,仅支持追番,追剧仅支持哔哩哔哩源。`bili`: [哔哩哔哩源](https://www.bilibili.com/), `bgmv0`: **建议**[Bgm Api源(api.bgm.tv)](https://bgm.tv/), `bangumi`: [Bangumi源(bangumi.tv)](https://bangumi.tv/), `bgm`: [Bangumi源(bgm.tv)](https://bgm.tv/) - **bgmInfoApi**: 获取Bangumi番剧信息时使用的Api,仅使用Bangumi源时此选项生效。`bgmApi`: [Bangumi Api](https://github.com/bangumi/api/), `bgmSub`: [Bangumi-Subject](https://github.com/czy0729/Bangumi-Subject) - **proxy**: 代理设置,仅在使用支持`bgm`源追番时生效。默认`false` - **path**: 页面路径,默认`bangumis/index.html`, `cinemas/index.html` -- **vmid**: 哔哩哔哩的 `vmid(uid)`[如何获取?](#获取-bilibili-uid)或Bangumi的用户`id`[如何获取?](#获取-bangumi-id) +- **vmid**: 哔哩哔哩的 `vmid(uid)`[如何获取?](#获取-bilibili-uid)/Bangumi的用户`用户名`(source为`bgmv0`时使用)[如何获取?](#获取-bangumi-用户名)/Bangumi的用户`id`(source为`bgm`或`bangumi`时使用)[如何获取?](#获取-bangumi-id) - **title**: 该页面的标题 - **quote**: 写在页面开头的一段话,支持 html 语法,可留空。 - **show**: 初始显示页面:`0: 想看`, `1: 在看`, `2: 看过`,默认为`1` @@ -108,7 +129,12 @@ cinema: # 追剧设置 ## 使用 +> 仅`bili`和`bgmv0`源支持在追番页面显示追番进度。 + 1. 在`hexo generate`或`hexo deploy`之前使用`hexo bangumi -u`命令更新追番数据,使用`hexo cinema -u`命令更新追剧数据! + + - 使用bili源时,如果要在追番页面显示追番进度,需使用`hexo bangumi -u 'SESSDATA'`, `SESSDATA`替换为哔哩哔哩cookie中的`SESSDATA`值。例`hexo bangumi -u 'df***EC'` + 2. 删除数据命令:`hexo bangumi -d`/`hexo cinema -d` ## 获取 Bilibili uid @@ -117,6 +143,10 @@ cinema: # 追剧设置 ***需要将追番列表设置为公开!*** +## 获取 Bangumi 用户名 + +登录[Bangumi](https://bangumi.tv/)后打开控制台(`Ctrl`+`Shift`+`J`),输入`document.getElementById('header').getElementsByTagName('a')[0].getAttribute('href').split('/').at(-1)`回车,下面会输出`用户名` + ## 获取 Bangumi id 登录[Bangumi](https://bangumi.tv/)后打开控制台(`Ctrl`+`Shift`+`J`),输入`CHOBITS_UID`回车,下面会输出`id` diff --git a/index.js b/index.js index 897f605..274535b 100644 --- a/index.js +++ b/index.js @@ -15,10 +15,12 @@ var _require = require('./lib/get-bili-data'), getBiliData = _require.getBiliData; var _require2 = require('./lib/get-bgm-data'), getBgmData = _require2.getBgmData; +var _require3 = require('./lib/get-bgmv0-data'), + getBgmv0Data = _require3.getBgmv0Data; // eslint-disable-next-line no-var -if (typeof URL !== 'function') var _require3 = require('url'), - URL = _require3.URL; +if (typeof URL !== 'function') var _require4 = require('url'), + URL = _require4.URL; var options = { options: [{ name: '-u, --update', @@ -42,6 +44,13 @@ hexo.extend.generator.register('cinemas', function (locals) { } return require('./lib/bangumi-generator').call(this, locals, 'cinema'); }); +hexo.extend.generator.register('games', function (locals) { + var _this$config3; + if (!(this !== null && this !== void 0 && (_this$config3 = this.config) !== null && _this$config3 !== void 0 && (_this$config3 = _this$config3.game) !== null && _this$config3 !== void 0 && _this$config3.enable)) { + return; + } + return require('./lib/bangumi-generator').call(this, locals, 'game'); +}); hexo.extend.console.register('bangumi', 'Generate pages of bangumis for Hexo', options, function (args) { if (args.d) { if (fs.existsSync(path.join(this.source_dir, '/_data/bangumis.json'))) { @@ -49,8 +58,8 @@ hexo.extend.console.register('bangumi', 'Generate pages of bangumis for Hexo', o log.info('Bangumis data has been deleted'); } } else if (args.u) { - var _this$config3; - if (!(this !== null && this !== void 0 && (_this$config3 = this.config) !== null && _this$config3 !== void 0 && _this$config3.bangumi)) { + var _this$config4; + if (!(this !== null && this !== void 0 && (_this$config4 = this.config) !== null && _this$config4 !== void 0 && _this$config4.bangumi)) { log.info('Please add config to _config.yml'); return; } @@ -65,6 +74,7 @@ hexo.extend.console.register('bangumi', 'Generate pages of bangumis for Hexo', o var _this$config$bangumi$, _this$config$bangumi$2; getBgmData({ vmid: this.config.bangumi.vmid, + type: "bangumi", showProgress: (_this$config$bangumi$ = this.config.bangumi.progress) !== null && _this$config$bangumi$ !== void 0 ? _this$config$bangumi$ : true, sourceDir: this.source_dir, extraOrder: this.config.bangumi.extraOrder, @@ -74,17 +84,30 @@ hexo.extend.console.register('bangumi', 'Generate pages of bangumis for Hexo', o host: "".concat(this.config.bangumi.source, ".tv"), coverMirror: (_this$config$bangumi$2 = this.config.bangumi.coverMirror) !== null && _this$config$bangumi$2 !== void 0 ? _this$config$bangumi$2 : '' }); - } else { + } else if (this.config.bangumi.source === 'bgmv0') { var _this$config$bangumi$3, _this$config$bangumi$4; + getBgmv0Data({ + vmid: this.config.bangumi.vmid, + type: 2, + showProgress: (_this$config$bangumi$3 = this.config.bangumi.progress) !== null && _this$config$bangumi$3 !== void 0 ? _this$config$bangumi$3 : true, + sourceDir: this.source_dir, + extraOrder: this.config.bangumi.extraOrder, + pagination: this.config.bangumi.pagination, + proxy: this.config.bangumi.proxy, + coverMirror: (_this$config$bangumi$4 = this.config.bangumi.coverMirror) !== null && _this$config$bangumi$4 !== void 0 ? _this$config$bangumi$4 : '' + }); + } else { + var _this$config$bangumi$5, _this$config$bangumi$6; getBiliData({ vmid: this.config.bangumi.vmid, type: 'bangumi', - showProgress: (_this$config$bangumi$3 = this.config.bangumi.progress) !== null && _this$config$bangumi$3 !== void 0 ? _this$config$bangumi$3 : true, + showProgress: (_this$config$bangumi$5 = this.config.bangumi.progress) !== null && _this$config$bangumi$5 !== void 0 ? _this$config$bangumi$5 : true, sourceDir: this.source_dir, extraOrder: this.config.bangumi.extraOrder, pagination: this.config.bangumi.pagination, useWebp: this.config.bangumi.webp, - coverMirror: (_this$config$bangumi$4 = this.config.bangumi.coverMirror) !== null && _this$config$bangumi$4 !== void 0 ? _this$config$bangumi$4 : '' + coverMirror: (_this$config$bangumi$6 = this.config.bangumi.coverMirror) !== null && _this$config$bangumi$6 !== void 0 ? _this$config$bangumi$6 : '', + SESSDATA: typeof args.u === 'string' ? args.u : null }); } } else { @@ -98,8 +121,8 @@ hexo.extend.console.register('cinema', 'Generate pages of bilibili cinemas for H log.info('Cinemas data has been deleted'); } } else if (args.u) { - var _this$config4, _this$config$cinema$p, _this$config$cinema$c; - if (!(this !== null && this !== void 0 && (_this$config4 = this.config) !== null && _this$config4 !== void 0 && _this$config4.cinema)) { + var _this$config5, _this$config$cinema$p, _this$config$cinema$c; + if (!(this !== null && this !== void 0 && (_this$config5 = this.config) !== null && _this$config5 !== void 0 && _this$config5.cinema)) { log.info('Please add config to _config.yml'); return; } @@ -124,3 +147,40 @@ hexo.extend.console.register('cinema', 'Generate pages of bilibili cinemas for H log.info('Unknown command, please use "hexo cinema -h" to see the available commands'); } }); +hexo.extend.console.register('game', 'Generate pages of games for Hexo', options, function (args) { + if (args.d) { + if (fs.existsSync(path.join(this.source_dir, '/_data/games.json'))) { + fs.unlinkSync(path.join(this.source_dir, '/_data/games.json')); + log.info('Games data has been deleted'); + } + } else if (args.u) { + var _this$config6, _this$config$game$pro, _this$config$game$cov; + if (!(this !== null && this !== void 0 && (_this$config6 = this.config) !== null && _this$config6 !== void 0 && _this$config6.game)) { + log.info('Please add config to _config.yml'); + return; + } + if (!this.config.game.enable) { + return; + } + if (!this.config.game.vmid) { + log.info('Please add vmid to _config.yml'); + return; + } + if (this.config.game.source !== 'bgmv0') { + log.info("".concat(this.config.bangumi.source, " not support")); + return; + } + getBgmv0Data({ + vmid: this.config.game.vmid, + type: 4, + showProgress: (_this$config$game$pro = this.config.game.progress) !== null && _this$config$game$pro !== void 0 ? _this$config$game$pro : true, + sourceDir: this.source_dir, + extraOrder: this.config.game.extraOrder, + pagination: this.config.game.pagination, + proxy: this.config.game.proxy, + coverMirror: (_this$config$game$cov = this.config.game.coverMirror) !== null && _this$config$game$cov !== void 0 ? _this$config$game$cov : '' + }); + } else { + log.info('Unknown command, please use "hexo game -h" to see the available commands'); + } +}); diff --git a/lib/bangumi-generator.js b/lib/bangumi-generator.js index 9d60e76..fd29c99 100644 --- a/lib/bangumi-generator.js +++ b/lib/bangumi-generator.js @@ -111,7 +111,7 @@ module.exports = /*#__PURE__*/function () { showMyComment: (_config$type$showMyCo = config[type].showMyComment) !== null && _config$type$showMyCo !== void 0 ? _config$type$showMyCo : false, pagination: (_config$type$paginati = config[type].pagination) !== null && _config$type$paginati !== void 0 ? _config$type$paginati : false, theme: fs.existsSync(path.join(__dirname, "templates/theme/".concat(config.theme, ".min.css"))) ? config.theme : null, - ejsTemplate: fs.readFileSync(path.join(__dirname, "templates/".concat(config[type].source === 'bili' ? 'bili' : 'bgm', "-template.ejs"))).toString().replace('class="bangumi-item"', 'class="bangumi-item bangumi-hide"'), + ejsTemplate: fs.readFileSync(path.join(__dirname, "templates/".concat(config[type].source === 'bili' ? 'bili' : config[type].source === 'bgmv0' ? 'bgmv0' : 'bgm', "-template.ejs"))).toString().replace('class="bangumi-item"', 'class="bangumi-item bangumi-hide"'), wantWatch: ['score', '-score'].includes(config[type].order) ? wantWatch.sort(function (a, b) { return config[type].order === 'score' ? a.score - b.score : b.score - a.score; }) : wantWatch, diff --git a/lib/get-bgm-data.js b/lib/get-bgm-data.js index dfa9c11..6540868 100644 --- a/lib/get-bgm-data.js +++ b/lib/get-bgm-data.js @@ -380,11 +380,11 @@ var getBangumiDataFromBangumiApi = /*#__PURE__*/function () { var getItemsId = /*#__PURE__*/function () { var _ref10 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(_ref9) { var _response$request$pat; - var vmid, status, showProgress, sourceDir, proxy, infoApi, host, coverMirror, getBangumiData, items, bar, options, response, username, $, pageNum, _loop, i; + var vmid, type, status, showProgress, sourceDir, proxy, infoApi, host, coverMirror, getBangumiData, items, bar, options, response, username, $, pageNum, _loop, i; return _regenerator["default"].wrap(function _callee5$(_context6) { while (1) switch (_context6.prev = _context6.next) { case 0: - vmid = _ref9.vmid, status = _ref9.status, showProgress = _ref9.showProgress, sourceDir = _ref9.sourceDir, proxy = _ref9.proxy, infoApi = _ref9.infoApi, host = _ref9.host, coverMirror = _ref9.coverMirror; + vmid = _ref9.vmid, type = _ref9.type, status = _ref9.status, showProgress = _ref9.showProgress, sourceDir = _ref9.sourceDir, proxy = _ref9.proxy, infoApi = _ref9.infoApi, host = _ref9.host, coverMirror = _ref9.coverMirror; getBangumiData = infoApi === 'bgmSub' ? getBangumiDataFromBangumiSubject : getBangumiDataFromBangumiApi; items = []; options = { @@ -400,10 +400,10 @@ var getItemsId = /*#__PURE__*/function () { }); } _context6.next = 7; - return axios.get("https://".concat(host, "/anime/list/").concat(vmid, "/").concat(status, "?page=1"), options); + return axios.get("https://".concat(host, "/").concat(type, "/list/").concat(vmid, "/").concat(status, "?page=1"), options); case 7: response = _context6.sent; - username = (_response$request$pat = response.request.path.match(/anime\/list\/(.*?)\//)) === null || _response$request$pat === void 0 ? void 0 : _response$request$pat[1]; + username = (_response$request$pat = response.request.path.match(/(anime|game)\/list\/(.*?)\//)) === null || _response$request$pat === void 0 ? void 0 : _response$request$pat[1]; if (username) { _context6.next = 11; break; @@ -439,7 +439,7 @@ var getItemsId = /*#__PURE__*/function () { _context6.t0.apply.call(_context6.t0, _context6.t1, _context6.t4); if (showProgress) { // eslint-disable-next-line no-nested-ternary - bar = new ProgressBar("\u6B63\u5728\u83B7\u53D6 ".concat(status === 'wish' ? '[想看]' : status === 'do' ? '[在看]' : '[已看]', " \u756A\u5267 [:bar] :percent :elapseds"), { + bar = new ProgressBar("\u6B63\u5728\u83B7\u53D6 ".concat(status === 'wish' ? '[想看]' : status === 'do' ? '[在看]' : '[已看]', " ").concat(type === 'game' ? '游戏' : '番剧', " [:bar] :percent :elapseds"), { total: pageNum < 2 ? 1 : pageNum, complete: '█' }); @@ -458,7 +458,7 @@ var getItemsId = /*#__PURE__*/function () { case 0: if (showProgress) bar.tick(); _context5.next = 3; - return axios.get("https://".concat(host, "/anime/list/").concat(username, "/").concat(status, "?page=").concat(i), _objectSpread(_objectSpread({}, options), {}, { + return axios.get("https://".concat(host, "/").concat(type, "/list/").concat(username, "/").concat(status, "?page=").concat(i), _objectSpread(_objectSpread({}, options), {}, { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36 Edg/97.0.1072.69' })); case 3: @@ -513,16 +513,21 @@ var getItemsId = /*#__PURE__*/function () { }(); module.exports.getBgmData = /*#__PURE__*/function () { var _getBgmData = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6(_ref11) { - var vmid, showProgress, sourceDir, extraOrder, pagination, proxy, infoApi, host, coverMirror, startTime, wantWatch, watching, watched, endTime, bangumis, allBangumis, _JSON$parse, wantWatchExtra, watchingExtra, watchedExtra; + var vmid, type, showProgress, sourceDir, extraOrder, pagination, proxy, infoApi, host, coverMirror, typePathMap, startTime, wantWatch, watching, watched, endTime, bangumis, allBangumis, _JSON$parse, wantWatchExtra, watchingExtra, watchedExtra; return _regenerator["default"].wrap(function _callee6$(_context7) { while (1) switch (_context7.prev = _context7.next) { case 0: - vmid = _ref11.vmid, showProgress = _ref11.showProgress, sourceDir = _ref11.sourceDir, extraOrder = _ref11.extraOrder, pagination = _ref11.pagination, proxy = _ref11.proxy, infoApi = _ref11.infoApi, host = _ref11.host, coverMirror = _ref11.coverMirror; + vmid = _ref11.vmid, type = _ref11.type, showProgress = _ref11.showProgress, sourceDir = _ref11.sourceDir, extraOrder = _ref11.extraOrder, pagination = _ref11.pagination, proxy = _ref11.proxy, infoApi = _ref11.infoApi, host = _ref11.host, coverMirror = _ref11.coverMirror; log.info('Getting bangumis, please wait...'); + typePathMap = { + bangumi: 'anime', + game: 'game' + }; startTime = new Date().getTime(); - _context7.next = 5; + _context7.next = 6; return getItemsId({ vmid: vmid, + type: typePathMap[type], status: 'wish', showProgress: showProgress, sourceDir: sourceDir, @@ -531,11 +536,12 @@ module.exports.getBgmData = /*#__PURE__*/function () { host: host, coverMirror: coverMirror }); - case 5: + case 6: wantWatch = _context7.sent; - _context7.next = 8; + _context7.next = 9; return getItemsId({ vmid: vmid, + type: typePathMap[type], status: 'do', showProgress: showProgress, sourceDir: sourceDir, @@ -544,11 +550,12 @@ module.exports.getBgmData = /*#__PURE__*/function () { host: host, coverMirror: coverMirror }); - case 8: + case 9: watching = _context7.sent; - _context7.next = 11; + _context7.next = 12; return getItemsId({ vmid: vmid, + type: typePathMap[type], status: 'collect', showProgress: showProgress, sourceDir: sourceDir, @@ -557,10 +564,10 @@ module.exports.getBgmData = /*#__PURE__*/function () { host: host, coverMirror: coverMirror }); - case 11: + case 12: watched = _context7.sent; endTime = new Date().getTime(); - log.info("".concat(wantWatch.length + watching.length + watched.length, " bangumis have been loaded in ").concat(endTime - startTime, " ms")); + log.info("".concat(wantWatch.length + watching.length + watched.length, " ").concat(type, "s have been loaded in ").concat(endTime - startTime, " ms")); bangumis = { wantWatch: wantWatch, watching: watching, @@ -569,17 +576,17 @@ module.exports.getBgmData = /*#__PURE__*/function () { if (!fs.existsSync(path.join(sourceDir, '/_data/'))) { fs.mkdirsSync(path.join(sourceDir, '/_data/')); } - fs.writeFile(path.join(sourceDir, '/_data/bangumis.json'), JSON.stringify(bangumis), function (err) { + fs.writeFile(path.join(sourceDir, "/_data/".concat(type, "s.json")), JSON.stringify(bangumis), function (err) { if (err) { - log.info('Failed to write data to _data/bangumis.json'); + log.info("Failed to write data to _data/".concat(type, "s.json")); console.error(err); } else { - log.info('Bangumi bangumis data has been saved'); + log.info("Bangumi ".concat(type, "s data has been saved")); } }); if (pagination) { allBangumis = _objectSpread({}, bangumis); // extra bangumis - if (fs.existsSync(path.join(sourceDir, '/_data/extra_bangumis.json'))) { + if (fs.existsSync(path.join(sourceDir, "/_data/extra_".concat(type, "s.json")))) { _JSON$parse = JSON.parse(fs.readFileSync(path.join(this.source_dir, "/_data/extra_".concat(type, "s.json")))), wantWatchExtra = _JSON$parse.wantWatchExtra, watchingExtra = _JSON$parse.watchingExtra, watchedExtra = _JSON$parse.watchedExtra; if (wantWatchExtra) { if (extraOrder === 1) { @@ -603,16 +610,16 @@ module.exports.getBgmData = /*#__PURE__*/function () { } } } - fs.writeFile(path.join(sourceDir, '/bangumis.json'), JSON.stringify(allBangumis), function (err) { + fs.writeFile(path.join(sourceDir, "/".concat(type, "s.json")), JSON.stringify(allBangumis), function (err) { if (err) { - log.info('Failed to write data to bangumis.json'); + log.info("Failed to write data to ".concat(type, "s.json")); console.error(err); } else { - log.info('Bangumi bangumis data has been saved'); + log.info("Bangumi ".concat(type, "s data has been saved")); } }); } - case 18: + case 19: case "end": return _context7.stop(); } diff --git a/lib/get-bgmv0-data.js b/lib/get-bgmv0-data.js new file mode 100644 index 0000000..ec57c53 --- /dev/null +++ b/lib/get-bgmv0-data.js @@ -0,0 +1,273 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); +var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); +var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); +var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); +var _this = void 0; +function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } +function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } +var fs = require('hexo-fs'); +var path = require('path'); +var axios = require('axios'); +var hexoLog = require('hexo-log'); +var log = typeof hexoLog["default"] === 'function' ? hexoLog["default"]({ + debug: false, + silent: false +}) : hexoLog({ + debug: false, + silent: false +}); +var ProgressBar = require('progress'); +var TYPE = { + 1: '书籍', + 2: '动画', + 3: '音乐', + 4: '游戏', + 6: '三次元' +}; +var getDataPage = /*#__PURE__*/function () { + var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(vmid, status, typeNum) { + var _response$data; + var response; + return _regenerator["default"].wrap(function _callee$(_context) { + while (1) switch (_context.prev = _context.next) { + case 0: + _context.next = 2; + return axios.get("http://api.bgm.tv/v0/users/".concat(vmid, "/collections?subject_type=").concat(typeNum, "&type=").concat(status, "&limit=1&offset=0"), { + headers: { + 'User-Agent': 'HCLonely/hexo-bilibili-bangumi' + } + }); + case 2: + response = _context.sent; + if (!(typeof (response === null || response === void 0 || (_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.total) !== 'undefined')) { + _context.next = 7; + break; + } + return _context.abrupt("return", { + success: true, + data: Math.ceil(response.data.total / 30) + 1 + }); + case 7: + if (!(response && response.data)) { + _context.next = 9; + break; + } + return _context.abrupt("return", { + success: false, + data: response.data + }); + case 9: + return _context.abrupt("return", { + success: false, + data: response + }); + case 10: + case "end": + return _context.stop(); + } + }, _callee); + })); + return function getDataPage(_x, _x2, _x3) { + return _ref.apply(this, arguments); + }; +}(); +var getData = /*#__PURE__*/function () { + var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(vmid, status, typeNum, pn, coverMirror) { + var response, $data, _response$data2, list, _iterator, _step, _bangumi$subject, _bangumi$subject2, _bangumi$subject3, _bangumi$subject4, _bangumi$subject5, _bangumi$subject$scor, _bangumi$subject6, _bangumi$subject7, _bangumi$subject8, _bangumi$subject9, _bangumi$subject10, bangumi; + return _regenerator["default"].wrap(function _callee2$(_context2) { + while (1) switch (_context2.prev = _context2.next) { + case 0: + _context2.next = 2; + return axios.get("http://api.bgm.tv/v0/users/".concat(vmid, "/collections?subject_type=").concat(typeNum, "&type=").concat(status, "&limit=30&offset=").concat(pn), { + headers: { + 'User-Agent': 'HCLonely/hexo-bilibili-bangumi' + } + }); + case 2: + response = _context2.sent; + $data = []; + if (!((response === null || response === void 0 ? void 0 : response.status) === 200)) { + _context2.next = 9; + break; + } + list = (response === null || response === void 0 || (_response$data2 = response.data) === null || _response$data2 === void 0 ? void 0 : _response$data2.data) || []; + _iterator = _createForOfIteratorHelper(list); + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + bangumi = _step.value; + $data.push({ + title: (bangumi === null || bangumi === void 0 || (_bangumi$subject = bangumi.subject) === null || _bangumi$subject === void 0 ? void 0 : _bangumi$subject.name_cn) || (bangumi === null || bangumi === void 0 || (_bangumi$subject2 = bangumi.subject) === null || _bangumi$subject2 === void 0 ? void 0 : _bangumi$subject2.name), + type: TYPE[(bangumi === null || bangumi === void 0 ? void 0 : bangumi.subject_type) || (bangumi === null || bangumi === void 0 ? void 0 : bangumi.type)] || '未知', + cover: coverMirror + (bangumi === null || bangumi === void 0 || (_bangumi$subject3 = bangumi.subject) === null || _bangumi$subject3 === void 0 || (_bangumi$subject3 = _bangumi$subject3.images) === null || _bangumi$subject3 === void 0 ? void 0 : _bangumi$subject3.common), + totalCount: bangumi === null || bangumi === void 0 || (_bangumi$subject4 = bangumi.subject) === null || _bangumi$subject4 === void 0 ? void 0 : _bangumi$subject4.eps, + id: (bangumi === null || bangumi === void 0 ? void 0 : bangumi.subject_id) || (bangumi === null || bangumi === void 0 || (_bangumi$subject5 = bangumi.subject) === null || _bangumi$subject5 === void 0 ? void 0 : _bangumi$subject5.id), + score: (_bangumi$subject$scor = bangumi === null || bangumi === void 0 || (_bangumi$subject6 = bangumi.subject) === null || _bangumi$subject6 === void 0 ? void 0 : _bangumi$subject6.score) !== null && _bangumi$subject$scor !== void 0 ? _bangumi$subject$scor : '-', + des: "".concat(bangumi === null || bangumi === void 0 || (_bangumi$subject7 = bangumi.subject) === null || _bangumi$subject7 === void 0 || (_bangumi$subject7 = _bangumi$subject7.short_summary) === null || _bangumi$subject7 === void 0 ? void 0 : _bangumi$subject7.trim(), "...") || '-', + collect: (bangumi === null || bangumi === void 0 || (_bangumi$subject8 = bangumi.subject) === null || _bangumi$subject8 === void 0 ? void 0 : _bangumi$subject8.collection_total) || '-', + myComment: bangumi.comment || '-', + progress: Math.round(((bangumi === null || bangumi === void 0 ? void 0 : bangumi.ep_status) || 0) / ((bangumi === null || bangumi === void 0 || (_bangumi$subject9 = bangumi.subject) === null || _bangumi$subject9 === void 0 ? void 0 : _bangumi$subject9.eps) || 1) * 100), + tags: (bangumi === null || bangumi === void 0 || (_bangumi$subject10 = bangumi.subject) === null || _bangumi$subject10 === void 0 || (_bangumi$subject10 = _bangumi$subject10.tags) === null || _bangumi$subject10 === void 0 || (_bangumi$subject10 = _bangumi$subject10[0]) === null || _bangumi$subject10 === void 0 ? void 0 : _bangumi$subject10.name) || '-', + ep_status: (bangumi === null || bangumi === void 0 ? void 0 : bangumi.ep_status) || 0 + }); + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + return _context2.abrupt("return", $data); + case 9: + case "end": + return _context2.stop(); + } + }, _callee2); + })); + return function getData(_x4, _x5, _x6, _x7, _x8) { + return _ref2.apply(this, arguments); + }; +}(); +var processData = /*#__PURE__*/function () { + var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(vmid, status, showProgress, typeNum, coverMirror) { + var page, list, bar, i, data; + return _regenerator["default"].wrap(function _callee3$(_context3) { + while (1) switch (_context3.prev = _context3.next) { + case 0: + _context3.next = 2; + return getDataPage(vmid, status, typeNum); + case 2: + page = _context3.sent; + if (!(page !== null && page !== void 0 && page.success)) { + _context3.next = 18; + break; + } + list = []; + bar = null; + if (showProgress) { + // eslint-disable-next-line no-nested-ternary + bar = new ProgressBar("\u6B63\u5728\u83B7\u53D6 ".concat(status === 1 ? "".concat(typeNum === 4 ? '[想玩]' : '[想看]') : status === 2 ? "".concat(typeNum === 4 ? '[已玩]' : '[已看]') : "".concat(typeNum === 4 ? '[在玩]' : '[在看]'), " ").concat(TYPE[typeNum], " [:bar] :percent :elapseds"), { + total: page.data - 1, + complete: '█' + }); + } + // eslint-disable-next-line no-plusplus + i = 1; + case 8: + if (!(i < page.data)) { + _context3.next = 17; + break; + } + if (showProgress) bar.tick(); + _context3.next = 12; + return getData(vmid, status, typeNum, (i - 1) * 30, coverMirror); + case 12: + data = _context3.sent; + list.push.apply(list, (0, _toConsumableArray2["default"])(data)); + case 14: + i++; + _context3.next = 8; + break; + case 17: + return _context3.abrupt("return", list); + case 18: + console.log("Get ".concat(typeNum === 2 ? 'bangumi' : 'game', " data error:"), page === null || page === void 0 ? void 0 : page.data); + return _context3.abrupt("return", []); + case 20: + case "end": + return _context3.stop(); + } + }, _callee3); + })); + return function processData(_x9, _x10, _x11, _x12, _x13) { + return _ref3.apply(this, arguments); + }; +}(); +module.exports.getBgmv0Data = /*#__PURE__*/function () { + var _ref5 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(_ref4) { + var vmid, type, showProgress, sourceDir, extraOrder, pagination, coverMirror, startTime, wantWatch, watching, watched, endTime, bangumis, allBangumis, _JSON$parse, wantWatchExtra, watchingExtra, watchedExtra; + return _regenerator["default"].wrap(function _callee4$(_context4) { + while (1) switch (_context4.prev = _context4.next) { + case 0: + vmid = _ref4.vmid, type = _ref4.type, showProgress = _ref4.showProgress, sourceDir = _ref4.sourceDir, extraOrder = _ref4.extraOrder, pagination = _ref4.pagination, coverMirror = _ref4.coverMirror; + log.info("Getting bgm ".concat(type === 2 ? 'bangumi' : 'game', " data, please wait...")); + startTime = new Date().getTime(); + _context4.next = 5; + return processData(vmid, 1, showProgress, type, coverMirror); + case 5: + wantWatch = _context4.sent; + _context4.next = 8; + return processData(vmid, 3, showProgress, type, coverMirror); + case 8: + watching = _context4.sent; + _context4.next = 11; + return processData(vmid, 2, showProgress, type, coverMirror); + case 11: + watched = _context4.sent; + endTime = new Date().getTime(); + log.info("".concat(wantWatch.length + watching.length + watched.length, " ").concat(type, "s have been loaded in ").concat(endTime - startTime, " ms")); + bangumis = { + wantWatch: wantWatch, + watching: watching, + watched: watched + }; + if (!fs.existsSync(path.join(sourceDir, '/_data/'))) { + fs.mkdirsSync(path.join(sourceDir, '/_data/')); + } + fs.writeFile(path.join(sourceDir, "/_data/".concat(type === 2 ? 'bangumi' : 'game', "s.json")), JSON.stringify(bangumis), function (err) { + if (err) { + log.info("Failed to write data to _data/".concat(type === 2 ? 'bangumi' : 'game', "s.json")); + console.error(err); + } else { + log.info("Bgm ".concat(type === 2 ? 'bangumi' : 'game', "s data has been saved")); + } + }); + if (pagination) { + allBangumis = _objectSpread({}, bangumis); // extra bangumis + if (fs.existsSync(path.join(sourceDir, "/_data/extra_".concat(type === 2 ? 'bangumi' : 'game', "s.json")))) { + _JSON$parse = JSON.parse(fs.readFileSync(path.join(_this.source_dir, "/_data/extra_".concat(type === 2 ? 'bangumi' : 'game', "s.json")))), wantWatchExtra = _JSON$parse.wantWatchExtra, watchingExtra = _JSON$parse.watchingExtra, watchedExtra = _JSON$parse.watchedExtra; + if (wantWatchExtra) { + if (extraOrder === 1) { + allBangumis.wantWatch = [].concat((0, _toConsumableArray2["default"])(wantWatchExtra), (0, _toConsumableArray2["default"])(allBangumis.wantWatch)); + } else { + allBangumis.wantWatch = [].concat((0, _toConsumableArray2["default"])(allBangumis.wantWatch), (0, _toConsumableArray2["default"])(wantWatchExtra)); + } + } + if (watchingExtra) { + if (extraOrder === 1) { + allBangumis.watching = [].concat((0, _toConsumableArray2["default"])(watchingExtra), (0, _toConsumableArray2["default"])(allBangumis.watching)); + } else { + allBangumis.watching = [].concat((0, _toConsumableArray2["default"])(allBangumis.watching), (0, _toConsumableArray2["default"])(watchingExtra)); + } + } + if (watchedExtra) { + if (extraOrder === 1) { + allBangumis.watched = [].concat((0, _toConsumableArray2["default"])(watchedExtra), (0, _toConsumableArray2["default"])(allBangumis.watched)); + } else { + allBangumis.watched = [].concat((0, _toConsumableArray2["default"])(allBangumis.watched), (0, _toConsumableArray2["default"])(watchedExtra)); + } + } + } + fs.writeFile(path.join(sourceDir, "/".concat(type === 2 ? 'bangumi' : 'game', "s.json")), JSON.stringify(bangumis), function (err) { + if (err) { + log.info("Failed to write data to ".concat(type === 2 ? 'bangumi' : 'game', "s.json")); + console.error(err); + } else { + log.info("Bgm ".concat(type === 2 ? 'bangumi' : 'game', "s data has been saved")); + } + }); + } + case 18: + case "end": + return _context4.stop(); + } + }, _callee4); + })); + return function (_x14) { + return _ref5.apply(this, arguments); + }; +}(); diff --git a/lib/get-bili-data.js b/lib/get-bili-data.js index 6e2fe3b..363f799 100644 --- a/lib/get-bili-data.js +++ b/lib/get-bili-data.js @@ -76,14 +76,18 @@ var getDataPage = /*#__PURE__*/function () { }; }(); var getData = /*#__PURE__*/function () { - var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(vmid, status, useWebp, typeNum, pn, coverMirror) { + var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(vmid, status, useWebp, typeNum, pn, coverMirror, SESSDATA) { var _response$data5; - var response, $data, _response$data6, data, list, _iterator, _step, _bangumi$areas, _bangumi$stat, _bangumi$stat2, _bangumi$stat3, _bangumi$rating$score, _bangumi$rating, bangumi, cover, href; + var response, $data, _response$data6, data, list, _iterator, _step, _bangumi$areas, _bangumi$stat, _bangumi$stat2, _bangumi$stat3, _bangumi$rating$score, _bangumi$rating, _bangumi$progress$mat, _bangumi$new_ep, _bangumi$progress$mat2, _bangumi$new_ep2, bangumi, cover, href; return _regenerator["default"].wrap(function _callee2$(_context2) { while (1) switch (_context2.prev = _context2.next) { case 0: _context2.next = 2; - return axios.get("https://api.bilibili.com/x/space/bangumi/follow/list?type=".concat(typeNum, "&follow_status=").concat(status, "&vmid=").concat(vmid, "&ps=30&pn=").concat(pn)); + return axios.get("https://api.bilibili.com/x/space/bangumi/follow/list?type=".concat(typeNum, "&follow_status=").concat(status, "&vmid=").concat(vmid, "&ps=30&pn=").concat(pn), { + headers: { + cookie: "SESSDATA=".concat(SESSDATA, ";") + } + }); case 2: response = _context2.sent; $data = []; @@ -116,7 +120,10 @@ var getData = /*#__PURE__*/function () { danmaku: count(bangumi === null || bangumi === void 0 || (_bangumi$stat3 = bangumi.stat) === null || _bangumi$stat3 === void 0 ? void 0 : _bangumi$stat3.danmaku), coin: count(bangumi.stat.coin), score: (_bangumi$rating$score = bangumi === null || bangumi === void 0 || (_bangumi$rating = bangumi.rating) === null || _bangumi$rating === void 0 ? void 0 : _bangumi$rating.score) !== null && _bangumi$rating$score !== void 0 ? _bangumi$rating$score : '-', - des: bangumi === null || bangumi === void 0 ? void 0 : bangumi.evaluate + des: bangumi === null || bangumi === void 0 ? void 0 : bangumi.evaluate, + progress: !SESSDATA ? false : Math.round((parseInt((bangumi === null || bangumi === void 0 || (_bangumi$progress$mat = bangumi.progress.match(/\d+/)) === null || _bangumi$progress$mat === void 0 ? void 0 : _bangumi$progress$mat[0]) || '0', 10) || 0) / ((bangumi === null || bangumi === void 0 ? void 0 : bangumi.total_count) > 0 ? bangumi.total_count : ((_bangumi$new_ep = bangumi.new_ep) === null || _bangumi$new_ep === void 0 ? void 0 : _bangumi$new_ep.title) || 1) * 100), + ep_status: !SESSDATA ? false : parseInt((bangumi === null || bangumi === void 0 || (_bangumi$progress$mat2 = bangumi.progress.match(/\d+/)) === null || _bangumi$progress$mat2 === void 0 ? void 0 : _bangumi$progress$mat2[0]) || '0', 10) || 0, + new_ep: (bangumi === null || bangumi === void 0 ? void 0 : bangumi.total_count) > 0 ? bangumi.total_count : ((_bangumi$new_ep2 = bangumi.new_ep) === null || _bangumi$new_ep2 === void 0 ? void 0 : _bangumi$new_ep2.title) || -1 }); } } catch (err) { @@ -131,7 +138,7 @@ var getData = /*#__PURE__*/function () { } }, _callee2); })); - return function getData(_x4, _x5, _x6, _x7, _x8, _x9) { + return function getData(_x4, _x5, _x6, _x7, _x8, _x9, _x10) { return _ref2.apply(this, arguments); }; }(); @@ -145,7 +152,7 @@ var total = function total(e, typeNum) { return e ? e === -1 ? '未完结' : "\u5168".concat(e).concat(typeNum === 1 ? '话' : '集') : '-'; }; var processData = /*#__PURE__*/function () { - var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(vmid, status, useWebp, showProgress, typeNum, coverMirror) { + var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(vmid, status, useWebp, showProgress, typeNum, coverMirror, SESSDATA) { var page, list, bar, i, data; return _regenerator["default"].wrap(function _callee3$(_context3) { while (1) switch (_context3.prev = _context3.next) { @@ -176,7 +183,7 @@ var processData = /*#__PURE__*/function () { } if (showProgress) bar.tick(); _context3.next = 12; - return getData(vmid, status, useWebp, typeNum, i, coverMirror); + return getData(vmid, status, useWebp, typeNum, i, coverMirror, SESSDATA); case 12: data = _context3.sent; list.push.apply(list, (0, _toConsumableArray2["default"])(data)); @@ -195,30 +202,30 @@ var processData = /*#__PURE__*/function () { } }, _callee3); })); - return function processData(_x10, _x11, _x12, _x13, _x14, _x15) { + return function processData(_x11, _x12, _x13, _x14, _x15, _x16, _x17) { return _ref3.apply(this, arguments); }; }(); module.exports.getBiliData = /*#__PURE__*/function () { var _ref5 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(_ref4) { - var vmid, type, showProgress, sourceDir, extraOrder, pagination, _ref4$useWebp, useWebp, coverMirror, typeNum, startTime, wantWatch, watching, watched, endTime, bangumis, allBangumis, _JSON$parse, wantWatchExtra, watchingExtra, watchedExtra; + var vmid, type, showProgress, sourceDir, extraOrder, pagination, _ref4$useWebp, useWebp, coverMirror, SESSDATA, typeNum, startTime, wantWatch, watching, watched, endTime, bangumis, allBangumis, _JSON$parse, wantWatchExtra, watchingExtra, watchedExtra; return _regenerator["default"].wrap(function _callee4$(_context4) { while (1) switch (_context4.prev = _context4.next) { case 0: - vmid = _ref4.vmid, type = _ref4.type, showProgress = _ref4.showProgress, sourceDir = _ref4.sourceDir, extraOrder = _ref4.extraOrder, pagination = _ref4.pagination, _ref4$useWebp = _ref4.useWebp, useWebp = _ref4$useWebp === void 0 ? true : _ref4$useWebp, coverMirror = _ref4.coverMirror; + vmid = _ref4.vmid, type = _ref4.type, showProgress = _ref4.showProgress, sourceDir = _ref4.sourceDir, extraOrder = _ref4.extraOrder, pagination = _ref4.pagination, _ref4$useWebp = _ref4.useWebp, useWebp = _ref4$useWebp === void 0 ? true : _ref4$useWebp, coverMirror = _ref4.coverMirror, SESSDATA = _ref4.SESSDATA; typeNum = type === 'cinema' ? 2 : 1; log.info("Getting bilibili ".concat(type, ", please wait...")); startTime = new Date().getTime(); _context4.next = 6; - return processData(vmid, 1, useWebp, showProgress, typeNum, coverMirror); + return processData(vmid, 1, useWebp, showProgress, typeNum, coverMirror, SESSDATA); case 6: wantWatch = _context4.sent; _context4.next = 9; - return processData(vmid, 2, useWebp, showProgress, typeNum, coverMirror); + return processData(vmid, 2, useWebp, showProgress, typeNum, coverMirror, SESSDATA); case 9: watching = _context4.sent; _context4.next = 12; - return processData(vmid, 3, useWebp, showProgress, typeNum, coverMirror); + return processData(vmid, 3, useWebp, showProgress, typeNum, coverMirror, SESSDATA); case 12: watched = _context4.sent; endTime = new Date().getTime(); @@ -280,7 +287,7 @@ module.exports.getBiliData = /*#__PURE__*/function () { } }, _callee4); })); - return function (_x16) { + return function (_x18) { return _ref5.apply(this, arguments); }; }(); diff --git a/lib/templates/bangumi.ejs b/lib/templates/bangumi.ejs index 474d84b..e3262f1 100644 --- a/lib/templates/bangumi.ejs +++ b/lib/templates/bangumi.ejs @@ -9,32 +9,31 @@ <% } %>
- <%= __('wantWatch') %> + <%= __(type === 'game' ? 'wantPlay' : 'wantWatch') %> (<%= wantWatch.length %>) - <%= __('watching') %> + <%= __(type === 'game' ? 'playing' : 'watching') %> (<%= watching.length %>) - <%= __('watched') %> + <%= __(type === 'game' ? 'played' : 'watched') %> (<%= watched.length %>)
<% if (pagination) { %> <% wantWatch.slice(0, 10).forEach(function(item){ %> - <%- include((source === 'bili' ? 'bili' : 'bgm') + '-template.ejs', {item,loading,metaColor,type,lazyloadAttrName,srcValue}) %> + <%- include((source === 'bili' ? 'bili' : (source === 'bgmv0' ? 'bgmv0' : 'bgm')) + '-template.ejs', {item,loading,metaColor,type,lazyloadAttrName,srcValue}) %> <% }); %> <%- include('pagination.ejs', {__: __}) %> <% } else { %> <% wantWatch.forEach(function(item){ %> - <%- include((source === 'bili' ? 'bili' : 'bgm') + '-template.ejs', {item,loading,metaColor,type,lazyloadAttrName,srcValue}) %> + <%- include((source === 'bili' ? 'bili' : (source === 'bgmv0' ? 'bgmv0' : 'bgm')) + '-template.ejs', {item,loading,metaColor,type,lazyloadAttrName,srcValue}) %> <% }); %> <%- include('pagination.ejs', {__: __}) %> <% } %> @@ -42,12 +41,12 @@
<% if (pagination) { %> <% watching.slice(0, 10).forEach(function(item){ %> - <%- include((source === 'bili' ? 'bili' : 'bgm') + '-template.ejs', {item,loading,metaColor,type,lazyloadAttrName,srcValue}) %> + <%- include((source === 'bili' ? 'bili' : (source === 'bgmv0' ? 'bgmv0' : 'bgm')) + '-template.ejs', {item,loading,metaColor,type,lazyloadAttrName,srcValue}) %> <% }); %> <%- include('pagination.ejs', {__: __}) %> <% } else { %> <% watching.forEach(function(item){ %> - <%- include((source === 'bili' ? 'bili' : 'bgm') + '-template.ejs', {item,loading,metaColor,type,lazyloadAttrName,srcValue}) %> + <%- include((source === 'bili' ? 'bili' : (source === 'bgmv0' ? 'bgmv0' : 'bgm')) + '-template.ejs', {item,loading,metaColor,type,lazyloadAttrName,srcValue}) %> <% }); %> <%- include('pagination.ejs', {__: __}) %> <% } %> @@ -55,12 +54,12 @@
<% if (pagination) { %> <% watched.slice(0, 10).forEach(function(item){ %> - <%- include((source === 'bili' ? 'bili' : 'bgm') + '-template.ejs', {item,loading,metaColor,type,lazyloadAttrName,srcValue}) %> + <%- include((source === 'bili' ? 'bili' : (source === 'bgmv0' ? 'bgmv0' : 'bgm')) + '-template.ejs', {item,loading,metaColor,type,lazyloadAttrName,srcValue}) %> <% }); %> <%- include('pagination.ejs', {__: __}) %> <% } else { %> <% watched.forEach(function(item){ %> - <%- include((source === 'bili' ? 'bili' : 'bgm') + '-template.ejs', {item,loading,metaColor,type,lazyloadAttrName,srcValue}) %> + <%- include((source === 'bili' ? 'bili' : (source === 'bgmv0' ? 'bgmv0' : 'bgm')) + '-template.ejs', {item,loading,metaColor,type,lazyloadAttrName,srcValue}) %> <% }); %> <%- include('pagination.ejs', {__: __}) %> <% } %> diff --git a/lib/templates/bgm-template.ejs b/lib/templates/bgm-template.ejs index 55ac03f..af059e5 100644 --- a/lib/templates/bgm-template.ejs +++ b/lib/templates/bgm-template.ejs @@ -3,42 +3,42 @@
- > - + > <% if(item.totalCount){ %> + <%= item.totalCount %>0 <% } %> - 类型 <%= item.type %> + <%= __('type') %> <%= item.type %> - 想看 <%= item.wish %> + <%= __('wantWatch') %> <%= item.wish %> - 在看 <%= item.doing || "-" %> + <%= __('watching') %> <%= item.doing || "-" %> - 已看 <%= item.collect || "-" %> + <%= __('watched') %> <%= item.collect || "-" %> - 评分 <%= item.score || "-" %> + <%= __('score') %> <%= item.score || "-" %>
-
> -

简介:<%= item.des || "暂无简介" %>

+
> +

<%= __('summary') %>:<%= item.des || __('noSummary') %>

<% if (showMyComment && item.myComment) { %> -
我的评分: +
<%= __('myScore') %>: <% if (item.myStars) { %> <% } %>
- 我的评价:<%= item.myComment %> + <%= __('comment') %>:<%= item.myComment %>
<% } %>
diff --git a/lib/templates/bgmv0-template.ejs b/lib/templates/bgmv0-template.ejs new file mode 100644 index 0000000..ba3a180 --- /dev/null +++ b/lib/templates/bgmv0-template.ejs @@ -0,0 +1,47 @@ +
+
" <%- lazyload ? ` data-src="${item.cover}"` : (lazyloadAttrName ? ` ${lazyloadAttrName.split('=')[0]}="${lazyloadAttrName.split('=')[1] === '__loading__' ? (loading || "https://cdn.jsdelivr.net/npm/hexo-bilibili-bangumi@1.2.0/lib/img/loading.gif") : (lazyloadAttrName.split('=')[1] === '__image__' ? `https:${item.cover.replace(/^https:/, '')}` : (lazyloadAttrName.split('=')[1] || ''))}"` : "") %> referrerPolicy="no-referrer" width="110" style="width:110px;margin:20px auto;" /> +
+
+ +
+ > + <% if(item.totalCount && item.type !=='游戏'){ %> + + <%= item.totalCount ? `全${item.totalCount}话` : '-' %>0 + + <% } %> + + <%= __('type') %> <%= item.type %> + + + <%= __('tag') %> <%= item.tags %> + + + + <%= __('score') %> + <%= item.score || "-" %> + + +
+ <% if(item.type !=='游戏' ){ %> +
+
追番进度:<%= item.ep_status %>/<%= item.totalCount %>
+
+
+ <% } %> +
+

<%= __('summary') %>:<%= item.des || __('noSummary') %>

+ <% if (showMyComment && item.myComment) { %> + <%= __('comment') %>:<%= item.myComment %> +
+ <% } %> +
+
+
diff --git a/lib/templates/bili-template.ejs b/lib/templates/bili-template.ejs index 13bc43f..469b563 100644 --- a/lib/templates/bili-template.ejs +++ b/lib/templates/bili-template.ejs @@ -3,12 +3,12 @@
- > - + > <% if(item.totalCount){ %> + <%= item.totalCount %>0 @@ -19,22 +19,29 @@ <% } %> - 总播放 <%= item.view || "-" %> + <%= __('view') %> <%= item.view || "-" %> - <%= type === "bangumi" ? "追番人数" : "追剧人数" %> <%= item.follow || "-" %> + <%= __('follow') %> <%= item.follow || "-" %> - 硬币数 <%= item.coin || "-" %> + <%= __('coin') %> <%= item.coin || "-" %> - 弹幕总数 <%= item.danmaku || "-" %> + <%= __('danmaku') %> <%= item.danmaku || "-" %> - 评分 <%= item.score || "-" %> + <%= __('score') %> <%= item.score || "-" %>
-
>

简介:<%= item.des || "暂无简介" %>

+ <% if (item.progress !== false) { %> +
+
追番进度:<%= item.ep_status %>/<%= item.new_ep %> +
+
+
+ <% } %> +

<%= __('summary') %>:<%= item.des || __('noSummary') %>

diff --git a/lib/templates/index.css b/lib/templates/index.css index f47c714..5883fc5 100644 --- a/lib/templates/index.css +++ b/lib/templates/index.css @@ -1 +1 @@ -.bangumi-tabs{margin-bottom:15px;margin-top:15px}.bangumi-tab{padding:5px}a.bangumi-tab{text-decoration:none}.bangumi-active{background:#657b83;color:#fff}.bangumi-item{position:relative;clear:both;padding:10px 0;border-bottom:1px solid #ddd;min-height:180px}@media screen and (max-width:600px){.bangumi-item{width:100%}}.bangumi-picture{position:absolute;left:0;top:10px;width:110px}.bangumi-picture img{margin:10px 0}.bangumi-info{padding-left:120px;margin-top:10px}.bangumi-meta{font-size:12px;padding-right:10px;height:45px}.bangumi-comments{font-size:12px;margin-top:10px}.bangumi-comments>p{word-break:break-all;text-overflow:ellipsis;overflow:hidden;white-space:normal;display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:3}.bangumi-pagination{margin-top:15px;text-align:center;margin-bottom:10px}.bangumi-button{padding:5px}.bangumi-button:hover{background:#657b83;color:#fff}.bangumi-hide{display:none}.bangumi-show{display:block}.bangumi-title{font-size:18px}.bangumi-title a{line-height:1;text-decoration:none}.bangumi-info-items{font-size:12px;color:#2fd8d8;padding-top:10px;line-height:1;float:left;width:100%}.bangumi-info-item{display:inline-block;width:13%;border-right:1px solid #2fd8d8;text-align:center;height:34px}.bangumi-info-label{display:block;line-height:12px}.bangumi-info-item em{display:block;padding-top:6px;line-height:17px;font-style:normal;font-weight:700}.bangumi-info-total{padding-top:11px;display:block;line-height:12px;font-weight:700}.bangumi-info-item-score{border-right:1px solid #0000;width:50px}.bangumi-info-label-em{color:transparent;opacity:0;visibility:hidden;line-height:6px!important;padding:0!important}@media (max-width:650px){.bangumi-coin,.bangumi-type{display:none}.bangumi-info-item{width:16%}}@media (max-width:590px){.bangumi-danmaku,.bangumi-wish{display:none}.bangumi-info-item{width:19%}}@media (max-width:520px){.bangumi-doing,.bangumi-play{display:none}.bangumi-info-item{width:24%}}@media (max-width:480px){.bangumi-collect,.bangumi-follow{display:none}.bangumi-info-item{width:30%}}@media (max-width:400px){.bangumi-area{display:none}.bangumi-info-item{width:45%}}.bangumi-my-comments{border:1px dashed #8f8f8f;padding:3px;border-radius:5px;margin-left:-120px}.bangumi-starstop{background:url(https://cdn.jsdelivr.net/npm/hexo-bilibili-bangumi@1.7.9/lib/img/rate_star_2x.png) 100% 100%/10px 19.5px repeat-x;height:10px;width:50px;display:inline-block;float:none}.bangumi-starlight{background:url(https://cdn.jsdelivr.net/npm/hexo-bilibili-bangumi@1.7.9/lib/img/rate_star_2x.png) 0 0/10px 19.5px repeat-x;height:10px;display:block;width:100%}.bangumi-starlight.stars1{width:5px}.bangumi-starlight.stars2{width:10px}.bangumi-starlight.stars3{width:15px}.bangumi-starlight.stars4{width:20px}.bangumi-starlight.stars5{width:25px}.bangumi-starlight.stars6{width:30px}.bangumi-starlight.stars7{width:35px}.bangumi-starlight.stars8{width:40px}.bangumi-starlight.stars9{width:45px}.bangumi-starlight.stars10{width:50px} \ No newline at end of file +.bangumi-tabs{margin-bottom:15px;margin-top:15px}.bangumi-tab{padding:5px}a.bangumi-tab{text-decoration:none}.bangumi-active{background:#657b83;color:#fff}.bangumi-item{position:relative;clear:both;padding:10px 0;border-bottom:1px solid #ddd;min-height:180px}@media screen and (max-width:600px){.bangumi-item{width:100%}}.bangumi-picture{position:absolute;left:0;top:10px;width:110px}.bangumi-picture img{margin:10px 0}.bangumi-info{padding-left:120px;margin-top:10px}.bangumi-meta{font-size:12px;padding-right:10px;height:45px}.bangumi-comments{font-size:12px;margin-top:10px}.bangumi-comments>p{word-break:break-all;text-overflow:ellipsis;overflow:hidden;white-space:normal;display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:3}.bangumi-pagination{margin-top:15px;text-align:center;margin-bottom:10px}.bangumi-button{padding:5px}.bangumi-button:hover{background:#657b83;color:#fff}.bangumi-hide{display:none}.bangumi-show{display:block}.bangumi-title{font-size:18px;font-weight:700}.bangumi-title a{line-height:1;text-decoration:none}.bangumi-info-items{font-size:12px;color:#2fd8d8;padding-top:10px;line-height:1;float:left;width:100%}.bangumi-info-item{display:inline-block;width:13%;border-right:1px solid #2fd8d8;text-align:center;height:34px}.bangumi-info-label{display:block;line-height:12px}.bangumi-info-item em{display:block;padding-top:6px;line-height:17px;font-style:normal;font-weight:700}.bangumi-info-total{padding-top:11px;display:block;line-height:12px;font-weight:700}.bangumi-info-item-score{border-right:1px solid #0000;width:50px}.bangumi-info-label-em{color:transparent;opacity:0;visibility:hidden;line-height:6px!important;padding:0!important}@media (max-width:650px){.bangumi-coin,.bangumi-type{display:none}.bangumi-info-item{width:16%}}@media (max-width:590px){.bangumi-danmaku,.bangumi-wish{display:none}.bangumi-info-item{width:19%}}@media (max-width:520px){.bangumi-doing,.bangumi-play{display:none}.bangumi-info-item{width:24%}}@media (max-width:480px){.bangumi-collect,.bangumi-follow{display:none}.bangumi-info-item{width:30%}}@media (max-width:400px){.bangumi-area{display:none}.bangumi-info-item{width:45%}}.bangumi-my-comments{border:1px dashed #8f8f8f;padding:3px;border-radius:5px;margin-left:-120px}.bangumi-starstop{background:url(https://cdn.jsdelivr.net/npm/hexo-bilibili-bangumi@1.7.9/lib/img/rate_star_2x.png) 100% 100%/10px 19.5px repeat-x;height:10px;width:50px;display:inline-block;float:none}.bangumi-starlight{background:url(https://cdn.jsdelivr.net/npm/hexo-bilibili-bangumi@1.7.9/lib/img/rate_star_2x.png) 0 0/10px 19.5px repeat-x;height:10px;display:block;width:100%}.bangumi-starlight.stars1{width:5px}.bangumi-starlight.stars2{width:10px}.bangumi-starlight.stars3{width:15px}.bangumi-starlight.stars4{width:20px}.bangumi-starlight.stars5{width:25px}.bangumi-starlight.stars6{width:30px}.bangumi-starlight.stars7{width:35px}.bangumi-starlight.stars8{width:40px}.bangumi-starlight.stars9{width:45px}.bangumi-starlight.stars10{width:50px}.bangumi-info .bangumi-progress{width:100%;height:24px;background-color:#f2f2f2;border-radius:5px;overflow:hidden;font-size:16px;text-align:center;position:relative}.bangumi-info .bangumi-progress-text{z-index:100;position:relative;color:#3c4858;line-height:24px}.bangumi-info .bangumi-progress .progress-bar{z-index:50;height:100%;background-color:#007bffad;border-radius:5px;position:absolute;top:0} \ No newline at end of file diff --git a/lib/util.js b/lib/util.js index 854a84f..f4c55ad 100644 --- a/lib/util.js +++ b/lib/util.js @@ -11,7 +11,22 @@ i18n.set('en', { prev: 'Prev', next: 'Next', top: 'Top', - end: 'End' + end: 'End', + wantPlay: 'Wish', + playing: 'Playing', + played: 'Played', + type: 'Type', + tag: 'Tags', + score: 'Score', + follow: 'Follow', + summary: 'Summary', + comment: 'My Comment', + noSummary: 'No Summary', + unknown: 'Unknown', + view: 'Views', + coin: 'Coins', + danmaku: 'Danmaku', + myScore: 'My Score' // Added myScore translation }); i18n.set('zh-TW', { wantWatch: '想看', @@ -20,7 +35,22 @@ i18n.set('zh-TW', { prev: '上一頁', next: '下一頁', top: '首頁', - end: '尾頁' + end: '尾頁', + wantPlay: '想玩', + playing: '在玩', + played: '玩過', + type: '類型', + tag: '標籤', + score: '評分', + follow: '關注', + summary: '簡介', + comment: '我的評價', + noSummary: '暫無簡介', + unknown: '未知', + view: '總播放', + coin: '硬幣', + danmaku: '彈幕', + myScore: '我的評分' // Added myScore translation }); i18n.set('zh-Hans', { wantWatch: '想看', @@ -29,7 +59,22 @@ i18n.set('zh-Hans', { prev: '上一页', next: '下一页', top: '首页', - end: '尾页' + end: '尾页', + wantPlay: '想玩', + playing: '在玩', + played: '玩过', + type: '类型', + tag: '标签', + score: '评分', + follow: '关注', + summary: '简介', + comment: '我的评价', + noSummary: '暂无简介', + unknown: '未知', + view: '总播放', + coin: '硬币', + danmaku: '弹幕', + myScore: '我的评分' // Added myScore translation }); i18n.set('zh-CN', { wantWatch: '想看', @@ -38,6 +83,21 @@ i18n.set('zh-CN', { prev: '上一页', next: '下一页', top: '首页', - end: '尾页' + end: '尾页', + wantPlay: '想玩', + playing: '在玩', + played: '玩过', + type: '类型', + tag: '标签', + score: '评分', + follow: '关注', + summary: '简介', + comment: '我的评价', + noSummary: '暂无简介', + unknown: '未知', + view: '总播放', + coin: '硬币', + danmaku: '弹幕', + myScore: '我的评分' // Added myScore translation }); module.exports.i18n = i18n; diff --git a/package.json b/package.json index fc6972f..78cc2e3 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { "name": "hexo-bilibili-bangumi", - "version": "1.9.0", + "version": "1.10.0", "description": "hexo bilibili番剧页", "main": "index.js", "scripts": { "test": "standard --fix && ejslint lib/templates/*.ejs", - "build": "babel src/index.js --out-file index.js && babel src/lib/util.js --out-file lib/util.js && babel src/lib/get-bili-data.js --out-file lib/get-bili-data.js && babel src/lib/get-bgm-data.js --out-file lib/get-bgm-data.js && babel src/lib/bangumi-generator.js --out-file lib/bangumi-generator.js && babel src/lib/templates/index.js --out-file lib/templates/index.js --presets minify && babel --no-babelrc src/lib/templates/pagination.js --out-file lib/templates/pagination.js --presets minify && cleancss src/lib/templates/index.css -O2 -o lib/templates/index.css && cleancss --batch src/lib/templates/theme/*.css --batch-suffix .min -O2 -o lib/templates/theme/", + "build": "babel src/index.js --out-file index.js && babel src/lib/util.js --out-file lib/util.js && babel src/lib/get-bili-data.js --out-file lib/get-bili-data.js && babel src/lib/get-bgm-data.js --out-file lib/get-bgm-data.js && babel src/lib/get-bgmv0-data.js --out-file lib/get-bgmv0-data.js && babel src/lib/bangumi-generator.js --out-file lib/bangumi-generator.js && babel src/lib/templates/index.js --out-file lib/templates/index.js --presets minify && babel --no-babelrc src/lib/templates/pagination.js --out-file lib/templates/pagination.js --presets minify && cleancss src/lib/templates/index.css -O2 -o lib/templates/index.css && cleancss --batch src/lib/templates/theme/*.css --batch-suffix .min -O2 -o lib/templates/theme/", "ejslint": "ejslint lib/templates/*.ejs" }, "author": "HCLonely ", diff --git a/src/index.js b/src/index.js index 8b73d60..ba81225 100644 --- a/src/index.js +++ b/src/index.js @@ -12,6 +12,7 @@ const log = typeof hexoLog.default === 'function' ? hexoLog.default({ }); const { getBiliData } = require('./lib/get-bili-data'); const { getBgmData } = require('./lib/get-bgm-data'); +const { getBgmv0Data } = require('./lib/get-bgmv0-data'); // eslint-disable-next-line no-var if (typeof URL !== 'function') var { URL } = require('url'); @@ -34,6 +35,14 @@ hexo.extend.generator.register('cinemas', function (locals) { } return require('./lib/bangumi-generator').call(this, locals, 'cinema'); }); + +hexo.extend.generator.register('games', function (locals) { + if (!this?.config?.game?.enable) { + return; + } + return require('./lib/bangumi-generator').call(this, locals, 'game'); +}); + hexo.extend.console.register('bangumi', 'Generate pages of bangumis for Hexo', options, function (args) { if (args.d) { if (fs.existsSync(path.join(this.source_dir, '/_data/bangumis.json'))) { @@ -55,6 +64,7 @@ hexo.extend.console.register('bangumi', 'Generate pages of bangumis for Hexo', o if (['bgm', 'bangumi'].includes(this.config.bangumi.source)) { getBgmData({ vmid: this.config.bangumi.vmid, + type: "bangumi", showProgress: this.config.bangumi.progress ?? true, sourceDir: this.source_dir, extraOrder: this.config.bangumi.extraOrder, @@ -64,6 +74,17 @@ hexo.extend.console.register('bangumi', 'Generate pages of bangumis for Hexo', o host: `${this.config.bangumi.source}.tv`, coverMirror: this.config.bangumi.coverMirror ?? '' }); + } else if (this.config.bangumi.source === 'bgmv0') { + getBgmv0Data({ + vmid: this.config.bangumi.vmid, + type: 2, + showProgress: this.config.bangumi.progress ?? true, + sourceDir: this.source_dir, + extraOrder: this.config.bangumi.extraOrder, + pagination: this.config.bangumi.pagination, + proxy: this.config.bangumi.proxy, + coverMirror: this.config.bangumi.coverMirror ?? '' + }); } else { getBiliData({ vmid: this.config.bangumi.vmid, @@ -73,7 +94,8 @@ hexo.extend.console.register('bangumi', 'Generate pages of bangumis for Hexo', o extraOrder: this.config.bangumi.extraOrder, pagination: this.config.bangumi.pagination, useWebp: this.config.bangumi.webp, - coverMirror: this.config.bangumi.coverMirror ?? '' + coverMirror: this.config.bangumi.coverMirror ?? '', + SESSDATA: typeof args.u === 'string' ? args.u : null }); } } else { @@ -112,3 +134,40 @@ hexo.extend.console.register('cinema', 'Generate pages of bilibili cinemas for H log.info('Unknown command, please use "hexo cinema -h" to see the available commands'); } }); + +hexo.extend.console.register('game', 'Generate pages of games for Hexo', options, function (args) { + if (args.d) { + if (fs.existsSync(path.join(this.source_dir, '/_data/games.json'))) { + fs.unlinkSync(path.join(this.source_dir, '/_data/games.json')); + log.info('Games data has been deleted'); + } + } else if (args.u) { + if (!this?.config?.game) { + log.info('Please add config to _config.yml'); + return; + } + if (!this.config.game.enable) { + return; + } + if (!this.config.game.vmid) { + log.info('Please add vmid to _config.yml'); + return; + } + if (this.config.game.source !== 'bgmv0') { + log.info(`${this.config.bangumi.source} not support`); + return; + } + getBgmv0Data({ + vmid: this.config.game.vmid, + type: 4, + showProgress: this.config.game.progress ?? true, + sourceDir: this.source_dir, + extraOrder: this.config.game.extraOrder, + pagination: this.config.game.pagination, + proxy: this.config.game.proxy, + coverMirror: this.config.game.coverMirror ?? '' + }); + } else { + log.info('Unknown command, please use "hexo game -h" to see the available commands'); + } +}); diff --git a/src/lib/bangumi-generator.js b/src/lib/bangumi-generator.js index 3e7afb1..099e41c 100644 --- a/src/lib/bangumi-generator.js +++ b/src/lib/bangumi-generator.js @@ -79,7 +79,7 @@ module.exports = async function (locals, type = 'bangumi') { showMyComment: config[type].showMyComment ?? false, pagination: config[type].pagination ?? false, theme: fs.existsSync(path.join(__dirname, `templates/theme/${config.theme}.min.css`)) ? config.theme : null, - ejsTemplate: fs.readFileSync(path.join(__dirname, `templates/${config[type].source === 'bili' ? 'bili' : 'bgm'}-template.ejs`)).toString() + ejsTemplate: fs.readFileSync(path.join(__dirname, `templates/${config[type].source === 'bili' ? 'bili' : (config[type].source === 'bgmv0' ? 'bgmv0' : 'bgm')}-template.ejs`)).toString() .replace('class="bangumi-item"', 'class="bangumi-item bangumi-hide"'), wantWatch: ['score', '-score'].includes(config[type].order) ? wantWatch.sort((a, b) => (config[type].order === 'score' ? (a.score - b.score) : (b.score - a.score))) : wantWatch, watched: ['score', '-score'].includes(config[type].order) ? watched.sort((a, b) => (config[type].order === 'score' ? (a.score - b.score) : (b.score - a.score))) : watched, diff --git a/src/lib/get-bgm-data.js b/src/lib/get-bgm-data.js index b06a9ea..e1ff441 100644 --- a/src/lib/get-bgm-data.js +++ b/src/lib/get-bgm-data.js @@ -211,7 +211,7 @@ const getBangumiDataFromBangumiApi = async (items, sourceDir, proxy, coverMirror }; }); -const getItemsId = async ({ vmid, status, showProgress, sourceDir, proxy, infoApi, host, coverMirror }) => { +const getItemsId = async ({ vmid, type, status, showProgress, sourceDir, proxy, infoApi, host, coverMirror }) => { const getBangumiData = infoApi === 'bgmSub' ? getBangumiDataFromBangumiSubject : getBangumiDataFromBangumiApi; const items = []; @@ -230,8 +230,8 @@ const getItemsId = async ({ vmid, status, showProgress, sourceDir, proxy, infoAp }); } - const response = await axios.get(`https://${host}/anime/list/${vmid}/${status}?page=1`, options); - const username = response.request.path.match(/anime\/list\/(.*?)\//)?.[1]; + const response = await axios.get(`https://${host}/${type}/list/${vmid}/${status}?page=1`, options); + const username = response.request.path.match(/(anime|game)\/list\/(.*?)\//)?.[1]; if (!username) { return console.error('Failed to get "username"!'); } @@ -259,7 +259,7 @@ const getItemsId = async ({ vmid, status, showProgress, sourceDir, proxy, infoAp if (showProgress) { // eslint-disable-next-line no-nested-ternary - bar = new ProgressBar(`正在获取 ${status === 'wish' ? '[想看]' : (status === 'do' ? '[在看]' : '[已看]')} 番剧 [:bar] :percent :elapseds`, + bar = new ProgressBar(`正在获取 ${status === 'wish' ? '[想看]' : (status === 'do' ? '[在看]' : '[已看]')} ${type === 'game' ? '游戏' : '番剧'} [:bar] :percent :elapseds`, { total: pageNum < 2 ? 1 : pageNum, complete: '█' }); bar.tick(); } @@ -270,7 +270,7 @@ const getItemsId = async ({ vmid, status, showProgress, sourceDir, proxy, infoAp // eslint-disable-next-line no-plusplus for (let i = 2; i <= pageNum; i++) { if (showProgress) bar.tick(); - const response = await axios.get(`https://${host}/anime/list/${username}/${status}?page=${i}`, { + const response = await axios.get(`https://${host}/${type}/list/${username}/${status}?page=${i}`, { ...options, 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36 Edg/97.0.1072.69' }); @@ -296,31 +296,35 @@ const getItemsId = async ({ vmid, status, showProgress, sourceDir, proxy, infoAp return items; }; -module.exports.getBgmData = async function getBgmData({ vmid, showProgress, sourceDir, extraOrder, pagination, proxy, infoApi, host, coverMirror }) { +module.exports.getBgmData = async function getBgmData({ vmid, type, showProgress, sourceDir, extraOrder, pagination, proxy, infoApi, host, coverMirror }) { log.info('Getting bangumis, please wait...'); + const typePathMap = { + bangumi: 'anime', + game: 'game' + }; const startTime = new Date().getTime(); - const wantWatch = await getItemsId({ vmid, status: 'wish', showProgress, sourceDir, proxy, infoApi, host, coverMirror }); - const watching = await getItemsId({ vmid, status: 'do', showProgress, sourceDir, proxy, infoApi, host, coverMirror }); - const watched = await getItemsId({ vmid, status: 'collect', showProgress, sourceDir, proxy, infoApi, host, coverMirror }); + const wantWatch = await getItemsId({ vmid, type: typePathMap[type], status: 'wish', showProgress, sourceDir, proxy, infoApi, host, coverMirror }); + const watching = await getItemsId({ vmid, type: typePathMap[type], status: 'do', showProgress, sourceDir, proxy, infoApi, host, coverMirror }); + const watched = await getItemsId({ vmid, type: typePathMap[type], status: 'collect', showProgress, sourceDir, proxy, infoApi, host, coverMirror }); const endTime = new Date().getTime(); - log.info(`${wantWatch.length + watching.length + watched.length} bangumis have been loaded in ${endTime - startTime} ms`); + log.info(`${wantWatch.length + watching.length + watched.length} ${type}s have been loaded in ${endTime - startTime} ms`); const bangumis = { wantWatch, watching, watched }; if (!fs.existsSync(path.join(sourceDir, '/_data/'))) { fs.mkdirsSync(path.join(sourceDir, '/_data/')); } - fs.writeFile(path.join(sourceDir, '/_data/bangumis.json'), JSON.stringify(bangumis), (err) => { + fs.writeFile(path.join(sourceDir, `/_data/${type}s.json`), JSON.stringify(bangumis), (err) => { if (err) { - log.info('Failed to write data to _data/bangumis.json'); + log.info(`Failed to write data to _data/${type}s.json`); console.error(err); } else { - log.info('Bangumi bangumis data has been saved'); + log.info(`Bangumi ${type}s data has been saved`); } }); if (pagination) { const allBangumis = { ...bangumis }; // extra bangumis - if (fs.existsSync(path.join(sourceDir, '/_data/extra_bangumis.json'))) { + if (fs.existsSync(path.join(sourceDir, `/_data/extra_${type}s.json`))) { const { wantWatchExtra, watchingExtra, watchedExtra } = JSON.parse(fs.readFileSync(path.join(this.source_dir, `/_data/extra_${type}s.json`))); if (wantWatchExtra) { if (extraOrder === 1) { @@ -344,12 +348,12 @@ module.exports.getBgmData = async function getBgmData({ vmid, showProgress, sour } } } - fs.writeFile(path.join(sourceDir, '/bangumis.json'), JSON.stringify(allBangumis), (err) => { + fs.writeFile(path.join(sourceDir, `/${type}s.json`), JSON.stringify(allBangumis), (err) => { if (err) { - log.info('Failed to write data to bangumis.json'); + log.info(`Failed to write data to ${type}s.json`); console.error(err); } else { - log.info('Bangumi bangumis data has been saved'); + log.info(`Bangumi ${type}s data has been saved`); } }); } diff --git a/src/lib/get-bgmv0-data.js b/src/lib/get-bgmv0-data.js new file mode 100644 index 0000000..7ab28e3 --- /dev/null +++ b/src/lib/get-bgmv0-data.js @@ -0,0 +1,139 @@ +const fs = require('hexo-fs'); +const path = require('path'); +const axios = require('axios'); +const hexoLog = require('hexo-log'); +const log = typeof hexoLog.default === 'function' ? hexoLog.default({ + debug: false, + silent: false +}) : hexoLog({ + debug: false, + silent: false +}); +const ProgressBar = require('progress'); + +const TYPE = { + 1: '书籍', + 2: '动画', + 3: '音乐', + 4: '游戏', + 6: '三次元' +}; +const getDataPage = async (vmid, status, typeNum) => { + const response = await axios.get(`http://api.bgm.tv/v0/users/${vmid}/collections?subject_type=${typeNum}&type=${status}&limit=1&offset=0`, {headers: { + 'User-Agent': 'HCLonely/hexo-bilibili-bangumi' + }}); + if (typeof response?.data?.total !== 'undefined') { + return { success: true, data: Math.ceil(response.data.total / 30) + 1 }; + } else if (response && response.data) { + return { success: false, data: response.data }; + } + return { success: false, data: response }; +}; +const getData = async (vmid, status, typeNum, pn, coverMirror) => { + const response = await axios.get(`http://api.bgm.tv/v0/users/${vmid}/collections?subject_type=${typeNum}&type=${status}&limit=30&offset=${pn}`, { + headers: { + 'User-Agent': 'HCLonely/hexo-bilibili-bangumi' + } + }); + const $data = []; + if (response?.status === 200) { + const list = response?.data?.data || []; + for (const bangumi of list) { + $data.push({ + title: bangumi?.subject?.name_cn || bangumi?.subject?.name, + type: TYPE[bangumi?.subject_type || bangumi?.type] || '未知', + cover: coverMirror + bangumi?.subject?.images?.common, + totalCount: bangumi?.subject?.eps, + id: bangumi?.subject_id || bangumi?.subject?.id, + score: bangumi?.subject?.score ?? '-', + des: `${bangumi?.subject?.short_summary?.trim()}...` || '-', + collect: bangumi?.subject?.collection_total || '-', + myComment: bangumi.comment || '-', + progress: Math.round(((bangumi?.ep_status || 0) / (bangumi?.subject?.eps || 1)) * 100), + tags: bangumi?.subject?.tags?.[0]?.name || '-', + ep_status: bangumi?.ep_status || 0 + }); + } + return $data; + } +}; +const processData = async (vmid, status, showProgress, typeNum, coverMirror) => { + const page = await getDataPage(vmid, status, typeNum); + if (page?.success) { + const list = []; + let bar = null; + if (showProgress) { + // eslint-disable-next-line no-nested-ternary + bar = new ProgressBar(`正在获取 ${status === 1 ? `${typeNum === 4 ? '[想玩]' : '[想看]'}` : + status === 2 ? `${typeNum === 4 ? '[已玩]' : '[已看]'}` : + `${typeNum === 4 ? '[在玩]' : '[在看]'}`} ${TYPE[typeNum]} [:bar] :percent :elapseds`, { total: page.data - 1, complete: '█' }); + } + // eslint-disable-next-line no-plusplus + for (let i = 1; i < page.data; i++) { + if (showProgress) bar.tick(); + const data = await getData(vmid, status, typeNum, (i-1)*30, coverMirror); + list.push(...data); + } + return list; + } + console.log(`Get ${typeNum === 2 ? 'bangumi' : 'game'} data error:`, page?.data); + return []; +}; +module.exports.getBgmv0Data = async ({ vmid, type, showProgress, sourceDir, extraOrder, pagination, coverMirror }) => { + log.info(`Getting bgm ${type === 2 ? 'bangumi' : 'game'} data, please wait...`); + const startTime = new Date().getTime(); + const wantWatch = await processData(vmid, 1, showProgress, type, coverMirror); + const watching = await processData(vmid, 3, showProgress, type, coverMirror); + const watched = await processData(vmid, 2, showProgress, type, coverMirror); + const endTime = new Date().getTime(); + log.info(`${wantWatch.length + watching.length + watched.length} ${type}s have been loaded in ${endTime - startTime} ms`); + const bangumis = { wantWatch, watching, watched }; + if (!fs.existsSync(path.join(sourceDir, '/_data/'))) { + fs.mkdirsSync(path.join(sourceDir, '/_data/')); + } + fs.writeFile(path.join(sourceDir, `/_data/${type === 2 ? 'bangumi' : 'game'}s.json`), JSON.stringify(bangumis), (err) => { + if (err) { + log.info(`Failed to write data to _data/${type === 2 ? 'bangumi' : 'game'}s.json`); + console.error(err); + } else { + log.info(`Bgm ${type === 2 ? 'bangumi' : 'game'}s data has been saved`); + } + }); + + if (pagination) { + const allBangumis = { ...bangumis }; + // extra bangumis + if (fs.existsSync(path.join(sourceDir, `/_data/extra_${type === 2 ? 'bangumi' : 'game'}s.json`))) { + const { wantWatchExtra, watchingExtra, watchedExtra } = JSON.parse(fs.readFileSync(path.join(this.source_dir, `/_data/extra_${type === 2 ? 'bangumi' : 'game'}s.json`))); + if (wantWatchExtra) { + if (extraOrder === 1) { + allBangumis.wantWatch = [...wantWatchExtra, ...allBangumis.wantWatch]; + } else { + allBangumis.wantWatch = [...allBangumis.wantWatch, ...wantWatchExtra]; + } + } + if (watchingExtra) { + if (extraOrder === 1) { + allBangumis.watching = [...watchingExtra, ...allBangumis.watching]; + } else { + allBangumis.watching = [...allBangumis.watching, ...watchingExtra]; + } + } + if (watchedExtra) { + if (extraOrder === 1) { + allBangumis.watched = [...watchedExtra, ...allBangumis.watched]; + } else { + allBangumis.watched = [...allBangumis.watched, ...watchedExtra]; + } + } + } + fs.writeFile(path.join(sourceDir, `/${type === 2 ? 'bangumi' : 'game'}s.json`), JSON.stringify(bangumis), (err) => { + if (err) { + log.info(`Failed to write data to ${type === 2 ? 'bangumi' : 'game'}s.json`); + console.error(err); + } else { + log.info(`Bgm ${type === 2 ? 'bangumi' : 'game'}s data has been saved`); + } + }); + } +}; diff --git a/src/lib/get-bili-data.js b/src/lib/get-bili-data.js index efead53..52bc192 100644 --- a/src/lib/get-bili-data.js +++ b/src/lib/get-bili-data.js @@ -22,8 +22,12 @@ const getDataPage = async (vmid, status, typeNum) => { } return { success: false, data: response }; }; -const getData = async (vmid, status, useWebp, typeNum, pn, coverMirror) => { - const response = await axios.get(`https://api.bilibili.com/x/space/bangumi/follow/list?type=${typeNum}&follow_status=${status}&vmid=${vmid}&ps=30&pn=${pn}`); +const getData = async (vmid, status, useWebp, typeNum, pn, coverMirror, SESSDATA) => { + const response = await axios.get(`https://api.bilibili.com/x/space/bangumi/follow/list?type=${typeNum}&follow_status=${status}&vmid=${vmid}&ps=30&pn=${pn}`, { + headers: { + cookie: `SESSDATA=${SESSDATA};` + } + }); const $data = []; if (response?.data?.code === 0) { const data = response?.data?.data; @@ -48,7 +52,10 @@ const getData = async (vmid, status, useWebp, typeNum, pn, coverMirror) => { danmaku: count(bangumi?.stat?.danmaku), coin: count(bangumi.stat.coin), score: bangumi?.rating?.score ?? '-', - des: bangumi?.evaluate + des: bangumi?.evaluate, + progress: !SESSDATA ? false : Math.round(((parseInt(bangumi?.progress.match(/\d+/)?.[0] || '0', 10) || 0) / (bangumi?.total_count > 0 ? bangumi.total_count : (bangumi.new_ep?.title || 1))) * 100), + ep_status: !SESSDATA ? false : (parseInt(bangumi?.progress.match(/\d+/)?.[0] || '0', 10) || 0), + new_ep: bangumi?.total_count > 0 ? bangumi.total_count : (bangumi.new_ep?.title || -1) }); } return $data; @@ -60,7 +67,7 @@ const count = (e) => (e ? (e > 10000 && e < 100000000 ? `${(e / 10000).toFixed( // eslint-disable-next-line no-nested-ternary const total = (e, typeNum) => (e ? (e === -1 ? '未完结' : `全${e}${typeNum === 1 ? '话' : '集'}`) : '-'); -const processData = async (vmid, status, useWebp, showProgress, typeNum, coverMirror) => { +const processData = async(vmid, status, useWebp, showProgress, typeNum, coverMirror, SESSDATA) => { const page = await getDataPage(vmid, status, typeNum); if (page?.success) { const list = []; @@ -72,7 +79,7 @@ const processData = async (vmid, status, useWebp, showProgress, typeNum, coverMi // eslint-disable-next-line no-plusplus for (let i = 1; i < page.data; i++) { if (showProgress) bar.tick(); - const data = await getData(vmid, status, useWebp, typeNum, i, coverMirror); + const data = await getData(vmid, status, useWebp, typeNum, i, coverMirror, SESSDATA); list.push(...data); } return list; @@ -80,13 +87,13 @@ const processData = async (vmid, status, useWebp, showProgress, typeNum, coverMi console.log(`Get ${typeNum === 1 ? 'bangumi' : 'cinema'} data error:`, page?.data); return []; }; -module.exports.getBiliData = async ({ vmid, type, showProgress, sourceDir, extraOrder, pagination, useWebp = true, coverMirror }) => { +module.exports.getBiliData = async ({ vmid, type, showProgress, sourceDir, extraOrder, pagination, useWebp = true, coverMirror, SESSDATA }) => { const typeNum = type === 'cinema' ? 2 : 1; log.info(`Getting bilibili ${type}, please wait...`); const startTime = new Date().getTime(); - const wantWatch = await processData(vmid, 1, useWebp, showProgress, typeNum, coverMirror); - const watching = await processData(vmid, 2, useWebp, showProgress, typeNum, coverMirror); - const watched = await processData(vmid, 3, useWebp, showProgress, typeNum, coverMirror); + const wantWatch = await processData(vmid, 1, useWebp, showProgress, typeNum, coverMirror, SESSDATA); + const watching = await processData(vmid, 2, useWebp, showProgress, typeNum, coverMirror, SESSDATA); + const watched = await processData(vmid, 3, useWebp, showProgress, typeNum, coverMirror, SESSDATA); const endTime = new Date().getTime(); log.info(`${wantWatch.length + watching.length + watched.length} ${type}s have been loaded in ${endTime - startTime} ms`); const bangumis = { wantWatch, watching, watched }; diff --git a/src/lib/templates/index.css b/src/lib/templates/index.css index 773da1c..007f4b7 100644 --- a/src/lib/templates/index.css +++ b/src/lib/templates/index.css @@ -94,6 +94,7 @@ a.bangumi-tab { .bangumi-title { font-size: 18px; + font-weight: bold; } .bangumi-title a { @@ -277,3 +278,29 @@ a.bangumi-tab { .bangumi-starlight.stars10 { width: 50px; } + +.bangumi-info .bangumi-progress { + width: 100%; + height: 24px; + background-color: #f2f2f2; + border-radius: 5px; + overflow: hidden; + font-size: 16px; + text-align: center; + position: relative; +} +.bangumi-info .bangumi-progress-text { + z-index: 100; + position: relative; + color: #3c4858; + line-height: 24px; +} + +.bangumi-info .bangumi-progress .progress-bar { + z-index: 50; + height: 100%; + background-color: #007bffad; + border-radius: 5px; + position: absolute; + top: 0; +} diff --git a/src/lib/util.js b/src/lib/util.js index ada1447..af60c6e 100644 --- a/src/lib/util.js +++ b/src/lib/util.js @@ -13,7 +13,22 @@ i18n.set('en', { prev: 'Prev', next: 'Next', top: 'Top', - end: 'End' + end: 'End', + wantPlay: 'Wish', + playing: 'Playing', + played: 'Played', + type: 'Type', + tag: 'Tags', + score: 'Score', + follow: 'Follow', + summary: 'Summary', + comment: 'My Comment', + noSummary: 'No Summary', + unknown: 'Unknown', + view: 'Views', + coin: 'Coins', + danmaku: 'Danmaku', + myScore: 'My Score' // Added myScore translation }); i18n.set('zh-TW', { @@ -23,7 +38,22 @@ i18n.set('zh-TW', { prev: '上一頁', next: '下一頁', top: '首頁', - end: '尾頁' + end: '尾頁', + wantPlay: '想玩', + playing: '在玩', + played: '玩過', + type: '類型', + tag: '標籤', + score: '評分', + follow: '關注', + summary: '簡介', + comment: '我的評價', + noSummary: '暫無簡介', + unknown: '未知', + view: '總播放', + coin: '硬幣', + danmaku: '彈幕', + myScore: '我的評分' // Added myScore translation }); i18n.set('zh-Hans', { @@ -33,7 +63,22 @@ i18n.set('zh-Hans', { prev: '上一页', next: '下一页', top: '首页', - end: '尾页' + end: '尾页', + wantPlay: '想玩', + playing: '在玩', + played: '玩过', + type: '类型', + tag: '标签', + score: '评分', + follow: '关注', + summary: '简介', + comment: '我的评价', + noSummary: '暂无简介', + unknown: '未知', + view: '总播放', + coin: '硬币', + danmaku: '弹幕', + myScore: '我的评分' // Added myScore translation }); i18n.set('zh-CN', { @@ -43,7 +88,22 @@ i18n.set('zh-CN', { prev: '上一页', next: '下一页', top: '首页', - end: '尾页' + end: '尾页', + wantPlay: '想玩', + playing: '在玩', + played: '玩过', + type: '类型', + tag: '标签', + score: '评分', + follow: '关注', + summary: '简介', + comment: '我的评价', + noSummary: '暂无简介', + unknown: '未知', + view: '总播放', + coin: '硬币', + danmaku: '弹幕', + myScore: '我的评分' // Added myScore translation }); module.exports.i18n = i18n;