Skip to content

Commit

Permalink
新增:获取bangumi用户的游戏列表(仅支持source: bgmv0)(#391);
Browse files Browse the repository at this point in the history
新增:追番进度条(仅支持`source: bgmv0`或`source: bili`, 使用bili源时需提供cookie, 具体看说明文档)(#454);
优化:i18n.
  • Loading branch information
HCLonely committed Jul 5, 2024
1 parent 9c55d50 commit 7903abf
Show file tree
Hide file tree
Showing 20 changed files with 906 additions and 120 deletions.
36 changes: 33 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ $ npm install hexo-bilibili-bangumi --save
bangumi: # 追番设置
enable: true
source: bili
bgmInfoSource: 'bgmApi'
bgmInfoSource: 'bgmv0'
path:
vmid:
title: '追番列表'
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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
Expand All @@ -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`
Expand Down
78 changes: 69 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -42,15 +44,22 @@ 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'))) {
fs.unlinkSync(path.join(this.source_dir, '/_data/bangumis.json'));
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;
}
Expand All @@ -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,
Expand All @@ -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 {
Expand All @@ -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;
}
Expand All @@ -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');
}
});
2 changes: 1 addition & 1 deletion lib/bangumi-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 7903abf

Please sign in to comment.