Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript将WEBTT文件转换为json_Javascript_Json_Object_Subtitle_Webvtt - Fatal编程技术网

Javascript将WEBTT文件转换为json

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

文件.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-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