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 @@ <% } %>
简介:<%= item.des || "暂无简介" %>
<%= __('summary') %>:<%= item.des || __('noSummary') %>
简介:<%= item.des || "暂无简介" %>
+<%= __('summary') %>:<%= item.des || __('noSummary') %>
<% if (showMyComment && item.myComment) { %> -- 我的评价:<%= item.myComment %> + <%= __('comment') %>:<%= item.myComment %>
<%= __('summary') %>:<%= item.des || __('noSummary') %>
+ <% if (showMyComment && item.myComment) { %> + <%= __('comment') %>:<%= item.myComment %> +