Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
mantas-done committed Jun 21, 2023
2 parents 7bad00d + eb6877b commit e214a52
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Code/Converters/SbvConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function fileContentToInternalFormat($file_content)
{
$internal_format = []; // array - where file content will be stored

$blocks = explode("\n\n", trim($file_content)); // each block contains: start and end times + text
$blocks = preg_split("/(\n{2,})/", trim($file_content)); // each block contains: start and end times + text
foreach ($blocks as $block) {
$lines = explode("\n", $block); // separate all block lines
$times = explode(',', $lines[0]); // one the second line there is start and end times
Expand Down
35 changes: 35 additions & 0 deletions tests/formats/SbvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,41 @@ public function testConvertToFile()
$this->assertEquals($expected_file_content, $actual_file_content);
}

public function testParseMultipleNewLines()
{
$actual_file_content = <<< TEXT
0:01:04.927,0:01:06.927
Calm down da Vinci!
OK...
0:01:07.550,0:01:09.550
Yes, yes. On my way.
0:01:24.291,0:01:26.291
Lisa...Mona Lisa.
TEXT;

$actual_internal_format = Subtitles::loadFromString($actual_file_content, 'sbv')->getInternalFormat();
$expected_internal_format = [[
'start' => 64.927,
'end' => 66.927,
'lines' => ['Calm down da Vinci!', 'OK...'],
], [
'start' => 67.55,
'end' => 69.55,
'lines' => ['Yes, yes. On my way.'],
], [
'start' => 84.291,
'end' => 86.291,
'lines' => ['Lisa...Mona Lisa.'],
]];

$this->assertInternalFormatsEqual($expected_internal_format, $actual_internal_format);
}

// @TODO test time above 1 hour

}

0 comments on commit e214a52

Please sign in to comment.