Skip to content

Commit 20b84a5

Browse files
committed
Parse one more format
1 parent 0544f53 commit 20b84a5

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/Code/Converters/TtmlConverter.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,15 +304,20 @@ private static function subtitleXml(string $file_content, $fps)
304304
// Select and process subtitle data
305305
$xml = simplexml_load_string($file_content);
306306

307-
$namespace = $xml->getNamespaces(true)[''];
307+
$namespace_array = $xml->getNamespaces(true);
308+
$namespace = array_pop($namespace_array);
308309
$xml->registerXPathNamespace('ns', $namespace);
309310

310311
$subtitles = $xml->xpath('//ns:Subtitle');
311312
foreach ($subtitles as $subtitle) {
313+
$text = $subtitle->Text->asXML();
314+
if ($text === false) {
315+
$text = $subtitle->children('dcst', true)->Text->asXML();
316+
}
312317
$internal_format[] = [
313318
'start' => self::ttmlTimeToInternal((string)$subtitle['TimeIn'], $fps),
314319
'end' => self::ttmlTimeToInternal((string)$subtitle['TimeOut'], $fps),
315-
'lines' => self::getLinesFromTextWithBr($subtitle->Text->asXML()),
320+
'lines' => self::getLinesFromTextWithBr($text),
316321
];
317322
}
318323
}

tests/formats/TtmlTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,35 @@ public function testConvertFromXml6()
399399
$this->assertInternalFormatsEqual($expected, $actual);
400400
}
401401

402+
public function testConvertFromXml6b()
403+
{
404+
$text = <<<X
405+
<?xml version="1.0" encoding="UTF-8"?>
406+
<dcst:SubtitleReel xmlns:dcst="http://www.smpte-ra.org/schemas/428-7/2010/DCST" xmlns:xs="http://www.w3.org/2001/XMLSchema">
407+
<dcst:Id>urn:uuid:f7e1802b-9aea-4899-bc33-5a9d9011f0e9</dcst:Id>
408+
<dcst:ContentTitleText>title</dcst:ContentTitleText>
409+
<dcst:AnnotationText>This is a subtitle file</dcst:AnnotationText>
410+
<dcst:IssueDate>2024-02-04T20:17:48.000-00:00</dcst:IssueDate>
411+
<dcst:ReelNumber>1</dcst:ReelNumber>
412+
<dcst:Language>en</dcst:Language>
413+
<dcst:EditRate>25 1</dcst:EditRate>
414+
<dcst:TimeCodeRate>25</dcst:TimeCodeRate>
415+
<dcst:StartTime>00:00:00:00</dcst:StartTime>
416+
<dcst:LoadFont ID="theFontId">urn:uuid:3dec6dc0-39d0-498d-97d0-928d2eb78391</dcst:LoadFont>
417+
<dcst:SubtitleList>
418+
<dcst:Font ID="theFontId" Size="42" Weight="normal" Color="FFFFFFFF" Effect="border" EffectColor="FF000000">
419+
<dcst:Subtitle SpotNumber="1" FadeUpTime="00:00:00:00" FadeDownTime="00:00:00:00" TimeIn="00:00:30:04" TimeOut="00:00:33:21">
420+
<dcst:Text Vposition="8" Valign="bottom" Halign="center" Direction="ltr">L'extérieur est différent de l'intérieur.</dcst:Text>
421+
</dcst:Subtitle>
422+
</dcst:Font>
423+
</dcst:SubtitleList>
424+
</dcst:SubtitleReel>
425+
X;
426+
$actual = Subtitles::loadFromString($text)->getInternalFormat();
427+
$expected = (new Subtitles())->add(30.154, 33.808, "L'extérieur est différent de l'intérieur.")->getInternalFormat();
428+
$this->assertInternalFormatsEqual($expected, $actual);
429+
}
430+
402431
public function testConvertFromXml7()
403432
{
404433
$text = <<<X

0 commit comments

Comments
 (0)