Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse vtt file without WEBVTT string in file #83

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Code/Converters/VttConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class VttConverter implements ConverterContract

public function canParseFileContent($file_content)
{
return preg_match('/WEBVTT/m', $file_content) === 1;
return preg_match('/WEBVTT/m', $file_content) === 1 || preg_match('/' . static::$time_regexp . '/m', $file_content);
}

public function fileContentToInternalFormat($file_content)
Expand Down
15 changes: 15 additions & 0 deletions tests/formats/VttTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,19 @@ public function testParsesFileWithExtraNewLines()
->getInternalFormat();
$this->assertEquals($expected, $actual);
}

public function testParseFileWithoutWEBVTTText()
{
$given = <<< TEXT

00:00:02.100 --> 00:00:03.100
text1
TEXT;
$actual = (new Subtitles())->loadFromString($given)->getInternalFormat();
$expected = (new Subtitles())
->add(2.1, 3.1, 'text1')
->getInternalFormat();

$this->assertEquals($expected, $actual);
}
}