Skip to content

Commit

Permalink
Explore RTF parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
mantas-done committed Mar 29, 2024
1 parent f432584 commit 21e2842
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
"require-dev": {
"phpunit/phpunit": "^8.0"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Done\Subtitles\Code\UserException;

class EbuStlConverter implements ConverterContract
class EbuStlReader implements ConverterContract
{
public function canParseFileContent($file_content)
{
Expand Down
28 changes: 28 additions & 0 deletions src/Code/Converters/RtfReader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Done\Subtitles\Code\Converters;

use Done\Subtitles\Code\Helpers;
use Done\Subtitles\Code\UserException;
use Done\Subtitles\Subtitles;
use Jstewmc\Rtf\Document;

class RtfReader implements ConverterContract
{
public function canParseFileContent($file_content)
{
return strpos($file_content, '{\rtf1') === 0;
}

public function fileContentToInternalFormat($file_content, $original_file_content)
{

}

public function internalFormatToFileContent(array $internal_format, array $options)
{
// not implemented
}


}
8 changes: 5 additions & 3 deletions src/Subtitles.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
use Done\Subtitles\Code\Converters\BinaryFinder;
use Done\Subtitles\Code\Converters\CsvConverter;
use Done\Subtitles\Code\Converters\DfxpConverter;
use Done\Subtitles\Code\Converters\EbuStlConverter;
use Done\Subtitles\Code\Converters\EbuStlReader;
use Done\Subtitles\Code\Converters\LrcConverter;
use Done\Subtitles\Code\Converters\RtfReader;
use Done\Subtitles\Code\Converters\SbvConverter;
use Done\Subtitles\Code\Converters\SccConverter;
use Done\Subtitles\Code\Converters\SmiConverter;
Expand Down Expand Up @@ -39,7 +40,7 @@ class Subtitles
['extension' => 'vtt', 'format' => 'vtt', 'name' => 'WebVTT', 'class' => VttConverter::class],
['extension' => 'srt', 'format' => 'srt', 'name' => 'SubRip', 'class' => SrtConverter::class],
['extension' => 'stl', 'format' => 'stl', 'name' => 'Spruce Subtitle File', 'class' => StlConverter::class],
['extension' => 'stl', 'format' => 'ebu_stl', 'name' => 'EBU STL', 'class' => EbuStlConverter::class], // text needs to be converted from iso6937 encoding. PHP doesn't support it natively
['extension' => 'stl', 'format' => 'ebu_stl', 'name' => 'EBU STL', 'class' => EbuStlReader::class], // text needs to be converted from iso6937 encoding. PHP doesn't support it natively
['extension' => 'sub', 'format' => 'sub_microdvd', 'name' => 'MicroDVD', 'class' => SubMicroDvdConverter::class],
['extension' => 'sub', 'format' => 'sub_subviewer', 'name' => 'SubViewer2.0', 'class' => SubViewerConverter::class],
['extension' => 'ttml', 'format' => 'ttml', 'name' => 'TimedText 1.0', 'class' => TtmlConverter::class],
Expand All @@ -48,8 +49,9 @@ class Subtitles
['extension' => 'txt', 'format' => 'txt_quicktime', 'name' => 'Quick Time Text', 'class' => TxtQuickTimeConverter::class],
['extension' => 'scc', 'format' => 'scc', 'name' => 'Scenarist', 'class' => SccConverter::class],
['extension' => 'lrc', 'format' => 'lrc', 'name' => 'LyRiCs', 'class' => LrcConverter::class],
// ['extension' => 'rtf', 'format' => 'rtf', 'name' => 'Rich text format', 'class' => RtfReader::class], // libraryies eather throws exception, not parses, or takes long to parse 2h file
['extension' => 'csv', 'format' => 'csv', 'name' => 'Coma Separated Values', 'class' => CsvConverter::class], // must be last from bottom
['extension' => 'bin', 'format' => 'bin', 'name' => 'Binary', 'class' => BinaryFinder::class], // must be the last one
['extension' => 'bin', 'format' => 'bin', 'name' => 'Binary', 'class' => BinaryFinder::class],
['extension' => 'txt', 'format' => 'txt', 'name' => 'Plaintext', 'class' => TxtConverter::class], // must be the last one
];

Expand Down
4 changes: 2 additions & 2 deletions tests/formats/EbuStlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Tests\Formats;

use Done\Subtitles\Code\Converters\EbuStlConverter;
use Done\Subtitles\Code\Converters\EbuStlReader;
use Done\Subtitles\Code\Converters\VttConverter;
use Done\Subtitles\Code\Formats\Vtt;
use Done\Subtitles\Code\Helpers;
Expand All @@ -29,7 +29,7 @@ public function testParsesEbuStl()

public function testTextConversion()
{
$actual = EbuStlConverter::iso6937ToUtf8("\xA439");
$actual = EbuStlReader::iso6937ToUtf8("\xA439");
$this->assertEquals('$39', $actual);
}
}

0 comments on commit 21e2842

Please sign in to comment.