diff --git a/src/Code/Converters/SmiConverter.php b/src/Code/Converters/SmiConverter.php
index a4a998d..419c8fb 100644
--- a/src/Code/Converters/SmiConverter.php
+++ b/src/Code/Converters/SmiConverter.php
@@ -36,14 +36,28 @@ public function fileContentToInternalFormat($file_content, $original_file_conten
$syncElements = $doc->getElementsByTagName('sync');
+ $data = [];
foreach ($syncElements as $syncElement) {
$time = $syncElement->getAttribute('start');
+ if(!$syncElement->childNodes->length) {
+ continue;
+ }
+
foreach ($syncElement->childNodes as $childNode) {
$lines = [];
$line = '';
+
+ $contentNode = null;
+
if ($childNode->nodeName === 'p' || $childNode->nodeName === '#text') {
- $line = $doc->saveHTML($childNode);
+ $contentNode = $childNode;
+ } else if ($childNode->nodeName === 'font' && $childNode->childNodes->length) {
+ $contentNode = $childNode->childNodes->item(0);
+ }
+
+ if($contentNode) {
+ $line = $doc->saveHTML($contentNode);
$line = preg_replace('/
/', '
', $line); // normalize
$line = str_replace("\u{00a0}", '', $line); // no brake space -
$line = str_replace(" ", '', $line); // somebody didn't have semicolon at the end of  
@@ -62,6 +76,10 @@ public function fileContentToInternalFormat($file_content, $original_file_conten
];
}
+ if(empty($data)) {
+ return $internal_format;
+ }
+
$i = 0;
foreach ($data as $row) {
if (!isset($internal_format[$i - 1]['end']) && $i !== 0) {
@@ -76,7 +94,7 @@ public function fileContentToInternalFormat($file_content, $original_file_conten
}
}
if (!isset($internal_format[$i - 1]['end'])) {
- $internal_format[$i - 1]['end'] = $internal_format[$i - 1]['start'] + 2.067; // SubtitleEdit adds this time if there is no last nbsp block
+ $internal_format[$i - 1]['end'] = $internal_format[$i - 1]['start'] + 1;
}
return $internal_format;
diff --git a/tests/formats/SmiTest.php b/tests/formats/SmiTest.php
index 86e4e07..a8dd97b 100644
--- a/tests/formats/SmiTest.php
+++ b/tests/formats/SmiTest.php
@@ -42,7 +42,7 @@ public function testFormatted()
'When we think',
'of E equals m c-squared,',
])
- ->add(17.35, 19.417, 'we have this vision of Einstein')
+ ->add(17.35, 18.35, 'we have this vision of Einstein')
->getInternalFormat();
$this->assertInternalFormatsEqual($expected, $actual);
}
@@ -136,7 +136,27 @@ public function testClientFile2()
')->getInternalFormat();
$expected = (new Subtitles())
- ->add(141.516, 143.583, 'test')
+ ->add(141.516, 142.516, 'test')
+ ->getInternalFormat();
+ $this->assertInternalFormatsEqual($expected, $actual);
+ }
+
+ public function testClientFile3()
+ {
+ $actual = Subtitles::loadFromString('
+
+금토드라마(열혈사제)-35회(19년04월13일(토))
+
+
+
+-야, 처리해.
+-야, 이중권.
+
+
+')->getInternalFormat();
+ $expected = (new Subtitles())
+ ->add(145.308, 145.994, '-야, 처리해.')
+ ->add(145.994, 146.994, '-야, 이중권.')
->getInternalFormat();
$this->assertInternalFormatsEqual($expected, $actual);
}