bgmt 0.0.11 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -0
- package/dist/cdn.cjs +22 -0
- package/dist/cdn.d.cts +25 -0
- package/dist/cdn.d.mts +25 -0
- package/dist/cdn.mjs +19 -0
- package/dist/index.cjs +123 -3
- package/dist/index.d.cts +3847 -2
- package/dist/index.d.mts +3847 -2
- package/dist/index.mjs +118 -2
- package/dist/types-CDKF8vJi.d.mts +31 -0
- package/dist/types-qUxe1mrZ.d.cts +31 -0
- package/package.json +14 -7
- package/dist/index.d.ts +0 -3
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,119 @@
|
|
|
1
|
-
|
|
1
|
+
import { fullToHalf, tradToSimple } from "simptrad";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
//#region src/utils/tags.ts
|
|
4
|
+
const MERGE_TAGS = [
|
|
5
|
+
["漫改", "漫画改"],
|
|
6
|
+
["轻改", "轻小说改"],
|
|
7
|
+
["东映アニメーション", "东映动画"],
|
|
8
|
+
["TV", "TVA"]
|
|
9
|
+
];
|
|
10
|
+
const REMOVE_TAGS = new Set([
|
|
11
|
+
"未定档",
|
|
12
|
+
"未确定",
|
|
13
|
+
"日本",
|
|
14
|
+
"日本动画"
|
|
15
|
+
]);
|
|
16
|
+
function normalizeTags(tags, options = {}) {
|
|
17
|
+
const merged = mergeSimpleTags(tags.filter((t) => !REMOVE_TAGS.has(t.name)));
|
|
18
|
+
return (options.count ? merged.filter((t) => t.count >= options.count) : merged).map((t) => t.name).sort();
|
|
19
|
+
}
|
|
20
|
+
function mergeSimpleTags(tags) {
|
|
21
|
+
const map = /* @__PURE__ */ new Map();
|
|
22
|
+
for (const t of tags) {
|
|
23
|
+
if (/(19|20)\d{2}(春|夏|秋|冬)/.test(t.name)) {
|
|
24
|
+
if (t.name.includes("春")) t.name = t.name.replace("春", "年4月");
|
|
25
|
+
else if (t.name.includes("夏")) t.name = t.name.replace("夏", "年7月");
|
|
26
|
+
else if (t.name.includes("秋")) t.name = t.name.replace("秋", "年10月");
|
|
27
|
+
else if (t.name.includes("冬")) t.name = t.name.replace("冬", "年1月");
|
|
28
|
+
}
|
|
29
|
+
if (/(19|20)\d{2}年(春|夏|秋|冬)/.test(t.name)) {
|
|
30
|
+
if (t.name.includes("春")) t.name = t.name.replace("春", "4月");
|
|
31
|
+
else if (t.name.includes("夏")) t.name = t.name.replace("夏", "7月");
|
|
32
|
+
else if (t.name.includes("秋")) t.name = t.name.replace("秋", "10月");
|
|
33
|
+
else if (t.name.includes("冬")) t.name = t.name.replace("冬", "1月");
|
|
34
|
+
}
|
|
35
|
+
if (/(19|20)\d{2}?|\d{1,2}月/.test(t.name)) {
|
|
36
|
+
let target = t.name;
|
|
37
|
+
for (const tt of tags) if (tt.name.indexOf(t.name) !== -1 && tt.name.length > target.length) target = tt.name;
|
|
38
|
+
t.name = target;
|
|
39
|
+
}
|
|
40
|
+
const name0 = t.name;
|
|
41
|
+
const name1 = fullToHalf(tradToSimple(name0), { punctuation: true });
|
|
42
|
+
const name = MERGE_TAGS.find((arr) => arr.includes(name1))?.[0] ?? name1;
|
|
43
|
+
map.set(name, (map.get(name) ?? 0) + t.count);
|
|
44
|
+
}
|
|
45
|
+
return [...map.entries()].map(([k, v]) => ({
|
|
46
|
+
name: k,
|
|
47
|
+
count: v
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/utils/season.ts
|
|
53
|
+
const REs = [
|
|
54
|
+
/(?:S|Season|season\s?)(\d+)$/,
|
|
55
|
+
/(1st|2nd|3rd|[456789]th) Season$/,
|
|
56
|
+
/第?(\d+)[季期]$/,
|
|
57
|
+
/第?((?:[零一二三四五六七八九]十|十)?[零一二三四五六七八九])[季期]$/,
|
|
58
|
+
/\((?:19|20)\d{2}\)$/
|
|
59
|
+
];
|
|
60
|
+
function trimSeason(bgm) {
|
|
61
|
+
let changed = false;
|
|
62
|
+
function trim(t) {
|
|
63
|
+
for (const RE of REs) {
|
|
64
|
+
const match = RE.exec(t);
|
|
65
|
+
if (match) {
|
|
66
|
+
changed = true;
|
|
67
|
+
return t.slice(0, t.length - match[0].length).trimEnd();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const trimmed = bgm.alias.map(trim);
|
|
72
|
+
trimmed.push(trim(bgm.name));
|
|
73
|
+
const original = [...new Set(trimmed.filter(Boolean))].sort();
|
|
74
|
+
if (original.length === bgm.alias.length && !changed) return {
|
|
75
|
+
name: bgm.name,
|
|
76
|
+
original: void 0
|
|
77
|
+
};
|
|
78
|
+
return {
|
|
79
|
+
name: bgm.name,
|
|
80
|
+
original
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/utils/title.ts
|
|
86
|
+
function normalizeTitle(t) {
|
|
87
|
+
return fullToHalf(tradToSimple(t), { punctuation: true });
|
|
88
|
+
}
|
|
89
|
+
function getSubjectDisplayName(bgm) {
|
|
90
|
+
return bgm?.name_cn || bgm?.name || "";
|
|
91
|
+
}
|
|
92
|
+
function getSubjectInfoboxArray(infobox) {
|
|
93
|
+
return Array.isArray(infobox?.value) ? infobox?.value.map((v) => v?.v).filter(Boolean) ?? [] : typeof infobox?.value === "string" ? [infobox.value] : [];
|
|
94
|
+
}
|
|
95
|
+
function getSubjectAlias(subject) {
|
|
96
|
+
const translations = (subject.infobox?.filter((box) => [
|
|
97
|
+
"别名",
|
|
98
|
+
"中文名",
|
|
99
|
+
"英文名"
|
|
100
|
+
].includes(box.key)) ?? [])?.flatMap((box) => getSubjectInfoboxArray(box)) ?? [];
|
|
101
|
+
return [...new Set([
|
|
102
|
+
subject.name,
|
|
103
|
+
subject.name_cn,
|
|
104
|
+
...translations
|
|
105
|
+
].filter(Boolean).map(decodeSubjectTitle))].sort();
|
|
106
|
+
}
|
|
107
|
+
function decodeSubjectTitle(name) {
|
|
108
|
+
return name.replace(/"/g, "\"").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region src/utils/summary.ts
|
|
113
|
+
function normalizeSummary(text) {
|
|
114
|
+
if (!text) return "";
|
|
115
|
+
return text.trim().replace(/\u2028|\r\n/g, "\n");
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
//#endregion
|
|
119
|
+
export { decodeSubjectTitle, getSubjectAlias, getSubjectDisplayName, normalizeSummary, normalizeTags, normalizeTitle, trimSeason };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
type SubjectRating = {
|
|
3
|
+
score: number;
|
|
4
|
+
rank: number;
|
|
5
|
+
};
|
|
6
|
+
type SubjectImage = {
|
|
7
|
+
provider: 'bgm' | 'tmdb';
|
|
8
|
+
quality: string;
|
|
9
|
+
src: string;
|
|
10
|
+
};
|
|
11
|
+
type SubjectSearch = {
|
|
12
|
+
include: string[];
|
|
13
|
+
exclude?: string[] | null | undefined;
|
|
14
|
+
};
|
|
15
|
+
type BasicSubject = {
|
|
16
|
+
id: number;
|
|
17
|
+
title: string;
|
|
18
|
+
platform: string;
|
|
19
|
+
onair_date?: string | null | undefined;
|
|
20
|
+
rating: SubjectRating;
|
|
21
|
+
poster: string;
|
|
22
|
+
tags: string[];
|
|
23
|
+
search: SubjectSearch;
|
|
24
|
+
};
|
|
25
|
+
type FullSubject = BasicSubject & {
|
|
26
|
+
summary: string;
|
|
27
|
+
alias: string[];
|
|
28
|
+
images: SubjectImage[];
|
|
29
|
+
};
|
|
30
|
+
//#endregion
|
|
31
|
+
export { SubjectSearch as a, SubjectRating as i, FullSubject as n, SubjectImage as r, BasicSubject as t };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
type SubjectRating = {
|
|
3
|
+
score: number;
|
|
4
|
+
rank: number;
|
|
5
|
+
};
|
|
6
|
+
type SubjectImage = {
|
|
7
|
+
provider: 'bgm' | 'tmdb';
|
|
8
|
+
quality: string;
|
|
9
|
+
src: string;
|
|
10
|
+
};
|
|
11
|
+
type SubjectSearch = {
|
|
12
|
+
include: string[];
|
|
13
|
+
exclude?: string[] | null | undefined;
|
|
14
|
+
};
|
|
15
|
+
type BasicSubject = {
|
|
16
|
+
id: number;
|
|
17
|
+
title: string;
|
|
18
|
+
platform: string;
|
|
19
|
+
onair_date?: string | null | undefined;
|
|
20
|
+
rating: SubjectRating;
|
|
21
|
+
poster: string;
|
|
22
|
+
tags: string[];
|
|
23
|
+
search: SubjectSearch;
|
|
24
|
+
};
|
|
25
|
+
type FullSubject = BasicSubject & {
|
|
26
|
+
summary: string;
|
|
27
|
+
alias: string[];
|
|
28
|
+
images: SubjectImage[];
|
|
29
|
+
};
|
|
30
|
+
//#endregion
|
|
31
|
+
export { SubjectSearch as a, SubjectRating as i, FullSubject as n, SubjectImage as r, BasicSubject as t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bgmt",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Bangumi Data Toolkit",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bangumi",
|
|
@@ -20,9 +20,14 @@
|
|
|
20
20
|
"type": "module",
|
|
21
21
|
"exports": {
|
|
22
22
|
".": {
|
|
23
|
-
"
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
24
|
"import": "./dist/index.mjs",
|
|
25
|
-
"
|
|
25
|
+
"require": "./dist/index.cjs"
|
|
26
|
+
},
|
|
27
|
+
"./cdn": {
|
|
28
|
+
"types": "./dist/cdn.d.ts",
|
|
29
|
+
"import": "./dist/cdn.mjs",
|
|
30
|
+
"require": "./dist/cdn.cjs"
|
|
26
31
|
}
|
|
27
32
|
},
|
|
28
33
|
"main": "dist/index.cjs",
|
|
@@ -39,8 +44,10 @@
|
|
|
39
44
|
"files": [
|
|
40
45
|
"dist"
|
|
41
46
|
],
|
|
42
|
-
"dependencies": {
|
|
43
|
-
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"simptrad": "^0.2.0",
|
|
49
|
+
"bgmc": "0.0.12"
|
|
50
|
+
},
|
|
44
51
|
"engines": {
|
|
45
52
|
"node": ">=v20.8.0"
|
|
46
53
|
},
|
|
@@ -59,8 +66,8 @@
|
|
|
59
66
|
}
|
|
60
67
|
},
|
|
61
68
|
"scripts": {
|
|
62
|
-
"build": "
|
|
63
|
-
"format": "prettier --write src/**/*.ts test/**/*.ts",
|
|
69
|
+
"build": "tsdown",
|
|
70
|
+
"format": "prettier --write 'src/**/*.ts' 'test/**/*.ts'",
|
|
64
71
|
"release": "release-it",
|
|
65
72
|
"test": "vitest",
|
|
66
73
|
"test:ci": "vitest --run",
|
package/dist/index.d.ts
DELETED