Javascript将WEBTT文件转换为json
文件.vtt:Javascript将WEBTT文件转换为json,javascript,json,object,subtitle,webvtt,Javascript,Json,Object,Subtitle,Webvtt,文件.vtt: WEBVTT 00:00:00.039 --> 00:00:25.968 VINCENZO Cassano! 00:00:26.044 --> 00:00:26.961 Damn it. 00:01:23.434 --> 00:01:24.894 Mr. Vincenzo Cassano. 00:01:24.978 --> 00:01:27.814 You're under arrest for the murder of Mr. Oh Jeong
WEBVTT
00:00:00.039 --> 00:00:25.968
VINCENZO Cassano!
00:00:26.044 --> 00:00:26.961
Damn it.
00:01:23.434 --> 00:01:24.894
Mr. Vincenzo Cassano.
00:01:24.978 --> 00:01:27.814
You're under arrest
for the murder of Mr. Oh Jeong-bae.
00:01:43.913 --> 00:01:44.956
Hands up,
00:01:45.540 --> 00:01:46.708
or I'll fire.
00:01:51.504 --> 00:01:52.964
I didn't do it.
转换为json:
[
{
"from":"00:00:00.039",
"to":"00:00:25.968",
"timeString":"00:00:00.039 --> 00:00:25.968",
"text":"VINCENZO Cassano!"
},
....,
{
"from":"00:01:24.978",
"to":"00:01:27.814",
"timeString":"00:01:24.978 --> 00:01:27.814",
"text":"You're under arrest\nfor the murder of Mr. Oh Jeong-bae."<- Multi line,i assume it's a \n??
}
]
你能帮我一把吗?在劈开之前试着修剪一下<代码>v.trim().split(…?
const v = enc.decode(text).replace('WEBVTT', '').replace(/[\r\n]{2,}/g, '\n').replace('\n', '');
const lines = v.split('\n');
lines.map((el, i) => console.log(`${i} - ${el}`));
const test = new RegExp('\\b(\\d{2}:\\d{2}:\\d{2})\\.(\\d{3})\\b').test(el);
<-- expression to check if the string is of the type 00:00:00.039