Skip to content

Commit

Permalink
Find binary files
Browse files Browse the repository at this point in the history
  • Loading branch information
mantas-done committed Mar 29, 2024
1 parent 040b712 commit f432584
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "mantas-done/subtitles",
"description": "Subtitle converter and generator for PHP",
"type": "library",
"license": "MIT",
"minimum-stability": "dev",
"autoload": {
"psr-4": {
Expand Down
28 changes: 28 additions & 0 deletions src/Code/Converters/BinaryFinder.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;

class BinaryFinder implements ConverterContract
{
public function canParseFileContent($file_content)
{
if (Helpers::strContains($file_content, "\x00")) {
throw new UserException('This file is binary file and it is probably not a caption file.');
}

return false;
}

public function fileContentToInternalFormat($file_content, $original_file_content)
{
// no code needed
}

public function internalFormatToFileContent(array $internal_format , array $options)
{
// no code needed
}
}
2 changes: 2 additions & 0 deletions src/Subtitles.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Done\Subtitles;

use Done\Subtitles\Code\Converters\AssConverter;
use Done\Subtitles\Code\Converters\BinaryFinder;
use Done\Subtitles\Code\Converters\CsvConverter;
use Done\Subtitles\Code\Converters\DfxpConverter;
use Done\Subtitles\Code\Converters\EbuStlConverter;
Expand Down Expand Up @@ -48,6 +49,7 @@ class Subtitles
['extension' => 'scc', 'format' => 'scc', 'name' => 'Scenarist', 'class' => SccConverter::class],
['extension' => 'lrc', 'format' => 'lrc', 'name' => 'LyRiCs', 'class' => LrcConverter::class],
['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' => 'txt', 'format' => 'txt', 'name' => 'Plaintext', 'class' => TxtConverter::class], // must be the last one
];

Expand Down

0 comments on commit f432584

Please sign in to comment.