From 20b84a593af883318aac8a325f6d5ed2bf95874e Mon Sep 17 00:00:00 2001 From: Mantas Date: Tue, 5 Mar 2024 15:07:13 +0200 Subject: [PATCH] Parse one more format --- src/Code/Converters/TtmlConverter.php | 9 +++++++-- tests/formats/TtmlTest.php | 29 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/Code/Converters/TtmlConverter.php b/src/Code/Converters/TtmlConverter.php index 2771765..f58b172 100644 --- a/src/Code/Converters/TtmlConverter.php +++ b/src/Code/Converters/TtmlConverter.php @@ -304,15 +304,20 @@ private static function subtitleXml(string $file_content, $fps) // Select and process subtitle data $xml = simplexml_load_string($file_content); - $namespace = $xml->getNamespaces(true)['']; + $namespace_array = $xml->getNamespaces(true); + $namespace = array_pop($namespace_array); $xml->registerXPathNamespace('ns', $namespace); $subtitles = $xml->xpath('//ns:Subtitle'); foreach ($subtitles as $subtitle) { + $text = $subtitle->Text->asXML(); + if ($text === false) { + $text = $subtitle->children('dcst', true)->Text->asXML(); + } $internal_format[] = [ 'start' => self::ttmlTimeToInternal((string)$subtitle['TimeIn'], $fps), 'end' => self::ttmlTimeToInternal((string)$subtitle['TimeOut'], $fps), - 'lines' => self::getLinesFromTextWithBr($subtitle->Text->asXML()), + 'lines' => self::getLinesFromTextWithBr($text), ]; } } diff --git a/tests/formats/TtmlTest.php b/tests/formats/TtmlTest.php index 095bc6a..4cd7e73 100644 --- a/tests/formats/TtmlTest.php +++ b/tests/formats/TtmlTest.php @@ -399,6 +399,35 @@ public function testConvertFromXml6() $this->assertInternalFormatsEqual($expected, $actual); } + public function testConvertFromXml6b() + { + $text = << + + urn:uuid:f7e1802b-9aea-4899-bc33-5a9d9011f0e9 + title + This is a subtitle file + 2024-02-04T20:17:48.000-00:00 + 1 + en + 25 1 + 25 + 00:00:00:00 + urn:uuid:3dec6dc0-39d0-498d-97d0-928d2eb78391 + + + + L'extérieur est différent de l'intérieur. + + + + +X; + $actual = Subtitles::loadFromString($text)->getInternalFormat(); + $expected = (new Subtitles())->add(30.154, 33.808, "L'extérieur est différent de l'intérieur.")->getInternalFormat(); + $this->assertInternalFormatsEqual($expected, $actual); + } + public function testConvertFromXml7() { $text = <<