���� JFIF �� � ( %"1"%)+...383,7(-.-
![]() Server : Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.20 System : Linux st2.domain.com 3.10.0-1127.10.1.el7.x86_64 #1 SMP Wed Jun 3 14:28:03 UTC 2020 x86_64 User : apache ( 48) PHP Version : 7.4.20 Disable Function : NONE Directory : /var/www/html/123vid/vendor/mantas-done/subtitles/src/code/Converters/ |
<?php namespace Done\Subtitles; class SbvConverter implements ConverterContract { /** * Converts file's content (.srt) to library's "internal format" (array) * * @param string $file_content Content of file that will be converted * @return array Internal format */ public function fileContentToInternalFormat($file_content) { $internal_format = []; // array - where file content will be stored $blocks = explode("\n\n", trim($file_content)); // each block contains: start and end times + text foreach ($blocks as $block) { $lines = explode("\n", $block); // separate all block lines $times = explode(',', $lines[0]); // one the second line there is start and end times $internal_format[] = [ 'start' => static::srtTimeToInternal($times[0]), 'end' => static::srtTimeToInternal($times[1]), 'lines' => array_slice($lines, 1), // get all the remaining lines from block (if multiple lines of text) ]; } return $internal_format; } /** * Convert library's "internal format" (array) to file's content * * @param array $internal_format Internal format * @return string Converted file content */ public function internalFormatToFileContent(array $internal_format) { $file_content = ''; foreach ($internal_format as $k => $block) { $start = static::internalTimeToSrt($block['start']); $end = static::internalTimeToSrt($block['end']); $lines = implode("\n", $block['lines']); $file_content .= $start . ',' . $end . "\n"; $file_content .= $lines . "\n"; $file_content .= "\n"; } $file_content = trim($file_content); return $file_content; } // ------------------------------ private -------------------------------------------------------------------------- /** * Convert .srt file format to internal time format (float in seconds) * Example: 00:02:17,440 -> 137.44 * * @param $srt_time * * @return float */ protected static function srtTimeToInternal($srt_time) { $parts = explode('.', $srt_time); $only_seconds = strtotime("1970-01-01 {$parts[0]} UTC"); $milliseconds = (float)('0.' . $parts[1]); $time = $only_seconds + $milliseconds; return $time; } /** * Convert internal time format (float in seconds) to .srt time format * Example: 137.44 -> 00:02:17,440 * * @param float $internal_time * * @return string */ protected static function internalTimeToSrt($internal_time) { $parts = explode('.', $internal_time); // 1.23 $whole = $parts[0]; // 1 $decimal = isset($parts[1]) ? substr($parts[1], 0, 3) : 0; // 23 $srt_time = gmdate("0:i:s", floor($whole)) . '.' . str_pad($decimal, 3, '0', STR_PAD_RIGHT); return $srt_time; } }