You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

59 lines
2.8 KiB

<?php
namespace App\Services;
class HandBrakeService
{
public function handleVideos($dir = "N:\\v\\91麻豆国产原创剧情片\\")
{
setlocale(LC_ALL, ['zh_CN.gbk', 'zh_CN.gb2312', 'zh_CN.gb18030']);
$files = scandir($dir);
// $files = array_slice($files, 128);
foreach ($files as $file) {
if ($file == "." || $file == "..") {
continue;
}
$subDir = implode("\\", [$dir, $file]);
$isDir = is_dir($subDir);
if ($isDir) {
$subFiles = scandir($subDir);
foreach ($subFiles as $subFile) {
$subPathFile = implode("\\", [$subDir, $subFile]);
if (is_dir($subPathFile) || $subFile == ".DS_Store") {
continue;
}
$mime = mime_content_type($subPathFile);
// dump("file type", [$mime, $subPathFile]);
// continue;
if (strstr($mime, "video/")) {
if (is_file($subPathFile)) {
$fileInfo = pathinfo($subPathFile);
dump("fileInfo", $fileInfo);
if (ends_with($fileInfo["filename"], "-1")) {
continue;
}
$subPathFileArr = explode("." . $fileInfo["extension"], $subPathFile);
if (is_file($subPathFileArr[0] . '-1'. '.' . $fileInfo["extension"])) {
unlink($subPathFile);
continue;
}
$targetFile = $subPathFileArr[0] . '-1'. '.' . $fileInfo["extension"];
// $result = shell_exec("handBrakeCli -Z 'Very Fast 720p30' -i '". $subPathFile ."' -o '". $targetFile . " && echo 'success'");
// dump("D:\Software\HandBrakeCLI-1.3.3-win-x86_64\HandBrakeCLI.exe -Z \"Very Fast 720p30\" -i '". $subPathFile ."' -o '". $targetFile . "'");exit;
file_put_contents("video.ps1", iconv('UTF-8', 'GBK', "D:\Software\HandBrakeCLI-1.3.3-win-x86_64\HandBrakeCLI.exe -Z \"Very Fast 720p30\" -i '". $subPathFile ."' -o '". $targetFile . "'"));
// $result = shell_exec("D:\Software\HandBrakeCLI-1.3.3-win-x86_64\HandBrakeCLI.exe -Z \"Very Fast 720p30\" -i '". $subPathFile ."' -o '". $targetFile . "");
$result = shell_exec( 'powershell.exe -executionpolicy bypass -NoProfile -File ".\video.ps1"');
dump($result);
}
}
}
}
}
print_r($files);
}
}