-
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
80 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { type ILyricsText, type ILyricsTag, LyricsContentType, TimestampFormat } from '../type.js'; | ||
|
||
/** | ||
* Parse LRC (Lyrics) formatted text | ||
* Ref: https://en.wikipedia.org/wiki/LRC_(file_format) | ||
* @param lrcString | ||
*/ | ||
export function parseLrc(lrcString: string): ILyricsTag { | ||
const lines = lrcString.split('\n'); | ||
const syncText: ILyricsText[] = []; | ||
|
||
// Regular expression to match LRC timestamps (e.g., [00:45.52]) | ||
const timestampRegex = /\[(\d{2}):(\d{2})\.(\d{2})\]/; | ||
|
||
for (const line of lines) { | ||
const match = line.match(timestampRegex); | ||
|
||
if (match) { | ||
const minutes = Number.parseInt(match[1], 10); | ||
const seconds = Number.parseInt(match[2], 10); | ||
const hundredths = Number.parseInt(match[3], 10); | ||
|
||
// Convert the timestamp to milliseconds, as per TimestampFormat.milliseconds | ||
const timestamp = (minutes * 60 + seconds) * 1000 + hundredths * 10; | ||
|
||
// Get the text portion of the line (e.g., "あの蝶は自由になれたかな") | ||
const text = line.replace(timestampRegex, '').trim(); | ||
|
||
syncText.push({ timestamp, text }); | ||
} | ||
} | ||
|
||
// Creating the ILyricsTag object | ||
return { | ||
contentType: LyricsContentType.lyrics, | ||
timeStampFormat: TimestampFormat.milliseconds, | ||
syncText, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters