Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/parse/krc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,14 @@ export const parseKRC = (text: string, options: ParseOptions = {}): LyricResult
cleanKangxi = false,
applyOffset = false,
} = options;
const content = cleanKangxi ? normalizeKangxi(text) : text;

const metadata: LyricMetadata = extractMetadata ? { timingMode: "Word" } : {};
const lines: LyricLine[] = [];
let krcTranslations: string[] = [];
let krcRomanizations: string[] = [];
const mainLines: LyricLine[] = [];
let kanaTag = "";

for (const raw of content.split("\n")) {
for (const raw of text.split("\n")) {
const trimmed = raw.trim();
if (!trimmed) continue;

Expand Down Expand Up @@ -163,6 +161,14 @@ export const parseKRC = (text: string, options: ParseOptions = {}): LyricResult
applyKanaToLines(lines, kanaTag);
}

if (cleanKangxi) {
for (const line of lines) {
for (const word of line.words) {
word.word = normalizeKangxi(word.word);
}
}
}

if (applyOffset && metadata.offset) {
applyTimestampOffset(lines, metadata.offset);
}
Expand Down
11 changes: 9 additions & 2 deletions src/parse/qrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ export const parseQRC = (text: string, options: ParseOptions = {}): LyricResult
cleanKangxi = false,
applyOffset = false,
} = options;
const normalized = cleanKangxi ? normalizeKangxi(text) : text;
const { content, xmlMeta } = extractFromXml(normalized);
const { content, xmlMeta } = extractFromXml(text);
const metadata: LyricMetadata =
extractMetadata && xmlMeta
? { ...xmlMeta, timingMode: "Word" }
Expand Down Expand Up @@ -149,6 +148,14 @@ export const parseQRC = (text: string, options: ParseOptions = {}): LyricResult
applyKanaToLines(lines, kanaTag);
}

if (cleanKangxi) {
for (const line of lines) {
for (const word of line.words) {
word.word = normalizeKangxi(word.word);
}
}
}

if (applyOffset && metadata.offset) {
applyTimestampOffset(lines, metadata.offset);
}
Expand Down
16 changes: 16 additions & 0 deletions tests/kana.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,22 @@ describe("Kana / Ruby Furigana Support", () => {
expect(result.lines).toHaveLength(1);
expect(result.lines[0].words[0].ruby).toBeUndefined();
});

it("应在康熙部首归一化前判断 kana 基础字符", () => {
const qrcText = `[offset:0]
[kana:1は(150865,168)な(151033,252)1お(153326,189)ど(153515,243)]
[150865,1633]離(150865,420)さ(151285,168)な(151453,260)い(151713,268)と(151981,249)⾔(152230,38)う(152268,230)
[152498,2173]((152498,192)Memento (152690,328)mori)(153018,308)躍(153326,432)る(153758,177)よ(153935,78)う(154013,78)に(154091,580)`;

const result = parseQRC(qrcText, { cleanKangxi: true });
const [line0, line1] = result.lines;
expect(line0.words[0].word).toBe("離");
expect(line0.words[0].ruby?.map((ruby) => ruby.word)).toEqual(["は", "な"]);
expect(line0.words[5].word).toBe("言");
expect(line0.words[5].ruby).toBeUndefined();
expect(line1.words[3].word).toBe("躍");
expect(line1.words[3].ruby?.map((ruby) => ruby.word)).toEqual(["お", "ど"]);
});
});

describe("parseKRC with Kana", () => {
Expand Down
Loading