@@ -109,6 +109,6 @@ |
||
| 109 | 109 | */ |
| 110 | 110 | protected static function internalTimeToFormat($internal_time) |
| 111 | 111 | { |
| 112 | - return round($internal_time * 1000); |
|
| 112 | + return round($internal_time * 1000); |
|
| 113 | 113 | } |
| 114 | 114 | } |
@@ -108,7 +108,7 @@ |
||
| 108 | 108 | $file_content .= '<SYNC Start=' . self::internalTimeToFormat($last_time) . '><P Class=ENUSCC> ' . "</P></SYNC>\r\n"; |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - $file_content .= '<SYNC Start=' . self::internalTimeToFormat($block['start']) . '><P Class=ENUSCC>' . implode('<br>', $block['lines']) . "</P></SYNC>\r\n"; |
|
| 111 | + $file_content .= '<SYNC Start=' . self::internalTimeToFormat($block['start']) . '><P Class=ENUSCC>' . implode('<br>', $block['lines']) . "</P></SYNC>\r\n"; |
|
| 112 | 112 | $last_time = $block['end']; |
| 113 | 113 | } |
| 114 | 114 | $file_content .= '<SYNC Start=' . self::internalTimeToFormat($last_time) . '><P Class=ENUSCC> ' . "</P></SYNC>\r\n"; |
@@ -53,7 +53,7 @@ |
||
| 53 | 53 | $parts = explode('.', $vtt_time); |
| 54 | 54 | |
| 55 | 55 | // parts[0] could be mm:ss or hh:mm:ss format -> always use hh:mm:ss |
| 56 | - $parts[0] = substr_count($parts[0], ':') == 2 ? $parts[0] : '00:'.$parts[0]; |
|
| 56 | + $parts[0] = substr_count($parts[0], ':') == 2 ? $parts[0] : '00:' . $parts[0]; |
|
| 57 | 57 | |
| 58 | 58 | $only_seconds = strtotime("1970-01-01 {$parts[0]} UTC"); |
| 59 | 59 | $milliseconds = (float)('0.' . $parts[1]); |
@@ -913,7 +913,7 @@ |
||
| 913 | 913 | '91bf' => 'û', |
| 914 | 914 | ]; |
| 915 | 915 | |
| 916 | - private static $extended_chars = [ |
|
| 916 | + private static $extended_chars = [ |
|
| 917 | 917 | '9220' => 'Á', |
| 918 | 918 | '92a1' => 'É', |
| 919 | 919 | '92a2' => 'Ó', |
@@ -97,7 +97,7 @@ |
||
| 97 | 97 | protected static function internalTimeToScc($internal_time) |
| 98 | 98 | { |
| 99 | 99 | $parts = explode('.', $internal_time); |
| 100 | - $whole = (int) $parts[0]; |
|
| 100 | + $whole = (int)$parts[0]; |
|
| 101 | 101 | $decimal = isset($parts[1]) ? (float)('0.' . $parts[1]) : 0.0; |
| 102 | 102 | $frame = round($decimal * self::$fps); |
| 103 | 103 | $frame = min($frame, floor(self::$fps)); // max 29 |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | $time_parts = explode('.', $ttml_time); |
| 132 | 132 | $milliseconds = 0; |
| 133 | 133 | if (isset($time_parts[1])) { |
| 134 | - $milliseconds = (float) ('0.' . $time_parts[1]); |
|
| 134 | + $milliseconds = (float)('0.' . $time_parts[1]); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | list($hours, $minutes, $seconds) = array_map('intval', explode(':', $time_parts[0])); |
@@ -143,10 +143,10 @@ discard block |
||
| 143 | 143 | |
| 144 | 144 | protected static function internalTimeToTtml($internal_time) |
| 145 | 145 | { |
| 146 | - $formatted_output = round($internal_time, 3); |
|
| 146 | + $formatted_output = round($internal_time, 3); |
|
| 147 | 147 | |
| 148 | 148 | if (strpos($formatted_output, '.') === false) { |
| 149 | - $formatted_output .= ".0"; // Add at least one digit after decimal if there are no digits |
|
| 149 | + $formatted_output .= ".0"; // Add at least one digit after decimal if there are no digits |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | return $formatted_output; |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | list($numerator, $denominator) = array_map('intval', explode(' ', $frameRateMultiplier)); |
| 163 | 163 | return $frameRate / $denominator * $numerator; |
| 164 | 164 | } else if ($frameRate) { |
| 165 | - return (int) $frameRate; |
|
| 165 | + return (int)$frameRate; |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | //This is a standard frame rate used in many video formats and broadcast television. |
@@ -12,7 +12,7 @@ |
||
| 12 | 12 | |
| 13 | 13 | foreach ($expected as $k => $block) { |
| 14 | 14 | $this->assertTrue(abs(round($expected[$k]['start'], 2) - round($actual[$k]['start'], 2)) < $allowable_error, round($expected[$k]['start'], 3) . ' vs ' . round($actual[$k]['start'], 3)); |
| 15 | - $this->assertTrue(abs(round($expected[$k]['end'], 2) - round($actual[$k]['end'], 2)) < $allowable_error, round($expected[$k]['end'], 3) . ' vs ' . round($actual[$k]['end'], 3)); |
|
| 15 | + $this->assertTrue(abs(round($expected[$k]['end'], 2) - round($actual[$k]['end'], 2)) < $allowable_error, round($expected[$k]['end'], 3) . ' vs ' . round($actual[$k]['end'], 3)); |
|
| 16 | 16 | |
| 17 | 17 | foreach ($expected[$k]['lines'] as $line_k => $line) { |
| 18 | 18 | $this->assertEquals($line, $actual[$k]['lines'][$line_k]); |
@@ -28,22 +28,22 @@ discard block |
||
| 28 | 28 | protected $output; |
| 29 | 29 | |
| 30 | 30 | public static $formats = [ |
| 31 | - ['extension' => 'ass', 'format' => 'ass', 'name' => 'Advanced Sub Station Alpha', 'class' => AssConverter::class], |
|
| 32 | - ['extension' => 'ssa', 'format' => 'ass', 'name' => 'Advanced Sub Station Alpha', 'class' => AssConverter::class], |
|
| 33 | - ['extension' => 'dfxp', 'format' => 'dfxp', 'name' => 'Netflix Timed Text', 'class' => DfxpConverter::class], |
|
| 34 | - ['extension' => 'sbv', 'format' => 'sbv', 'name' => 'YouTube', 'class' => SbvConverter::class], |
|
| 35 | - ['extension' => 'srt', 'format' => 'srt', 'name' => 'SubRip', 'class' => SrtConverter::class], |
|
| 36 | - ['extension' => 'stl', 'format' => 'stl', 'name' => 'Spruce Subtitle File', 'class' => StlConverter::class], |
|
| 37 | - ['extension' => 'sub', 'format' => 'sub_microdvd', 'name' => 'MicroDVD', 'class' => SubMicroDvdConverter::class], |
|
| 38 | - ['extension' => 'sub', 'format' => 'sub_subviewer', 'name' => 'SubViewer2.0', 'class' => SubViewerConverter::class], |
|
| 39 | - ['extension' => 'ttml', 'format' => 'ttml', 'name' => 'TimedText 1.0', 'class' => TtmlConverter::class], |
|
| 40 | - ['extension' => 'xml', 'format' => 'ttml', 'name' => 'TimedText 1.0', 'class' => TtmlConverter::class], |
|
| 41 | - ['extension' => 'smi', 'format' => 'smi', 'name' => 'SAMI', 'class' => SmiConverter::class], |
|
| 42 | - ['extension' => 'txt', 'format' => 'txt_quicktime', 'name' => 'Quick Time Text', 'class' => TxtQuickTimeConverter::class], |
|
| 43 | - ['extension' => 'vtt', 'format' => 'vtt', 'name' => 'WebVTT', 'class' => VttConverter::class], |
|
| 44 | - ['extension' => 'scc', 'format' => 'scc', 'name' => 'Scenarist', 'class' => SccConverter::class], |
|
| 45 | - ['extension' => 'csv', 'format' => 'csv', 'name' => 'Coma Separated Values', 'class' => CsvConverter::class], // must be last from bottom |
|
| 46 | - ['extension' => 'txt', 'format' => 'txt', 'name' => 'Plaintext', 'class' => TxtConverter::class], // must be the last one |
|
| 31 | + ['extension' => 'ass', 'format' => 'ass', 'name' => 'Advanced Sub Station Alpha', 'class' => AssConverter::class], |
|
| 32 | + ['extension' => 'ssa', 'format' => 'ass', 'name' => 'Advanced Sub Station Alpha', 'class' => AssConverter::class], |
|
| 33 | + ['extension' => 'dfxp', 'format' => 'dfxp', 'name' => 'Netflix Timed Text', 'class' => DfxpConverter::class], |
|
| 34 | + ['extension' => 'sbv', 'format' => 'sbv', 'name' => 'YouTube', 'class' => SbvConverter::class], |
|
| 35 | + ['extension' => 'srt', 'format' => 'srt', 'name' => 'SubRip', 'class' => SrtConverter::class], |
|
| 36 | + ['extension' => 'stl', 'format' => 'stl', 'name' => 'Spruce Subtitle File', 'class' => StlConverter::class], |
|
| 37 | + ['extension' => 'sub', 'format' => 'sub_microdvd', 'name' => 'MicroDVD', 'class' => SubMicroDvdConverter::class], |
|
| 38 | + ['extension' => 'sub', 'format' => 'sub_subviewer', 'name' => 'SubViewer2.0', 'class' => SubViewerConverter::class], |
|
| 39 | + ['extension' => 'ttml', 'format' => 'ttml', 'name' => 'TimedText 1.0', 'class' => TtmlConverter::class], |
|
| 40 | + ['extension' => 'xml', 'format' => 'ttml', 'name' => 'TimedText 1.0', 'class' => TtmlConverter::class], |
|
| 41 | + ['extension' => 'smi', 'format' => 'smi', 'name' => 'SAMI', 'class' => SmiConverter::class], |
|
| 42 | + ['extension' => 'txt', 'format' => 'txt_quicktime', 'name' => 'Quick Time Text', 'class' => TxtQuickTimeConverter::class], |
|
| 43 | + ['extension' => 'vtt', 'format' => 'vtt', 'name' => 'WebVTT', 'class' => VttConverter::class], |
|
| 44 | + ['extension' => 'scc', 'format' => 'scc', 'name' => 'Scenarist', 'class' => SccConverter::class], |
|
| 45 | + ['extension' => 'csv', 'format' => 'csv', 'name' => 'Coma Separated Values', 'class' => CsvConverter::class], // must be last from bottom |
|
| 46 | + ['extension' => 'txt', 'format' => 'txt', 'name' => 'Plaintext', 'class' => TxtConverter::class], // must be the last one |
|
| 47 | 47 | ]; |
| 48 | 48 | |
| 49 | 49 | public static function convert($from_file_path, $to_file_path, $to_format = null) |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | |
| 160 | 160 | protected function sortInternalFormat() |
| 161 | 161 | { |
| 162 | - usort($this->internal_format, function ($item1, $item2) { |
|
| 162 | + usort($this->internal_format, function($item1, $item2) { |
|
| 163 | 163 | if ($item2['start'] == $item1['start']) { |
| 164 | 164 | return 0; |
| 165 | 165 | } elseif ($item2['start'] < $item1['start']) { |
@@ -97,7 +97,10 @@ |
||
| 97 | 97 | foreach ($lines as $line) { |
| 98 | 98 | foreach (self::$allowedSeparators as $delimiter) { |
| 99 | 99 | $count = count(explode($delimiter, $line)); |
| 100 | - if ($count < 2) continue; // delimiter not found in line, minimum 2 cols (timestamp + text) |
|
| 100 | + if ($count < 2) { |
|
| 101 | + continue; |
|
| 102 | + } |
|
| 103 | + // delimiter not found in line, minimum 2 cols (timestamp + text) |
|
| 101 | 104 | |
| 102 | 105 | if (empty($results[$delimiter])) { |
| 103 | 106 | $results[$delimiter] = []; |
@@ -28,14 +28,14 @@ discard block |
||
| 28 | 28 | public function fileContentToInternalFormat($file_content) |
| 29 | 29 | { |
| 30 | 30 | $data = self::csvToArray($file_content); |
| 31 | - $data_string = ''; |
|
| 31 | + $data_string = ''; |
|
| 32 | 32 | |
| 33 | - $is_start_time = (bool) preg_match(TxtConverter::$time_regexp, $data[1][0]); |
|
| 34 | - $is_end_time = (bool) preg_match(TxtConverter::$time_regexp, $data[1][1]); |
|
| 33 | + $is_start_time = (bool)preg_match(TxtConverter::$time_regexp, $data[1][0]); |
|
| 34 | + $is_end_time = (bool)preg_match(TxtConverter::$time_regexp, $data[1][1]); |
|
| 35 | 35 | |
| 36 | 36 | foreach ($data as $k => $row) { |
| 37 | - $timestamp_found = (bool) preg_match(TxtConverter::$time_regexp, $row[0]); |
|
| 38 | - if ($k === 0 && $timestamp_found === false) { // heading |
|
| 37 | + $timestamp_found = (bool)preg_match(TxtConverter::$time_regexp, $row[0]); |
|
| 38 | + if ($k === 0 && $timestamp_found === false) { // heading |
|
| 39 | 39 | continue; |
| 40 | 40 | } |
| 41 | 41 | |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | |
| 90 | 90 | $separator = self::detectSeparator($content); |
| 91 | 91 | $csv = []; |
| 92 | - while ( ($data = fgetcsv($fp, 0, $separator) ) !== false ) { |
|
| 92 | + while (($data = fgetcsv($fp, 0, $separator)) !== false) { |
|
| 93 | 93 | $csv[] = $data; |
| 94 | 94 | } |
| 95 | 95 | fclose($fp); |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - $internal_format[$j] = [ |
|
| 101 | + $internal_format[$j] = [ |
|
| 102 | 102 | 'start' => $row['start'], |
| 103 | 103 | 'end' => $row['end'], |
| 104 | 104 | 'lines' => [$row['text']], |
@@ -224,16 +224,16 @@ discard block |
||
| 224 | 224 | $total_parts = count($time_parts); |
| 225 | 225 | |
| 226 | 226 | if ($total_parts === 1) { |
| 227 | - $tmp = (float) str_replace(',', '.', $time_parts[0]); |
|
| 227 | + $tmp = (float)str_replace(',', '.', $time_parts[0]); |
|
| 228 | 228 | return $tmp; |
| 229 | 229 | } elseif ($total_parts === 2) { // minutes:seconds format |
| 230 | 230 | list($minutes, $seconds) = array_map('intval', $time_parts); |
| 231 | - $tmp = (float) str_replace(',', '.', $time_parts[1]); |
|
| 231 | + $tmp = (float)str_replace(',', '.', $time_parts[1]); |
|
| 232 | 232 | $milliseconds = $tmp - floor($tmp); |
| 233 | 233 | return ($minutes * 60) + $seconds + $milliseconds; |
| 234 | 234 | } elseif ($total_parts === 3) { // hours:minutes:seconds,milliseconds format |
| 235 | 235 | list($hours, $minutes, $seconds) = array_map('intval', $time_parts); |
| 236 | - $tmp = (float) str_replace(',', '.', $time_parts[2]); |
|
| 236 | + $tmp = (float)str_replace(',', '.', $time_parts[2]); |
|
| 237 | 237 | $milliseconds = $tmp - floor($tmp); |
| 238 | 238 | return ($hours * 3600) + ($minutes * 60) + $seconds + $milliseconds; |
| 239 | 239 | } elseif ($total_parts === 4) { // hours:minutes:seconds:frames format |