@otohime-site/parser 24.1.1 → 26.4.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/dx_intl/player.js +22 -14
- package/dx_intl/scores.js +41 -27
- package/package.json +20 -21
package/dx_intl/player.js
CHANGED
|
@@ -8,27 +8,35 @@ const isLegacyRating = (rating, ref) => (ref === "green" && rating < 3000) ||
|
|
|
8
8
|
(ref === "gold" && rating < 14000) ||
|
|
9
9
|
(ref === "rainbow" && rating < 15000);
|
|
10
10
|
const parsePlayer = (content) => {
|
|
11
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
|
|
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
|
-
const title =
|
|
18
|
-
const trophy = (
|
|
19
|
-
.querySelector(".trophy_block")
|
|
16
|
+
const title = document.querySelector(".trophy_inner_block > span, .trophy_inner_block > div > div")?.textContent ?? "".trim();
|
|
17
|
+
const trophy = (document
|
|
18
|
+
.querySelector(".trophy_block")
|
|
19
|
+
?.className.match(/Normal|Bronze|Silver|Gold|Rainbow/) ?? [
|
|
20
20
|
"",
|
|
21
21
|
])[0].toLowerCase();
|
|
22
22
|
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
|
-
|
|
23
|
+
const rawRating = ratingBlock?.textContent ?? "";
|
|
24
|
+
const ratingImageRef = (document
|
|
25
|
+
.querySelector('img[src *= "/img/rating_base_"]')
|
|
26
|
+
?.getAttribute("src")
|
|
27
|
+
?.match(/_([a-z]+)\.png/) ?? ["", ""])[1];
|
|
28
|
+
const rawCourseRank = (document
|
|
29
|
+
.querySelector('img[src *= "/img/course/"]')
|
|
30
|
+
?.getAttribute("src")
|
|
31
|
+
?.match(/course_rank_([0-9]{2})/) ?? ["", ""])[1];
|
|
32
|
+
const rawClassRank = (document
|
|
33
|
+
.querySelector('img[src *= "/img/class/"]')
|
|
34
|
+
?.getAttribute("src")
|
|
35
|
+
?.match(/_([0-9]{2})/) ?? ["", ""])[1];
|
|
36
|
+
const rawGrade = (document
|
|
37
|
+
.querySelector('img[src *= "/img/grade_"]')
|
|
38
|
+
?.getAttribute("src")
|
|
39
|
+
?.match(/grade_([0-9]{2})/) ?? ["", ""])[1];
|
|
32
40
|
assertNonEmpty(cardName, "card_name");
|
|
33
41
|
assertNonEmpty(title, "title");
|
|
34
42
|
assertNonEmpty(trophy, "trophy");
|
package/dx_intl/scores.js
CHANGED
|
@@ -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,10 +60,11 @@ 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 =
|
|
66
|
+
const rawDeluxe = curr.querySelector(".music_kind_icon")?.getAttribute("src") ??
|
|
67
|
+
(curr.id.match(/sta|dx/) ?? [""])[0];
|
|
63
68
|
assertBetween(category, 1, categoryTo, "category");
|
|
64
69
|
assertNonEmpty(title, "title");
|
|
65
70
|
assertBetween(difficulty, 0, 4, "difficulty");
|
|
@@ -71,11 +76,13 @@ 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
|
-
const rawScore = (
|
|
79
|
+
const rawScore = (curr.querySelector(".music_score_block")?.textContent ?? "").replace("%", "");
|
|
75
80
|
if (rawScore.length === 0) {
|
|
76
81
|
// Skip if it is not played yet
|
|
77
82
|
return withNoScore
|
|
78
|
-
?
|
|
83
|
+
? {
|
|
84
|
+
...prev,
|
|
85
|
+
result: [
|
|
79
86
|
...prev.result,
|
|
80
87
|
{
|
|
81
88
|
category,
|
|
@@ -84,57 +91,64 @@ const parseScores = (content, categoryTo = 6, withNoScore = false) => {
|
|
|
84
91
|
difficulty,
|
|
85
92
|
level,
|
|
86
93
|
},
|
|
87
|
-
]
|
|
94
|
+
],
|
|
95
|
+
}
|
|
96
|
+
: { ...prev };
|
|
88
97
|
}
|
|
89
98
|
const score = parseFloat(rawScore);
|
|
90
99
|
assertBetween(score, 0, 101, "score");
|
|
91
100
|
const flagImages = [...curr.querySelectorAll("img.f_r").values()];
|
|
92
101
|
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/);
|
|
102
|
+
const comboMatches = (currFlagImg.getAttribute("src") ?? "").match(/(fc|fcp|ap|app)\.png/);
|
|
95
103
|
if (comboMatches !== null) {
|
|
96
104
|
switch (comboMatches[1]) {
|
|
97
105
|
case "fc":
|
|
98
|
-
return
|
|
106
|
+
return { ...prevFlags, combo_flag: "fc" };
|
|
99
107
|
case "fcp":
|
|
100
|
-
return
|
|
108
|
+
return { ...prevFlags, combo_flag: "fc+" };
|
|
101
109
|
case "ap":
|
|
102
|
-
return
|
|
110
|
+
return { ...prevFlags, combo_flag: "ap" };
|
|
103
111
|
case "app":
|
|
104
|
-
return
|
|
112
|
+
return { ...prevFlags, combo_flag: "ap+" };
|
|
105
113
|
}
|
|
106
114
|
}
|
|
107
|
-
const syncMatches = (
|
|
115
|
+
const syncMatches = (currFlagImg.getAttribute("src") ?? "").match(/(sync|fs|fsp|fsd|fsdp|fdx|fdxp)\.png/);
|
|
108
116
|
if (syncMatches !== null) {
|
|
109
117
|
switch (syncMatches[1]) {
|
|
110
118
|
case "sync":
|
|
111
|
-
return
|
|
119
|
+
return { ...prevFlags, sync_flag: "s" };
|
|
112
120
|
case "fs":
|
|
113
|
-
return
|
|
121
|
+
return { ...prevFlags, sync_flag: "fs" };
|
|
114
122
|
case "fsp":
|
|
115
|
-
return
|
|
123
|
+
return { ...prevFlags, sync_flag: "fs+" };
|
|
116
124
|
case "fsd":
|
|
117
125
|
case "fdx":
|
|
118
|
-
return
|
|
126
|
+
return { ...prevFlags, sync_flag: "fdx" };
|
|
119
127
|
case "fsdp":
|
|
120
128
|
case "fdxp":
|
|
121
|
-
return
|
|
129
|
+
return { ...prevFlags, sync_flag: "fdx+" };
|
|
122
130
|
}
|
|
123
131
|
}
|
|
124
|
-
return
|
|
132
|
+
return { ...prevFlags };
|
|
125
133
|
}, {
|
|
126
134
|
combo_flag: "",
|
|
127
135
|
sync_flag: "",
|
|
128
136
|
});
|
|
129
|
-
return
|
|
137
|
+
return {
|
|
138
|
+
...prev,
|
|
139
|
+
result: [
|
|
130
140
|
...prev.result,
|
|
131
|
-
|
|
141
|
+
{
|
|
142
|
+
category,
|
|
132
143
|
title,
|
|
133
144
|
deluxe,
|
|
134
145
|
difficulty,
|
|
135
146
|
level,
|
|
136
|
-
score
|
|
137
|
-
|
|
147
|
+
score,
|
|
148
|
+
...flags,
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
};
|
|
138
152
|
}, {
|
|
139
153
|
result: [],
|
|
140
154
|
currentCategory: 0,
|
package/package.json
CHANGED
|
@@ -1,38 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@otohime-site/parser",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "26.4.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
7
|
"homepage": "https://github.com/otohime-site/parser#readme",
|
|
8
|
+
"repository": "github:otohime-site/parser",
|
|
8
9
|
"exports": {
|
|
9
10
|
".": "./index.js",
|
|
10
11
|
"./dx_intl": "./dx_intl/index.js",
|
|
11
12
|
"./dx_intl/*": "./dx_intl/*.js"
|
|
12
13
|
},
|
|
13
|
-
"scripts": {
|
|
14
|
-
"lint": "eslint",
|
|
15
|
-
"test": "jest --coverage",
|
|
16
|
-
"build": "rm -rf dist/ && tsc && cp README.md dist/ && jq 'del(.scripts.prepare)' package.json > dist/package.json"
|
|
17
|
-
},
|
|
18
14
|
"devDependencies": {
|
|
19
|
-
"@
|
|
20
|
-
"@
|
|
21
|
-
"
|
|
22
|
-
"eslint-
|
|
23
|
-
"eslint
|
|
24
|
-
"eslint-
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"ts-jest": "^29.1.1",
|
|
32
|
-
"typescript": "^5.3.3"
|
|
15
|
+
"@eslint/js": "^10.0.1",
|
|
16
|
+
"@types/node": "^24.12.2",
|
|
17
|
+
"@vitest/coverage-v8": "^4.1.4",
|
|
18
|
+
"@vitest/eslint-plugin": "^1.6.16",
|
|
19
|
+
"eslint": "^10.2.0",
|
|
20
|
+
"eslint-config-prettier": "^10.1.8",
|
|
21
|
+
"husky": "^9.1.7",
|
|
22
|
+
"lint-staged": "^16.4.0",
|
|
23
|
+
"prettier": "^3.8.3",
|
|
24
|
+
"typescript": "^6.0.2",
|
|
25
|
+
"typescript-eslint": "^8.58.2",
|
|
26
|
+
"vitest": "^4.1.4"
|
|
33
27
|
},
|
|
34
28
|
"lint-staged": {
|
|
35
29
|
"*.js,*.ts": "eslint --cache --fix",
|
|
36
30
|
"*.{js,ts,css,md}": "prettier --write"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"lint": "eslint",
|
|
34
|
+
"test": "vitest run --coverage",
|
|
35
|
+
"build": "rm -rf dist/ && tsc && cp README.md dist/ && jq 'del(.scripts.prepare)' package.json > dist/package.json"
|
|
37
36
|
}
|
|
38
|
-
}
|
|
37
|
+
}
|