首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >解码vtt时间戳数据

解码vtt时间戳数据
EN

Stack Overflow用户
提问于 2019-03-30 06:35:10
回答 1查看 129关注 0票数 0

我有几百行来自VTT字幕文件,来自suttitle的示例如下

代码语言:javascript
复制
00:01:03.500 --> 00:01:03.510 align:start position:0%
<c.colorCCCCCC>fourth guess it came from a broken</c><c.colorE5E5E5> home
 </c>

00:01:03.510 --> 00:01:08.140 align:start position:0%
<c.colorCCCCCC>fourth guess it came from a broken</c><c.colorE5E5E5> home
a<00:01:04.580><c> father</c><00:01:05.580><c> not</c><00:01:05.820><c> being</c><00:01:05.880><c> there</c><00:01:06.890><c> my</c><00:01:07.890><c> mother</c></c>

00:01:08.140 --> 00:01:08.150 align:start position:0%
a<c.colorE5E5E5> father not being there my mother
 </c>

00:01:08.150 --> 00:01:13.429 align:start position:0%
a<c.colorE5E5E5> father not being there my mother</c>
<c.colorE5E5E5>getting<00:01:09.150><c> married</c><00:01:09.630><c> and</c><00:01:11.360><c> the</c><00:01:12.360><c> abuse</c></c><c.colorCCCCCC><00:01:12.659><c> started</c><00:01:13.049><c> at</c></c>

00:01:13.429 --> 00:01:13.439 align:start position:0%
<c.colorE5E5E5>getting married and the abuse</c><c.colorCCCCCC> started at
 </c>

VTT字幕文件非常混乱,但其目标是捕获时间戳标记和时间戳本身中的所有单词。我在想preg match,但不知道如何实现它

代码语言:javascript
复制
$pattern = "<([^;]*)>";
preg_match_all($pattern, $lineContent, $allintag);

是我得到的,但到此为止。

代码语言:javascript
复制
array(
00:01:03.510,
00:01:04.580,
00:01:05.58,
00:01:05.820,
00:01:05.880,
00:01:06.890,
00:01:07.890,
00:01:08.140,
00:01:09.150,
00:01:09.630,
00:01:11.360,
00:01:12.360,
00:01:12.659,
00:01:13.049
)
array(
'fourth guess it came from a broken home',
'father',
'not',
'being',
'there',
'my',
'mother',
'getting',
'married',
'and',
'the',
'abuse',
'started',
'at'
)
EN

回答 1

Stack Overflow用户

发布于 2019-03-30 06:50:00

您可以使用

代码语言:javascript
复制
'~<(?<time>\d{2}:\d{2}:\d{2}\.\d+)><c>\s*(?<text>.*?)</c>~'

如果时间和文本组不是连续使用的

代码语言:javascript
复制
'~<(?<time>\d{2}:\d{2}:\d{2}\.\d+)>|<c>\s*(?<text>.*?)</c>~'

请参阅regex demo

详细信息

  • < -a文字组-组“char
  • (?<time>\d{2}:\d{2}:\d{2}\.\d+)”:2位,文字,2位,:,2位,.,然后是文本组-a 1+ text
  • \s* - whitespaces
  • (?<text>.*?) -.1+- ><c>”:除换行符以外的任何文字字符,最少为possible
  • </c> - 0+ </c> text。

请参阅PHP demo

代码语言:javascript
复制
$lineContent = "<00:01:13.650><c> time</c><00:01:13.920><c> and</c> 
 <00:01:14.780><c> that's</c><00:01:15.780><c> what</c>";
if (preg_match_all('~<(?<time>\d{2}:\d{2}:\d{2}\.\d+)><c>\s*(?<text>.*?)</c>~', $lineContent, $allintag)) {
    print_r($allintag["time"]);
    print_r($allintag["text"]);
}

输出:

代码语言:javascript
复制
Array ( [0] => 00:01:13.650 [1] => 00:01:13.920 [2] => 00:01:14.780 [3] => 00:01:15.780 )
Array ( [0] => time [1] => and  [2] => that's  [3] => what )
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55426272

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档