mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-26 00:31:20 -08:00
fix srt subtitle parsing
This commit is contained in:
1 parent
7585f9895c
commit
1502212085
6 files changed
+34
-13
No files matched your search
@@ -1,12 +1,25 @@
|
||||
function fixSrt(srt) {
|
||||
return srt.replace(/(\d\d:\d\d:\d\d)[,.](\d+)/g, (_, $1, $2) => {
|
||||
let ms = $2.slice(0, 3);
|
||||
if ($2.length === 1) {
|
||||
ms = $2 + '00';
|
||||
}
|
||||
if ($2.length === 2) {
|
||||
ms = $2 + '0';
|
||||
}
|
||||
return `${$1},${ms}`;
|
||||
});
|
||||
}
|
||||
|
||||
export function srtToVtt(srtText) {
|
||||
return 'WEBVTT \r\n\r\n'.concat(
|
||||
srtText
|
||||
.replace(/{[\s\S]*?}/g, '')
|
||||
fixSrt(srtText)
|
||||
.replace(/\{\\([ibu])\}/g, '</$1>')
|
||||
.replace(/\{\\([ibu])1\}/g, '<$1>')
|
||||
.replace(/\{([ibu])\}/g, '<$1>')
|
||||
.replace(/\{\/([ibu])\}/g, '</$1>')
|
||||
.replace(/(\d\d:\d\d:\d\d),(\d\d\d)/g, '$1.$2')
|
||||
.replace(/{[\s\S]*?}/g, '')
|
||||
.concat('\r\n\r\n'),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user