Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- set_time_limit(0);
- /*
- ini_set('display_errors', 1);
- ini_set('display_startup_errors', 1);
- error_reporting(E_ALL);*/
- function filesize_formatted($path)
- {
- $size = filesize($path);
- $units = array( 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
- $power = $size > 0 ? floor(log($size, 1024)) : 0;
- return number_format($size / pow(1024, $power), 2, '.', ',') . ' ' . $units[$power];
- }
- /*
- ini_set('display_errors', 1);
- ini_set('display_startup_errors', 1);
- error_reporting(E_ALL);
- /*
- * ffprobe class helper for ffmpeg 0.9+ (JSON support)
- * Written by Paulo Freitas <me@paulofreitas.me> under CC BY-SA 3.0 license
- */
- class ffprobe
- {
- public function __construct($filename, $prettify = false)
- {
- if (!file_exists($filename)) {
- //throw new Exception(sprintf('File not exists: %s', $filename));
- }
- $this->__metadata = $this->__probe($filename, $prettify);
- }
- private function __probe($filename, $prettify)
- {
- // Start time
- $init = microtime(true);
- // Default options
- $options = '-loglevel quiet -show_format -show_streams -print_format json';
- if ($prettify) {
- $options .= ' -pretty';
- }
- // Avoid escapeshellarg() issues with UTF-8 filenames
- setlocale(LC_CTYPE, 'en_US.UTF-8');
- // Run the ffprobe, save the JSON output then decode
- $json = json_decode(shell_exec(sprintf('ffprobe %s %s', $options,
- escapeshellarg($filename))));
- if (!isset($json->format)) {
- //throw new Exception('Unsupported file type');
- }
- // Save parse time (milliseconds)
- $this->parse_time = round((microtime(true) - $init) * 1000);
- return $json;
- }
- public function __get($key)
- {
- if (isset($this->__metadata->$key)) {
- return $this->__metadata->$key;
- }
- //throw new Exception(sprintf('Undefined property: %s', $key));
- }
- }
- $dir = '/var/www/html/playbe.tk/public_html/files/Torrent/13.Reasons.Why.S01.2160p.NF.WEBRip.DD5.1.x264-VLAD[rartv]/';
- $files = scandir($dir);
- unset($files[0]);
- unset($files[1]);
- //unset($files[2]);
- $finalCommand = "";
- $counterExec = 0;
- echo "<h1>Total files: " . count($files) . "</h1>";
- foreach($files as $keyMain => $filename) {
- echo "</br>";
- echo "</br>";
- echo "</hr>";
- echo "<h3>Název souboru: [$keyMain] $filename</h3>";
- $info = new ffprobe($dir . $filename, true);
- $streams = (array) $info->streams;
- $bit_rate = explode(".", str_replace(" Mbit/s", "", $info->format->bit_rate) * 1000)[0];
- $audioFound = false;
- $audioMap = 0;
- $isCze = false;
- $foundVideoMap = false;
- $isBig = false;
- $fileSizeHuman = filesize_formatted($dir . $filename);
- $fileSize = intval(filesize($dir . $filename));
- $video_part_cmd = '-b:v ' . $bit_rate . 'k ';
- foreach($streams as $key => $stream) {
- $stream = (array) $stream;
- if($stream['codec_type'] == "audio") {
- if($stream['tags']->title == "Czech" || $stream['tags']->title == "Cze" || $stream['tags']->title == "Cz" || $stream['tags']->language == "cze" || $stream['tags']->language == "ces" || $stream['tags']->LANGUAGE == "cze" || $stream['tags']->LANGUAGE == "ces") {
- $isCze = true;
- }
- }
- if($stream['codec_type'] == "video") {
- if($stream['codec_name'] !== "h264" && $foundVideoMap === false) {
- echo "<b style='font-size: 20px;color: red;'>This is not h264!</b></br>";
- $foundVideoMap = $stream['index'];
- if(file_exists($dir . $filename)) {
- //rename($dir . $filename, str_replace("/download/", "/original/", $dir . $filename));
- }
- } else {
- if($stream['codec_name'] == "h264") {
- $foundVideoMap = $stream['index'];
- }
- }
- }
- }
- foreach($streams as $key => $stream) {
- $stream = (array) $stream;
- if($stream['codec_type'] == "video") {
- $resolution = "<b style='color: green;'>(" . $stream['width'] . "x" . $stream['height'] . ")</b> - ";
- } else {
- $resolution = null;
- }
- echo "<span style='background-color: #ddd;'>MAP: 0:" . $stream['index'] . " - $resolution" . $stream['codec_type'] . " - " . $stream['codec_name'] . " - " . $stream['channel_layout'] . " - <b>" . $stream['tags']->title . " /// " . $stream['tags']->language . " " . $stream['tags']->LANGUAGE . "</b></span>";
- if($stream['height'] < 800 && $stream['codec_type'] == "video") {
- echo "<b style='font-size: 20px;color: red;'>Low resolution!</b></br>";
- }
- if(strpos(strtolower($stream['tags']->title), 'forced') !== false) {
- if(strtolower($stream['tags']->language) == "cz" || strtolower($stream['tags']->language) == "cze" || strtolower($stream['tags']->language) == "czech" || strtolower($stream['tags']->language) == "cs") {
- $file_path = $dir . $filename;
- $titleSubs = file_get_contents("http://vps403015.ovh.net/playbe/webshareGetFinalTitle.php?file=" . urlencode(trim($filename)));
- if($titleSubs) {
- $file_path_subs = '/home/storage/success/forced/' . $titleSubs . ".srt";
- } else {
- $file_path_subs = '/home/storage/success/forced/' . $filename . ".srt";
- }
- echo "<b style='background-color: blue; color: white;'>FOUND FORCED SUBTITLES</b></br>";
- echo "<i style='font-size: 14px; color: #555;'>ffmpeg -i \"$file_path\" -map 0:" . $stream['index'] . " \"$file_path_subs\"</i>";
- }
- }
- if(!$audioFound) {
- if($isCze) {
- if(count($streams) == 2) {
- if($stream['codec_type'] == "audio") {
- $audioMap = $stream['index'];
- $audioFound = true;
- echo "<span style='background-color: green; color: white; letter-spacing: 5px;'><<<<<<<<<</span>";
- }
- } else {
- if($stream['codec_type'] == "audio") {
- if($stream['tags']->title == "Czech" || $stream['tags']->title == "Cze" || $stream['tags']->title == "Cz" || $stream['tags']->language == "cze" || $stream['tags']->language == "ces" || $stream['tags']->LANGUAGE == "cze" || $stream['tags']->LANGUAGE == "ces") {
- $audioMap = $stream['index'];
- $audioFound = true;
- echo "<span style='background-color: green; color: white; letter-spacing: 5px;'><<<<<<<<<</span>";
- }
- }
- }
- } else {
- if(count($streams) == 2 || count($streams) == 3) {
- if($stream['codec_type'] == "audio") {
- $audioMap = $stream['index'];
- $audioFound = true;
- echo "<span style='background-color: green; color: white; letter-spacing: 5px;'><<<<<<<<<</span>";
- }
- } else {
- if($stream['codec_type'] == "audio") {
- //if($stream['tags']->title == "English" || $stream['tags']->title == "Eng" || $stream['tags']->title == "En" || $stream['tags']->language == "eng" || $stream['tags']->LANGUAGE == "eng") {
- $audioMap = $stream['index'];
- $audioFound = true;
- echo "<span style='background-color: green; color: white; letter-spacing: 5px;'><<<<<<<<<</span>";
- //}
- }
- }
- }
- }
- if($audioMap == $stream['index'] && $audioFound) {
- $file_path = $dir . $filename;
- $file_path_audio = $dir . $filename . "_zvuk.mp4";
- $file_path_video = $dir . $filename . "_video.mp4";
- $file_path_final = '/var/www/html/playbe.tk/public_html/files/Torrent/13.Reasons.Why.S01.2160p.NF.WEBRip.DD5.1.x264-VLAD[rartv]/' . $filename . ".mp4";
- //echo "</br><pre>";print_r($stream);echo "</pre>";
- echo "</br>";
- if($streams[$foundVideoMap]->codec_name == "h264") {
- //is map h264
- $command_v = "ffmpeg -i \"$file_path\" -c copy -map 0:0$foundVideoMap \"$file_path_video\"";
- } else {
- //is not map h264
- $command_v = "ffmpeg -i \"$file_path\" -map 0:0$foundVideoMap -c:v libx264 -crf 18 -preset ultrafast -c:a libfdk_aac -profile:v baseline -level 3.0 $video_part_cmd \"$file_path_video\"";
- }
- //$command_v = "ffmpeg -i \"$file_path\" -c copy -c:v libx264 -preset ultrafast $video_part_cmd -map 0:0$foundVideoMap \"$file_path_video\"";
- $command_a = "ffmpeg -i \"$file_path\" -map 0:$audioMap -c:v libx264 -preset ultrafast -c:a libfdk_aac -profile:v baseline -level 3.0 \"$file_path_audio\"";
- $command_m = "ffmpeg -i \"$file_path_video\" -i \"$file_path_audio\" -c copy -map 0:0 -map 1:0 \"$file_path_final\" && rm \"$file_path_video\" && rm \"$file_path_audio\"";
- //$command_m = "ffmpeg -i \"$file_path_video\" -i \"$file_path_audio\" -c copy -map 0:0 -map 1:0 \"$file_path_final\"";
- $command_one = "ffmpeg -i \"$file_path\" -i \"$file_path\" -map 0:0$foundVideoMap -map 1:0$audioMap -c:v libx264 -preset ultrafast $video_part_cmd -c:a libfdk_aac -profile:v baseline -level 3.0 \"$file_path_final\"";
- $command_all = $command_v . " && " . $command_a . " && " . $command_m;
- $command_one = $command_all;
- if(file_exists($file_path_final)) {
- $finalExists = ' border-left: 30px solid green;';
- } else {
- $finalExists = ' border-left: 30px solid orange;';
- if(is_numeric($foundVideoMap)) {
- if($finalCommand != "") {
- //$finalCommand .= " && " . $command_v . " && " . $command_a . " && " . $command_m;
- $finalCommand .= " ; " . $command_one;
- } else {
- //$finalCommand .= $command_v . " && " . $command_a . " && " . $command_m;
- $finalCommand .= $command_one;
- }
- }
- if($_GET['exec']) {
- exec('pgrep -c ffmpeg', $countFFMPEG);
- //echo "<script>setTimeout(function(){window.location.reload(1);}, 60000);</script>";
- if($countFFMPEG[0] <= 1) {
- if($counterExec < (1 - $countFFMPEG[0])) {
- echo "<h1>Execute command... </h1>";
- $command_exec = $command_one . " > /dev/null 2>&1 &";
- exec($command_exec);
- $counterExec++;
- }
- }
- }
- }
- echo "<i style='font-size: 14px; color: #555;$finalExists'>$command_v</i>";
- echo "</br>";
- echo "<i style='font-size: 14px; color: #555;$finalExists'>$command_a</i>";
- echo "</br>";
- echo "<i style='font-size: 14px; color: #555;$finalExists'>$command_m</i>";
- echo "</br>";
- echo "<i style='font-size: 14px; color: #555;$finalExists'>$command_one</i>";
- echo "</br>";
- }
- echo "</br>";
- }
- }
- echo "</br>";
- echo "</br>";
- echo "<h2>Final Command:</h2>";
- echo "(" . $finalCommand . ")";
- /*
- echo "<pre>";
- print_r($files);
- echo "</pre>";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement