Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.83 KB | None | 0 0
  1. <?php
  2. set_time_limit(0);
  3. /*
  4. ini_set('display_errors', 1);
  5. ini_set('display_startup_errors', 1);
  6. error_reporting(E_ALL);*/
  7.  
  8. function filesize_formatted($path)
  9. {
  10. $size = filesize($path);
  11. $units = array( 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
  12. $power = $size > 0 ? floor(log($size, 1024)) : 0;
  13. return number_format($size / pow(1024, $power), 2, '.', ',') . ' ' . $units[$power];
  14. }
  15.  
  16. /*
  17. ini_set('display_errors', 1);
  18. ini_set('display_startup_errors', 1);
  19. error_reporting(E_ALL);
  20. /*
  21. * ffprobe class helper for ffmpeg 0.9+ (JSON support)
  22. * Written by Paulo Freitas <me@paulofreitas.me> under CC BY-SA 3.0 license
  23. */
  24. class ffprobe
  25. {
  26. public function __construct($filename, $prettify = false)
  27. {
  28. if (!file_exists($filename)) {
  29. //throw new Exception(sprintf('File not exists: %s', $filename));
  30. }
  31. $this->__metadata = $this->__probe($filename, $prettify);
  32. }
  33. private function __probe($filename, $prettify)
  34. {
  35. // Start time
  36. $init = microtime(true);
  37. // Default options
  38. $options = '-loglevel quiet -show_format -show_streams -print_format json';
  39. if ($prettify) {
  40. $options .= ' -pretty';
  41. }
  42. // Avoid escapeshellarg() issues with UTF-8 filenames
  43. setlocale(LC_CTYPE, 'en_US.UTF-8');
  44. // Run the ffprobe, save the JSON output then decode
  45. $json = json_decode(shell_exec(sprintf('ffprobe %s %s', $options,
  46. escapeshellarg($filename))));
  47. if (!isset($json->format)) {
  48. //throw new Exception('Unsupported file type');
  49. }
  50. // Save parse time (milliseconds)
  51. $this->parse_time = round((microtime(true) - $init) * 1000);
  52. return $json;
  53. }
  54. public function __get($key)
  55. {
  56. if (isset($this->__metadata->$key)) {
  57. return $this->__metadata->$key;
  58. }
  59. //throw new Exception(sprintf('Undefined property: %s', $key));
  60. }
  61. }
  62.  
  63.  
  64. $dir = '/var/www/html/playbe.tk/public_html/files/Torrent/13.Reasons.Why.S01.2160p.NF.WEBRip.DD5.1.x264-VLAD[rartv]/';
  65. $files = scandir($dir);
  66. unset($files[0]);
  67. unset($files[1]);
  68. //unset($files[2]);
  69. $finalCommand = "";
  70. $counterExec = 0;
  71.  
  72. echo "<h1>Total files: " . count($files) . "</h1>";
  73.  
  74. foreach($files as $keyMain => $filename) {
  75.  
  76.  
  77.  
  78. echo "</br>";
  79. echo "</br>";
  80. echo "</hr>";
  81. echo "<h3>Název souboru: [$keyMain] $filename</h3>";
  82.  
  83. $info = new ffprobe($dir . $filename, true);
  84. $streams = (array) $info->streams;
  85.  
  86. $bit_rate = explode(".", str_replace(" Mbit/s", "", $info->format->bit_rate) * 1000)[0];
  87.  
  88. $audioFound = false;
  89. $audioMap = 0;
  90.  
  91. $isCze = false;
  92. $foundVideoMap = false;
  93.  
  94. $isBig = false;
  95. $fileSizeHuman = filesize_formatted($dir . $filename);
  96. $fileSize = intval(filesize($dir . $filename));
  97.  
  98. $video_part_cmd = '-b:v ' . $bit_rate . 'k ';
  99.  
  100. foreach($streams as $key => $stream) {
  101. $stream = (array) $stream;
  102. if($stream['codec_type'] == "audio") {
  103. 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") {
  104. $isCze = true;
  105. }
  106. }
  107. if($stream['codec_type'] == "video") {
  108. if($stream['codec_name'] !== "h264" && $foundVideoMap === false) {
  109. echo "<b style='font-size: 20px;color: red;'>This is not h264!</b></br>";
  110. $foundVideoMap = $stream['index'];
  111. if(file_exists($dir . $filename)) {
  112. //rename($dir . $filename, str_replace("/download/", "/original/", $dir . $filename));
  113. }
  114. } else {
  115. if($stream['codec_name'] == "h264") {
  116. $foundVideoMap = $stream['index'];
  117. }
  118. }
  119. }
  120. }
  121.  
  122. foreach($streams as $key => $stream) {
  123. $stream = (array) $stream;
  124.  
  125. if($stream['codec_type'] == "video") {
  126. $resolution = "<b style='color: green;'>(" . $stream['width'] . "x" . $stream['height'] . ")</b> - ";
  127. } else {
  128. $resolution = null;
  129. }
  130.  
  131. 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>";
  132. if($stream['height'] < 800 && $stream['codec_type'] == "video") {
  133. echo "<b style='font-size: 20px;color: red;'>Low resolution!</b></br>";
  134. }
  135.  
  136.  
  137. if(strpos(strtolower($stream['tags']->title), 'forced') !== false) {
  138. if(strtolower($stream['tags']->language) == "cz" || strtolower($stream['tags']->language) == "cze" || strtolower($stream['tags']->language) == "czech" || strtolower($stream['tags']->language) == "cs") {
  139. $file_path = $dir . $filename;
  140.  
  141. $titleSubs = file_get_contents("http://vps403015.ovh.net/playbe/webshareGetFinalTitle.php?file=" . urlencode(trim($filename)));
  142. if($titleSubs) {
  143. $file_path_subs = '/home/storage/success/forced/' . $titleSubs . ".srt";
  144. } else {
  145. $file_path_subs = '/home/storage/success/forced/' . $filename . ".srt";
  146. }
  147.  
  148. echo "<b style='background-color: blue; color: white;'>FOUND FORCED SUBTITLES</b></br>";
  149. echo "<i style='font-size: 14px; color: #555;'>ffmpeg -i \"$file_path\" -map 0:" . $stream['index'] . " \"$file_path_subs\"</i>";
  150. }
  151. }
  152.  
  153.  
  154. if(!$audioFound) {
  155. if($isCze) {
  156. if(count($streams) == 2) {
  157. if($stream['codec_type'] == "audio") {
  158. $audioMap = $stream['index'];
  159. $audioFound = true;
  160. echo "<span style='background-color: green; color: white; letter-spacing: 5px;'><<<<<<<<<</span>";
  161. }
  162. } else {
  163. if($stream['codec_type'] == "audio") {
  164. 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") {
  165. $audioMap = $stream['index'];
  166. $audioFound = true;
  167. echo "<span style='background-color: green; color: white; letter-spacing: 5px;'><<<<<<<<<</span>";
  168. }
  169. }
  170. }
  171. } else {
  172. if(count($streams) == 2 || count($streams) == 3) {
  173. if($stream['codec_type'] == "audio") {
  174. $audioMap = $stream['index'];
  175. $audioFound = true;
  176. echo "<span style='background-color: green; color: white; letter-spacing: 5px;'><<<<<<<<<</span>";
  177. }
  178. } else {
  179. if($stream['codec_type'] == "audio") {
  180. //if($stream['tags']->title == "English" || $stream['tags']->title == "Eng" || $stream['tags']->title == "En" || $stream['tags']->language == "eng" || $stream['tags']->LANGUAGE == "eng") {
  181. $audioMap = $stream['index'];
  182. $audioFound = true;
  183. echo "<span style='background-color: green; color: white; letter-spacing: 5px;'><<<<<<<<<</span>";
  184. //}
  185. }
  186. }
  187. }
  188. }
  189.  
  190. if($audioMap == $stream['index'] && $audioFound) {
  191. $file_path = $dir . $filename;
  192. $file_path_audio = $dir . $filename . "_zvuk.mp4";
  193. $file_path_video = $dir . $filename . "_video.mp4";
  194. $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";
  195. //echo "</br><pre>";print_r($stream);echo "</pre>";
  196. echo "</br>";
  197.  
  198. if($streams[$foundVideoMap]->codec_name == "h264") {
  199. //is map h264
  200. $command_v = "ffmpeg -i \"$file_path\" -c copy -map 0:0$foundVideoMap \"$file_path_video\"";
  201.  
  202. } else {
  203. //is not map h264
  204. $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\"";
  205.  
  206. }
  207.  
  208. //$command_v = "ffmpeg -i \"$file_path\" -c copy -c:v libx264 -preset ultrafast $video_part_cmd -map 0:0$foundVideoMap \"$file_path_video\"";
  209. $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\"";
  210. $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\"";
  211. //$command_m = "ffmpeg -i \"$file_path_video\" -i \"$file_path_audio\" -c copy -map 0:0 -map 1:0 \"$file_path_final\"";
  212. $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\"";
  213. $command_all = $command_v . " && " . $command_a . " && " . $command_m;
  214. $command_one = $command_all;
  215.  
  216.  
  217. if(file_exists($file_path_final)) {
  218. $finalExists = ' border-left: 30px solid green;';
  219. } else {
  220. $finalExists = ' border-left: 30px solid orange;';
  221. if(is_numeric($foundVideoMap)) {
  222. if($finalCommand != "") {
  223. //$finalCommand .= " && " . $command_v . " && " . $command_a . " && " . $command_m;
  224. $finalCommand .= " ; " . $command_one;
  225. } else {
  226. //$finalCommand .= $command_v . " && " . $command_a . " && " . $command_m;
  227. $finalCommand .= $command_one;
  228. }
  229. }
  230.  
  231.  
  232. if($_GET['exec']) {
  233. exec('pgrep -c ffmpeg', $countFFMPEG);
  234. //echo "<script>setTimeout(function(){window.location.reload(1);}, 60000);</script>";
  235. if($countFFMPEG[0] <= 1) {
  236. if($counterExec < (1 - $countFFMPEG[0])) {
  237. echo "<h1>Execute command... </h1>";
  238. $command_exec = $command_one . " > /dev/null 2>&1 &";
  239. exec($command_exec);
  240. $counterExec++;
  241. }
  242. }
  243. }
  244. }
  245.  
  246. echo "<i style='font-size: 14px; color: #555;$finalExists'>$command_v</i>";
  247. echo "</br>";
  248.  
  249. echo "<i style='font-size: 14px; color: #555;$finalExists'>$command_a</i>";
  250. echo "</br>";
  251.  
  252. echo "<i style='font-size: 14px; color: #555;$finalExists'>$command_m</i>";
  253. echo "</br>";
  254.  
  255. echo "<i style='font-size: 14px; color: #555;$finalExists'>$command_one</i>";
  256. echo "</br>";
  257.  
  258.  
  259.  
  260.  
  261. }
  262. echo "</br>";
  263.  
  264. }
  265. }
  266. echo "</br>";
  267. echo "</br>";
  268. echo "<h2>Final Command:</h2>";
  269. echo "(" . $finalCommand . ")";
  270. /*
  271. echo "<pre>";
  272. print_r($files);
  273. echo "</pre>";
  274.  
  275.  
  276.  
  277.  
  278.  
  279. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement