diff --git a/app/Console/Commands/LiveVideoCommand.php b/app/Console/Commands/LiveVideoCommand.php index 99af775..da2cb22 100644 --- a/app/Console/Commands/LiveVideoCommand.php +++ b/app/Console/Commands/LiveVideoCommand.php @@ -12,7 +12,7 @@ class LiveVideoCommand extends Command * * @var string */ - protected $signature = 'live:process'; + protected $signature = 'live:process {source} {destination}'; /** * The console command description. @@ -39,7 +39,9 @@ class LiveVideoCommand extends Command public function handle() { // + $source = $this->argument("source"); + $destination = $this->argument("destination"); $service = new LiveStreamService(); - $service->moveFilesAndRenameFiles(escapeshellarg("/Volumes/Crucial X6/temp0"), escapeshellarg("/Volumes/Crucial X6/temp1")); + $service->moveFilesAndRenameFiles($source, $destination); } } diff --git a/app/Console/Commands/QueueFfmpegCommand.php b/app/Console/Commands/QueueFfmpegCommand.php index aed968f..dbf3aa5 100644 --- a/app/Console/Commands/QueueFfmpegCommand.php +++ b/app/Console/Commands/QueueFfmpegCommand.php @@ -46,10 +46,11 @@ class QueueFfmpegCommand extends Command if ($command == "add") { $queuedFfmpegService->processDir($path); } else { - $ffmpeg = new FfmpegService(); - $ffmpeg->setNeedRemoveExistFiles(false); - $ffmpeg->setNeedRemoveAfterEncode(true); - $ffmpeg->processDirWithQueue($path, "file_to_encode"); + $queuedFfmpegService->processQueue(); +// $ffmpeg = new FfmpegService(); +// $ffmpeg->setNeedRemoveExistFiles(false); +// $ffmpeg->setNeedRemoveAfterEncode(true); +// $ffmpeg->processDirWithQueue($path, "file_to_encode"); } } } diff --git a/app/Http/Controllers/WeiboController.php b/app/Http/Controllers/WeiboController.php index d987b60..9c090a6 100644 --- a/app/Http/Controllers/WeiboController.php +++ b/app/Http/Controllers/WeiboController.php @@ -64,14 +64,14 @@ class WeiboController extends Controller // $url[] = 'https://m.weibo.cn/api/container/getIndex?containerid=1076035893812490&openApp=0&page='.$i; // for( $i = 100; $i >= 1 ; $i-- ) // $url[] = 'https://m.weibo.cn/api/container/getIndex?containerid=2304133907143723&openApp=0&page='.$i; - for ($i = 100; $i >= 1; $i--) { - $url[] = 'https://m.weibo.cn/feed/group?gid=4423532052076817&&page=' . $i; - } - // foreach ($list as $key => $value) { - // for ($i = $size; $i >= 1; $i--) { - // $url[] = "https://m.weibo.cn/api/container/getIndex?containerid=$value&page=" . $i; - // } - // } + for ($i = 100; $i >= 1; $i--) { + $url[] = 'https://m.weibo.cn/feed/group?gid=4423532052076817&&page=' . $i; + } + // foreach ($list as $key => $value) { + // for ($i = $size; $i >= 1; $i--) { + // $url[] = "https://m.weibo.cn/api/container/getIndex?containerid=$value&page=" . $i; + // } + // } // for ($i = $size; $i >= 1; $i--) { // $url[] = 'https://m.weibo.cn/api/container/getIndex?containerid=230259&page=' . $i; // } @@ -111,8 +111,8 @@ class WeiboController extends Controller // die(); // Log::info($request->input()); $weibo = new WeiboService(); - // $result = $weibo->scrapeWeiboPicAndVideo($request->input("content")); - $result = $weibo->scrapeGroupWeiboPicAndVideo($request->input("content")); + // $result = $weibo->scrapeWeiboPicAndVideo($request->input("content")); + $result = $weibo->scrapeGroupWeiboPicAndVideo($request->input("content")); return response()->json($result); } diff --git a/app/Services/FileService.php b/app/Services/FileService.php index a158736..a47cf13 100644 --- a/app/Services/FileService.php +++ b/app/Services/FileService.php @@ -1,11 +1,16 @@ queuedFfmpegService = new QueuedFfmpegService(); + } + public function segmentFiles($baseDir) { if (!is_dir($baseDir)) { @@ -1192,13 +1197,16 @@ class FileService { } $files = scandir($dir); foreach ($files as $file) { + if (skipDefaultPathAndFile($file)) { + continue; + } $currentItem = implode(DIRECTORY_SEPARATOR, [$dir, $file]); if (is_dir($currentItem)) { $this->deleteFilesForExtensions($currentItem, $extensions); } if (is_file($currentItem)) { - $pathinfo = pathinfo($currentItem); - if (in_array($pathinfo[PATHINFO_EXTENSION], $extensions)) { + $pathInfo = pathinfo($currentItem); + if (in_array($pathInfo[PATHINFO_EXTENSION], $extensions)) { dump("now delete file $currentItem"); unlink($currentItem); } @@ -1214,6 +1222,9 @@ class FileService { } $files = scandir($dir); foreach ($files as $file) { + if (skipDefaultPathAndFile($file)) { + continue; + } $currentItem = implode(DIRECTORY_SEPARATOR, [$dir, $file]); if (is_dir($currentItem)) { $this->renameFileExtensionToAnother($currentItem, $fromExtension, $toExtension); @@ -1221,8 +1232,10 @@ class FileService { if (is_file($currentItem)) { $pathInfo = pathinfo($currentItem); if ($pathInfo[PATHINFO_EXTENSION] == $fromExtension) { - dump("now rename file $currentItem"); - rename($currentItem, str_replace($fromExtension, $toExtension, $currentItem)); + $newFile = str_replace($fromExtension, $toExtension, $currentItem); + dump("now rename file $currentItem to $newFile"); + rename($currentItem, $newFile); + $this->queuedFfmpegService->addToQueue($newFile); } } diff --git a/app/Services/GooglePhotoSyncService.php b/app/Services/GooglePhotoSyncService.php index a15c0d5..d562ae7 100644 --- a/app/Services/GooglePhotoSyncService.php +++ b/app/Services/GooglePhotoSyncService.php @@ -12,14 +12,14 @@ use Illuminate\Support\Facades\Redis; class GooglePhotoSyncService { private $map = [ - "/Users/shixuesen/Documents/local/xg/zz" => "/Users/shixuesen/Documents/sync/image/芝芝Booty", - "/Users/shixuesen/Documents/local/xg/wyc" => "/Users/shixuesen/Documents/sync/image/王雨纯", - "/Users/shixuesen/Documents/local/xg/ycc" => "/Users/shixuesen/Documents/sync/image/杨晨晨", - "/Users/shixuesen/Documents/local/xg/hlr" => "/Users/shixuesen/Documents/sync/image/黄乐然", - "/Users/shixuesen/Documents/local/xg/jrq" => "/Users/shixuesen/Documents/sync/image/姜仁卿", - "/Users/shixuesen/Documents/local/xg/azu" => "/Users/shixuesen/Documents/sync/image/是阿朱啊", - "/Users/shixuesen/Documents/local/xg/xq" => "/Users/shixuesen/Documents/sync/image/小琪", - "/Users/shixuesen/Documents/local/xg/小雪" => "/Users/shixuesen/Documents/sync/image/小雪", + // "/Users/shixuesen/Documents/local/xg/zz" => "/Users/shixuesen/Documents/sync/image/芝芝Booty", + // "/Users/shixuesen/Documents/local/xg/wyc" => "/Users/shixuesen/Documents/sync/image/王雨纯", + // "/Users/shixuesen/Documents/local/xg/ycc" => "/Users/shixuesen/Documents/sync/image/杨晨晨", + // "/Users/shixuesen/Documents/local/xg/hlr" => "/Users/shixuesen/Documents/sync/image/黄乐然", + // "/Users/shixuesen/Documents/local/xg/jrq" => "/Users/shixuesen/Documents/sync/image/姜仁卿", + // "/Users/shixuesen/Documents/local/xg/azu" => "/Users/shixuesen/Documents/sync/image/是阿朱啊", + // "/Users/shixuesen/Documents/local/xg/xq" => "/Users/shixuesen/Documents/sync/image/小琪", + // "/Users/shixuesen/Documents/local/xg/小雪" => "/Users/shixuesen/Documents/sync/image/小雪", "/Users/shixuesen/OneDrive/Pictures/instagram/Likes_new" => "/Users/shixuesen/Documents/sync/image/instagram/Likes", "/Users/shixuesen/OneDrive/Pictures/instagram/boram__jj" => "/Users/shixuesen/Documents/sync/image/instagram/boram__jj", "/Users/shixuesen/OneDrive/Pictures/instagram/cho_hyunyoung" => "/Users/shixuesen/Documents/sync/image/instagram/cho_hyunyoung", diff --git a/app/Services/QueuedFfmpegService.php b/app/Services/QueuedFfmpegService.php index c008718..9f7a11c 100644 --- a/app/Services/QueuedFfmpegService.php +++ b/app/Services/QueuedFfmpegService.php @@ -6,11 +6,22 @@ namespace App\Services; use App\Jobs\BilibiliEncode; +use App\Services\FfmpegService; +use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Redis; class QueuedFfmpegService { + private $ffmpegService; + + public function __construct() + { + $this->ffmpegService = new FfmpegService(); + $this->ffmpegService->setNeedRemoveAfterEncode(true); + $this->ffmpegService->setNeedRemoveExistFiles(false); + } + public function processDir($path) { $files = scandir($path); @@ -38,14 +49,25 @@ class QueuedFfmpegService { public function processQueue() { - $ffmpeg = new FfmpegService(); - $ffmpeg->setNeedRemoveAfterEncode(true); - $ffmpeg->setNeedRemoveExistFiles(false); - $item = Redis::connection()->rpop("file_to_encode"); - while ($item != null) { - echo $item . "\n"; + while (true) { + Log::info("start or restart process files in redis queue"); + $empty = true; $item = Redis::connection()->rpop("file_to_encode"); + while ($item != null) { + echo $item . "\n"; + $empty = false; + $item = Redis::connection()->rpop("file_to_encode"); + $this->ffmpegService->processVideo($item); + } + if ($empty) { + Log::info("process end sleep 300 seconds"); + } else { + Log::info("process queue empty sleep 300 seconds"); + } + + sleep(5 *60); } + exit; diff --git a/app/Utils/helper.php b/app/Utils/helper.php index 2ff558b..cb70268 100644 --- a/app/Utils/helper.php +++ b/app/Utils/helper.php @@ -98,3 +98,16 @@ function scanFilesWithoutPath($path): array } return $allFiles; } + +/** + * 跳过一些不需要处理的默认文件和路径 + * @param $file + * @return bool + */ +function skipDefaultPathAndFile($file): bool +{ + if ($file == "." || $file == ".." || $file == "config.json" || $file == "config.backup.json" || $file == ".DS_Store") { + return true; + } + return false; +} diff --git a/fail.log b/fail.log index 26a6cc4..182b123 100644 --- a/fail.log +++ b/fail.log @@ -2506,3 +2506,5 @@ /Users/shixuesen/OneDrive/Pictures/instagram/Likes_new/ https://scontent-lax3-1.cdninstagram.com/v/t51.2885-15/296811179_340837064930295_7523838812031641639_n.jpg?se=7&stp=dst-jpg_e35&cb=9ad74b5e-88ad7ee8&_nc_ht=scontent-lax3-1.cdninstagram.com&_nc_cat=1&_nc_ohc=jxXC8f4uF6cAX_Z-rkl&edm=AJ9x6zYBAAAA&ccb=7-5&ig_cache_key=Mjg5NTMyMTMyMDk4NjYyNDc4NA%3D%3D.2-ccb7-5&oh=00_AT_CXTztJbu8B3BZB9X2JpZQMrP7Dj1vahMOg0xNRi5AKA&oe=62EFF4B7&_nc_sid=cff2a4 /Users/shixuesen/OneDrive/Pictures/instagram/Likes_new/ https://scontent-lax3-1.cdninstagram.com/v/t51.2885-15/296953228_4113298422128218_4574269060691064940_n.jpg?stp=dst-jpg_e35&cb=9ad74b5e-88ad7ee8&_nc_ht=scontent-lax3-1.cdninstagram.com&_nc_cat=110&_nc_ohc=f3gfzOdhOgoAX8r1Uhh&edm=AJ9x6zYBAAAA&ccb=7-5&ig_cache_key=Mjg5NTQwMTY5NjE5MzcwNjg2Mw%3D%3D.2-ccb7-5&oh=00_AT-l9pHDqdmFIBvcf-FbakXbP7xXd01cmQ-TBhzVC9XitQ&oe=62EEEA83&_nc_sid=cff2a4 /Users/shixuesen/OneDrive/Pictures/instagram/sabrina5477_/ https://scontent-lax3-1.cdninstagram.com/v/t51.2885-15/297094511_299020245760978_6957926679087025812_n.jpg?se=7&stp=dst-jpg_e35&cb=9ad74b5e-88ad7ee8&_nc_ht=scontent-lax3-1.cdninstagram.com&_nc_cat=110&_nc_ohc=EdywP8TtnUkAX985VWM&edm=ABmJApABAAAA&ccb=7-5&ig_cache_key=Mjg5NTg2MTMzNTc5ODg5OTg0Nw%3D%3D.2-ccb7-5&oh=00_AT8rjOPKo2LZRA_IfHHkxOrHqZMz6KNHB0Oijf9yB7ZueQ&oe=62F087CA&_nc_sid=6136e7 +/Users/shixuesen/OneDrive/Pictures/instagram/Likes_new/ https://scontent-lax3-1.cdninstagram.com/v/t51.2885-15/296619854_185315873945889_6427142494510404340_n.jpg?se=8&stp=dst-jpg_e35&cb=9ad74b5e-88ad7ee8&_nc_ht=scontent-lax3-1.cdninstagram.com&_nc_cat=109&_nc_ohc=ZXBQqMcTc6wAX_bLd1b&edm=AJ9x6zYBAAAA&ccb=7-5&ig_cache_key=Mjg5NTk0NzU0Nzg5MDEyNjkzNg%3D%3D.2-ccb7-5&oh=00_AT8xtPVRnSQ1VQxCJp0KjGyMPDz3pDIP4QL-ZYJV0mNgnw&oe=62F0F94A&_nc_sid=cff2a4 +/Users/shixuesen/OneDrive/Pictures/instagram/Likes_new/ https://scontent-lax3-2.cdninstagram.com/v/t51.2885-15/291654716_5088827331229239_6353550709360795777_n.webp?se=7&stp=dst-jpg_e35&cb=9ad74b5e-88ad7ee8&_nc_ht=scontent-lax3-2.cdninstagram.com&_nc_cat=103&_nc_ohc=4ktY5JR706MAX8WkEFo&edm=AJ9x6zYBAAAA&ccb=7-5&ig_cache_key=Mjg5OTA3OTM5NDA3NTUxNzM3Mw%3D%3D.2-ccb7-5&oh=00_AT_UF4h06k0YujITCfquLoRmFFmC8tBA7MMancP3Su37zw&oe=62F85BB0&_nc_sid=cff2a4