@otohime-site/parser 24.1.1 → 26.11.0
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 +20 -4
- package/dx_intl/index.d.ts +4 -2
- package/dx_intl/index.js +2 -2
- package/dx_intl/player.d.ts +3 -3
- package/dx_intl/player.js +26 -17
- package/dx_intl/scores.d.ts +18 -2
- package/dx_intl/scores.js +69 -33
- package/package.json +26 -25
- package/index.d.ts +0 -1
- package/index.js +0 -1
package/README.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
### The Otohime Parser
|
|
2
2
|
|
|
3
|
-
The parser will take the `
|
|
3
|
+
The parser will take the `Document` or text (parsing with `DOMParser`) and return an object for each function.
|
|
4
4
|
|
|
5
5
|
You need polyfill for `DOMParser` if you are not under browser environment.
|
|
6
6
|
|
|
7
7
|
#### Implemented parser
|
|
8
8
|
|
|
9
|
-
##### maimai
|
|
9
|
+
##### maimai
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
We do our best to support both the Japanese and International versions of maimai DX NET.
|
|
12
|
+
It is currently tested up to maimai DX MAGiCAL.
|
|
13
13
|
|
|
14
14
|
```js
|
|
15
15
|
// Providing text from https://maimaidx-eng.com/maimai-mobile/home/...
|
|
@@ -18,5 +18,21 @@ const player = parsePlayer(playerText)
|
|
|
18
18
|
|
|
19
19
|
// Providing text from https://maimaidx-eng.com/maimai-mobile/record/musicGenre/search/?genre=99&diff=3...
|
|
20
20
|
import { parseScores } from "@otohime-site/parser/dx_intl"
|
|
21
|
+
// Played charts only, typed as ScoresParseEntryWithScore[]
|
|
21
22
|
const scores = parseScores(scoresText)
|
|
23
|
+
// Also include unplayed charts, typed as ScoresParseEntry[]
|
|
24
|
+
const allScores = parseScores(scoresText, { includeUnplayed: true })
|
|
22
25
|
```
|
|
26
|
+
|
|
27
|
+
All functions and result types are exported from `@otohime-site/parser/dx_intl`:
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import type {
|
|
31
|
+
PlayerParseResult,
|
|
32
|
+
ScoresParseEntry,
|
|
33
|
+
ScoresParseEntryWithScore,
|
|
34
|
+
} from "@otohime-site/parser/dx_intl"
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Played score entries include `dx_score` and `max_dx_score`. `dx_score` can be 0
|
|
38
|
+
for charts that were only played before maimai DX.
|
package/dx_intl/index.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { parsePlayer } from "./player.js";
|
|
2
|
+
export type { PlayerParseResult, PlayerParseResultBase, PlayerParseResultLegacy, PlayerParseResultNew, } from "./player.js";
|
|
3
|
+
export { parseScores } from "./scores.js";
|
|
4
|
+
export type { ParseScoresOptions, ScoresParseEntry, ScoresParseEntryWithoutScore, ScoresParseEntryWithScore, } from "./scores.js";
|
package/dx_intl/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { parsePlayer } from "./player.js";
|
|
2
|
+
export { parseScores } from "./scores.js";
|
package/dx_intl/player.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
interface PlayerParseResultBase {
|
|
1
|
+
export interface PlayerParseResultBase {
|
|
2
2
|
card_name: string;
|
|
3
3
|
rating: number;
|
|
4
4
|
rating_legacy: boolean;
|
|
@@ -12,5 +12,5 @@ export interface PlayerParseResultNew extends PlayerParseResultBase {
|
|
|
12
12
|
course_rank: number;
|
|
13
13
|
class_rank: number;
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
export
|
|
15
|
+
export type PlayerParseResult = PlayerParseResultLegacy | PlayerParseResultNew;
|
|
16
|
+
export declare function parsePlayer(content: string | Document): PlayerParseResult;
|
package/dx_intl/player.js
CHANGED
|
@@ -7,28 +7,38 @@ const isLegacyRating = (rating, ref) => (ref === "green" && rating < 3000) ||
|
|
|
7
7
|
(ref === "silver" && rating < 13000) ||
|
|
8
8
|
(ref === "gold" && rating < 14000) ||
|
|
9
9
|
(ref === "rainbow" && rating < 15000);
|
|
10
|
-
|
|
11
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
|
|
10
|
+
export function parsePlayer(content) {
|
|
12
11
|
const document = typeof content === "string"
|
|
13
12
|
? new DOMParser().parseFromString(content, "text/html")
|
|
14
13
|
: content;
|
|
15
|
-
const cardName =
|
|
14
|
+
const cardName = document.querySelector(".name_block")?.textContent ?? "";
|
|
16
15
|
// On marquee mode, the title will use another HTML structure...
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
// Do not trim: a gold title consists of full-width spaces (U+3000), the
|
|
17
|
+
// officially listed name of the song by x0o0x_ known as "Kisaragi Station"
|
|
18
|
+
const title = document.querySelector(".trophy_inner_block > span, .trophy_inner_block > div > div")?.textContent ?? "";
|
|
19
|
+
const trophy = (document
|
|
20
|
+
.querySelector(".trophy_block")
|
|
21
|
+
?.className.match(/Normal|Bronze|Silver|Gold|Rainbow/) ?? [
|
|
20
22
|
"",
|
|
21
23
|
])[0].toLowerCase();
|
|
22
24
|
const ratingBlock = document.querySelector(".rating_block");
|
|
23
|
-
const rawRating =
|
|
24
|
-
const ratingImageRef = (
|
|
25
|
-
.querySelector('img[src *= "/img/rating_base_"]')
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
.querySelector('img[src *= "/img/
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
const rawRating = ratingBlock?.textContent ?? "";
|
|
26
|
+
const ratingImageRef = (document
|
|
27
|
+
.querySelector('img[src *= "/img/rating_base_"]')
|
|
28
|
+
?.getAttribute("src")
|
|
29
|
+
?.match(/_([a-z]+)\.png/) ?? ["", ""])[1];
|
|
30
|
+
const rawCourseRank = (document
|
|
31
|
+
.querySelector('img[src *= "/img/course/"]')
|
|
32
|
+
?.getAttribute("src")
|
|
33
|
+
?.match(/course_rank_([0-9]{2})/) ?? ["", ""])[1];
|
|
34
|
+
const rawClassRank = (document
|
|
35
|
+
.querySelector('img[src *= "/img/class/"]')
|
|
36
|
+
?.getAttribute("src")
|
|
37
|
+
?.match(/_([0-9]{2})/) ?? ["", ""])[1];
|
|
38
|
+
const rawGrade = (document
|
|
39
|
+
.querySelector('img[src *= "/img/grade_"]')
|
|
40
|
+
?.getAttribute("src")
|
|
41
|
+
?.match(/grade_([0-9]{2})/) ?? ["", ""])[1];
|
|
32
42
|
assertNonEmpty(cardName, "card_name");
|
|
33
43
|
assertNonEmpty(title, "title");
|
|
34
44
|
assertNonEmpty(trophy, "trophy");
|
|
@@ -78,5 +88,4 @@ const parsePlayer = (content) => {
|
|
|
78
88
|
course_rank: courseRank,
|
|
79
89
|
class_rank: classRank,
|
|
80
90
|
};
|
|
81
|
-
}
|
|
82
|
-
export default parsePlayer;
|
|
91
|
+
}
|
package/dx_intl/scores.d.ts
CHANGED
|
@@ -8,9 +8,25 @@ export interface ScoresParseEntryWithoutScore {
|
|
|
8
8
|
}
|
|
9
9
|
export interface ScoresParseEntryWithScore extends ScoresParseEntryWithoutScore {
|
|
10
10
|
score: number;
|
|
11
|
+
/** Can be 0 if the chart was only played before maimai DX */
|
|
12
|
+
dx_score: number;
|
|
13
|
+
/** Always a multiple of 3 (3 * total notes) */
|
|
14
|
+
max_dx_score: number;
|
|
11
15
|
combo_flag: "" | "fc" | "fc+" | "ap" | "ap+";
|
|
12
16
|
sync_flag: "" | "s" | "fs" | "fs+" | "fdx" | "fdx+";
|
|
13
17
|
}
|
|
14
18
|
export type ScoresParseEntry = ScoresParseEntryWithoutScore | ScoresParseEntryWithScore;
|
|
15
|
-
|
|
16
|
-
|
|
19
|
+
export interface ParseScoresOptions {
|
|
20
|
+
/** Number of categories (genres) expected on the page, default 6 */
|
|
21
|
+
categoryCount?: number;
|
|
22
|
+
/** Also return charts that are not played yet, default false */
|
|
23
|
+
includeUnplayed?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export declare function parseScores(content: string | Document, options?: ParseScoresOptions & {
|
|
26
|
+
includeUnplayed?: false;
|
|
27
|
+
}): ScoresParseEntryWithScore[];
|
|
28
|
+
export declare function parseScores(content: string | Document, options: ParseScoresOptions & {
|
|
29
|
+
includeUnplayed: true;
|
|
30
|
+
}): ScoresParseEntry[];
|
|
31
|
+
export declare function parseScores(content: string | Document, options?: ParseScoresOptions): ScoresParseEntry[];
|
|
32
|
+
export {};
|
package/dx_intl/scores.js
CHANGED
|
@@ -24,7 +24,7 @@ const LEVELS = [
|
|
|
24
24
|
"14+",
|
|
25
25
|
"15",
|
|
26
26
|
];
|
|
27
|
-
|
|
27
|
+
export function parseScores(content, { categoryCount = 6, includeUnplayed = false } = {}) {
|
|
28
28
|
const document = typeof content === "string"
|
|
29
29
|
? new DOMParser().parseFromString(content, "text/html")
|
|
30
30
|
: content;
|
|
@@ -37,18 +37,22 @@ const parseScores = (content, categoryTo = 6, withNoScore = false) => {
|
|
|
37
37
|
throw new Error("Cannot read scores!");
|
|
38
38
|
}
|
|
39
39
|
const { result } = entries.reduce((prev, curr) => {
|
|
40
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
41
40
|
if (curr.className.includes("screw_block")) {
|
|
42
41
|
// XXX: This assume none of the category will be skipped
|
|
43
|
-
return
|
|
42
|
+
return {
|
|
43
|
+
...prev,
|
|
44
|
+
currentCategory: prev.currentCategory + 1,
|
|
45
|
+
};
|
|
44
46
|
}
|
|
45
|
-
const rawMusicDifficulty = (
|
|
46
|
-
|
|
47
|
+
const rawMusicDifficulty = (curr.className?.match(/_(basic|advanced|expert|master|remaster)/) ??
|
|
48
|
+
curr
|
|
49
|
+
.querySelector("div")
|
|
50
|
+
?.className?.match(/_(basic|advanced|expert|master|remaster)/) ?? [
|
|
47
51
|
"",
|
|
48
52
|
"",
|
|
49
53
|
])[1];
|
|
50
54
|
const category = prev.currentCategory;
|
|
51
|
-
const title =
|
|
55
|
+
const title = curr.querySelector(".music_name_block")?.textContent ?? "";
|
|
52
56
|
const difficulty = [
|
|
53
57
|
"basic",
|
|
54
58
|
"advanced",
|
|
@@ -56,11 +60,12 @@ const parseScores = (content, categoryTo = 6, withNoScore = false) => {
|
|
|
56
60
|
"master",
|
|
57
61
|
"remaster",
|
|
58
62
|
].indexOf(rawMusicDifficulty);
|
|
59
|
-
const rawLevel =
|
|
63
|
+
const rawLevel = curr.querySelector(".music_lv_block")?.textContent ?? "";
|
|
60
64
|
// If only one type: determine by .music_kind_icon (standard.png vs dx.png)
|
|
61
65
|
// Two types: determine by id (sta_xx vs dx_xx)
|
|
62
|
-
const rawDeluxe =
|
|
63
|
-
|
|
66
|
+
const rawDeluxe = curr.querySelector(".music_kind_icon")?.getAttribute("src") ??
|
|
67
|
+
(curr.id.match(/sta|dx/) ?? [""])[0];
|
|
68
|
+
assertBetween(category, 1, categoryCount, "category");
|
|
64
69
|
assertNonEmpty(title, "title");
|
|
65
70
|
assertBetween(difficulty, 0, 4, "difficulty");
|
|
66
71
|
assertNonEmpty(rawDeluxe, "deluxe");
|
|
@@ -71,11 +76,21 @@ const parseScores = (content, categoryTo = 6, withNoScore = false) => {
|
|
|
71
76
|
throw new Error("Level is not matched!");
|
|
72
77
|
}
|
|
73
78
|
const level = LEVELS[levelIndex];
|
|
74
|
-
|
|
75
|
-
if
|
|
79
|
+
// First block: score (e.g. 100.5000%), second block: DX score (e.g. 1,343 / 1,479)
|
|
80
|
+
// Both blocks are absent if the chart is not played yet
|
|
81
|
+
const scoreBlocks = [
|
|
82
|
+
...curr.querySelectorAll(".music_score_block").values(),
|
|
83
|
+
];
|
|
84
|
+
const rawScore = (scoreBlocks[0]?.textContent ?? "")
|
|
85
|
+
.replace("%", "")
|
|
86
|
+
.trim();
|
|
87
|
+
const rawDxScore = (scoreBlocks[1]?.textContent ?? "").trim();
|
|
88
|
+
if (rawScore.length === 0 && rawDxScore.length === 0) {
|
|
76
89
|
// Skip if it is not played yet
|
|
77
|
-
return
|
|
78
|
-
?
|
|
90
|
+
return includeUnplayed
|
|
91
|
+
? {
|
|
92
|
+
...prev,
|
|
93
|
+
result: [
|
|
79
94
|
...prev.result,
|
|
80
95
|
{
|
|
81
96
|
category,
|
|
@@ -84,61 +99,82 @@ const parseScores = (content, categoryTo = 6, withNoScore = false) => {
|
|
|
84
99
|
difficulty,
|
|
85
100
|
level,
|
|
86
101
|
},
|
|
87
|
-
]
|
|
102
|
+
],
|
|
103
|
+
}
|
|
104
|
+
: { ...prev };
|
|
88
105
|
}
|
|
89
106
|
const score = parseFloat(rawScore);
|
|
90
107
|
assertBetween(score, 0, 101, "score");
|
|
108
|
+
const dxScoreMatches = rawDxScore
|
|
109
|
+
.replace(/,/g, "")
|
|
110
|
+
.match(/^(\d+)\s*\/\s*(\d+)$/);
|
|
111
|
+
if (dxScoreMatches === null) {
|
|
112
|
+
throw new Error("Cannot get the value of dx_score");
|
|
113
|
+
}
|
|
114
|
+
const dxScore = parseInt(dxScoreMatches[1], 10);
|
|
115
|
+
const maxDxScore = parseInt(dxScoreMatches[2], 10);
|
|
116
|
+
if (maxDxScore <= 0 || maxDxScore % 3 !== 0) {
|
|
117
|
+
throw new Error(`max_dx_score should be a positive multiple of 3, received: ${maxDxScore}`);
|
|
118
|
+
}
|
|
119
|
+
// dx_score can be 0 if the chart was only played before maimai DX
|
|
120
|
+
assertBetween(dxScore, 0, maxDxScore, "dx_score");
|
|
91
121
|
const flagImages = [...curr.querySelectorAll("img.f_r").values()];
|
|
92
122
|
const flags = flagImages.reduce((prevFlags, currFlagImg) => {
|
|
93
|
-
|
|
94
|
-
const comboMatches = ((_a = currFlagImg.getAttribute("src")) !== null && _a !== void 0 ? _a : "").match(/(fc|fcp|ap|app)\.png/);
|
|
123
|
+
const comboMatches = (currFlagImg.getAttribute("src") ?? "").match(/(fc|fcp|ap|app)\.png/);
|
|
95
124
|
if (comboMatches !== null) {
|
|
96
125
|
switch (comboMatches[1]) {
|
|
97
126
|
case "fc":
|
|
98
|
-
return
|
|
127
|
+
return { ...prevFlags, combo_flag: "fc" };
|
|
99
128
|
case "fcp":
|
|
100
|
-
return
|
|
129
|
+
return { ...prevFlags, combo_flag: "fc+" };
|
|
101
130
|
case "ap":
|
|
102
|
-
return
|
|
131
|
+
return { ...prevFlags, combo_flag: "ap" };
|
|
103
132
|
case "app":
|
|
104
|
-
return
|
|
133
|
+
return { ...prevFlags, combo_flag: "ap+" };
|
|
105
134
|
}
|
|
106
135
|
}
|
|
107
|
-
const syncMatches = (
|
|
136
|
+
const syncMatches = (currFlagImg.getAttribute("src") ?? "").match(/(sync|fs|fsp|fsd|fsdp|fdx|fdxp)\.png/);
|
|
108
137
|
if (syncMatches !== null) {
|
|
109
138
|
switch (syncMatches[1]) {
|
|
110
139
|
case "sync":
|
|
111
|
-
return
|
|
140
|
+
return { ...prevFlags, sync_flag: "s" };
|
|
112
141
|
case "fs":
|
|
113
|
-
return
|
|
142
|
+
return { ...prevFlags, sync_flag: "fs" };
|
|
114
143
|
case "fsp":
|
|
115
|
-
return
|
|
144
|
+
return { ...prevFlags, sync_flag: "fs+" };
|
|
116
145
|
case "fsd":
|
|
117
146
|
case "fdx":
|
|
118
|
-
return
|
|
147
|
+
return { ...prevFlags, sync_flag: "fdx" };
|
|
119
148
|
case "fsdp":
|
|
120
149
|
case "fdxp":
|
|
121
|
-
return
|
|
150
|
+
return { ...prevFlags, sync_flag: "fdx+" };
|
|
122
151
|
}
|
|
123
152
|
}
|
|
124
|
-
return
|
|
153
|
+
return { ...prevFlags };
|
|
125
154
|
}, {
|
|
126
155
|
combo_flag: "",
|
|
127
156
|
sync_flag: "",
|
|
128
157
|
});
|
|
129
|
-
return
|
|
158
|
+
return {
|
|
159
|
+
...prev,
|
|
160
|
+
result: [
|
|
130
161
|
...prev.result,
|
|
131
|
-
|
|
162
|
+
{
|
|
163
|
+
category,
|
|
132
164
|
title,
|
|
133
165
|
deluxe,
|
|
134
166
|
difficulty,
|
|
135
167
|
level,
|
|
136
|
-
score
|
|
137
|
-
|
|
168
|
+
score,
|
|
169
|
+
dx_score: dxScore,
|
|
170
|
+
max_dx_score: maxDxScore,
|
|
171
|
+
...flags,
|
|
172
|
+
},
|
|
173
|
+
],
|
|
174
|
+
};
|
|
138
175
|
}, {
|
|
139
176
|
result: [],
|
|
140
177
|
currentCategory: 0,
|
|
141
178
|
});
|
|
142
179
|
return result;
|
|
143
|
-
}
|
|
144
|
-
export default parseScores;
|
|
180
|
+
}
|
package/package.json
CHANGED
|
@@ -1,38 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@otohime-site/parser",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "26.11.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"types": "index.d.ts",
|
|
7
6
|
"homepage": "https://github.com/otohime-site/parser#readme",
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"./dx_intl/*": "./dx_intl/*.js"
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "github:otohime-site/parser"
|
|
12
10
|
},
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
"build": "rm -rf dist/ && tsc && cp README.md dist/ && jq 'del(.scripts.prepare)' package.json > dist/package.json"
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"exports": {
|
|
13
|
+
"./dx_intl": "./dx_intl/index.js"
|
|
17
14
|
},
|
|
18
15
|
"devDependencies": {
|
|
19
|
-
"@
|
|
20
|
-
"@
|
|
21
|
-
"
|
|
22
|
-
"eslint-
|
|
23
|
-
"eslint
|
|
24
|
-
"eslint-
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"typescript": "^5.3.3"
|
|
16
|
+
"@eslint/js": "^10.0.1",
|
|
17
|
+
"@types/node": "^26.6.6",
|
|
18
|
+
"@vitest/coverage-v8": "^5.1.1",
|
|
19
|
+
"@vitest/eslint-plugin": "^1.6.28",
|
|
20
|
+
"eslint": "^10.15.0",
|
|
21
|
+
"eslint-config-prettier": "^10.1.8",
|
|
22
|
+
"husky": "^9.1.7",
|
|
23
|
+
"jsdom": "^31.0.1",
|
|
24
|
+
"lint-staged": "^17.6.1",
|
|
25
|
+
"prettier": "^3.10.1",
|
|
26
|
+
"typescript": "^6.0.3",
|
|
27
|
+
"typescript-eslint": "^8.73.0",
|
|
28
|
+
"vitest": "^5.1.1"
|
|
33
29
|
},
|
|
34
30
|
"lint-staged": {
|
|
35
31
|
"*.js,*.ts": "eslint --cache --fix",
|
|
36
32
|
"*.{js,ts,css,md}": "prettier --write"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"lint": "eslint",
|
|
36
|
+
"test": "vitest run --coverage",
|
|
37
|
+
"build": "rm -rf dist/ && tsc && cp README.md dist/ && jq 'del(.scripts.prepare)' package.json > dist/package.json"
|
|
37
38
|
}
|
|
38
|
-
}
|
|
39
|
+
}
|
package/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|