@otohime-site/parser 26.4.0 → 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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ### The Otohime Parser
2
2
 
3
- The parser will take the `HTMLDocument` or text (parsing with `DOMParser`) and return an object for each function.
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 DX Int'l Version
9
+ ##### maimai
10
10
 
11
- It is believed that it can be also used to parse from Japanese version of maimai DX Splash,
12
- but it is currently untested so use it carefully.
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.
@@ -1,2 +1,4 @@
1
- export { default as parsePlayer } from "./player.js";
2
- export { default as parseScores } from "./scores.js";
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 { default as parsePlayer } from "./player.js";
2
- export { default as parseScores } from "./scores.js";
1
+ export { parsePlayer } from "./player.js";
2
+ export { parseScores } from "./scores.js";
@@ -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
- declare const parsePlayer: (content: string | HTMLDocument) => PlayerParseResultLegacy | PlayerParseResultNew;
16
- export default parsePlayer;
15
+ export type PlayerParseResult = PlayerParseResultLegacy | PlayerParseResultNew;
16
+ export declare function parsePlayer(content: string | Document): PlayerParseResult;
package/dx_intl/player.js CHANGED
@@ -7,13 +7,15 @@ 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
- const parsePlayer = (content) => {
10
+ export function parsePlayer(content) {
11
11
  const document = typeof content === "string"
12
12
  ? new DOMParser().parseFromString(content, "text/html")
13
13
  : content;
14
14
  const cardName = document.querySelector(".name_block")?.textContent ?? "";
15
15
  // On marquee mode, the title will use another HTML structure...
16
- const title = document.querySelector(".trophy_inner_block > span, .trophy_inner_block > div > div")?.textContent ?? "".trim();
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 ?? "";
17
19
  const trophy = (document
18
20
  .querySelector(".trophy_block")
19
21
  ?.className.match(/Normal|Bronze|Silver|Gold|Rainbow/) ?? [
@@ -86,5 +88,4 @@ const parsePlayer = (content) => {
86
88
  course_rank: courseRank,
87
89
  class_rank: classRank,
88
90
  };
89
- };
90
- export default parsePlayer;
91
+ }
@@ -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
- declare const parseScores: (content: string | Document, categoryTo?: number, withNoScore?: boolean) => ScoresParseEntry[];
16
- export default parseScores;
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
- const parseScores = (content, categoryTo = 6, withNoScore = false) => {
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;
@@ -65,7 +65,7 @@ const parseScores = (content, categoryTo = 6, withNoScore = false) => {
65
65
  // Two types: determine by id (sta_xx vs dx_xx)
66
66
  const rawDeluxe = curr.querySelector(".music_kind_icon")?.getAttribute("src") ??
67
67
  (curr.id.match(/sta|dx/) ?? [""])[0];
68
- assertBetween(category, 1, categoryTo, "category");
68
+ assertBetween(category, 1, categoryCount, "category");
69
69
  assertNonEmpty(title, "title");
70
70
  assertBetween(difficulty, 0, 4, "difficulty");
71
71
  assertNonEmpty(rawDeluxe, "deluxe");
@@ -76,10 +76,18 @@ const parseScores = (content, categoryTo = 6, withNoScore = false) => {
76
76
  throw new Error("Level is not matched!");
77
77
  }
78
78
  const level = LEVELS[levelIndex];
79
- const rawScore = (curr.querySelector(".music_score_block")?.textContent ?? "").replace("%", "");
80
- if (rawScore.length === 0) {
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) {
81
89
  // Skip if it is not played yet
82
- return withNoScore
90
+ return includeUnplayed
83
91
  ? {
84
92
  ...prev,
85
93
  result: [
@@ -97,6 +105,19 @@ const parseScores = (content, categoryTo = 6, withNoScore = false) => {
97
105
  }
98
106
  const score = parseFloat(rawScore);
99
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");
100
121
  const flagImages = [...curr.querySelectorAll("img.f_r").values()];
101
122
  const flags = flagImages.reduce((prevFlags, currFlagImg) => {
102
123
  const comboMatches = (currFlagImg.getAttribute("src") ?? "").match(/(fc|fcp|ap|app)\.png/);
@@ -145,6 +166,8 @@ const parseScores = (content, categoryTo = 6, withNoScore = false) => {
145
166
  difficulty,
146
167
  level,
147
168
  score,
169
+ dx_score: dxScore,
170
+ max_dx_score: maxDxScore,
148
171
  ...flags,
149
172
  },
150
173
  ],
@@ -154,5 +177,4 @@ const parseScores = (content, categoryTo = 6, withNoScore = false) => {
154
177
  currentCategory: 0,
155
178
  });
156
179
  return result;
157
- };
158
- export default parseScores;
180
+ }
package/package.json CHANGED
@@ -1,29 +1,31 @@
1
1
  {
2
2
  "name": "@otohime-site/parser",
3
- "version": "26.4.0",
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
- "repository": "github:otohime-site/parser",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "github:otohime-site/parser"
10
+ },
11
+ "sideEffects": false,
9
12
  "exports": {
10
- ".": "./index.js",
11
- "./dx_intl": "./dx_intl/index.js",
12
- "./dx_intl/*": "./dx_intl/*.js"
13
+ "./dx_intl": "./dx_intl/index.js"
13
14
  },
14
15
  "devDependencies": {
15
16
  "@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",
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",
20
21
  "eslint-config-prettier": "^10.1.8",
21
22
  "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"
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"
27
29
  },
28
30
  "lint-staged": {
29
31
  "*.js,*.ts": "eslint --cache --fix",
package/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/index.js DELETED
@@ -1 +0,0 @@
1
- export {};