Browse Source

modify queued process

feature/new_bilibili_and_instagram_sxs20191126
shixuesen 3 years ago
parent
commit
83ca6380e7
8 changed files with 89 additions and 36 deletions
  1. +4
    -2
      app/Console/Commands/LiveVideoCommand.php
  2. +5
    -4
      app/Console/Commands/QueueFfmpegCommand.php
  3. +10
    -10
      app/Http/Controllers/WeiboController.php
  4. +19
    -6
      app/Services/FileService.php
  5. +8
    -8
      app/Services/GooglePhotoSyncService.php
  6. +28
    -6
      app/Services/QueuedFfmpegService.php
  7. +13
    -0
      app/Utils/helper.php
  8. +2
    -0
      fail.log

+ 4
- 2
app/Console/Commands/LiveVideoCommand.php View File

@ -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);
}
}

+ 5
- 4
app/Console/Commands/QueueFfmpegCommand.php View File

@ -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");
}
}
}

+ 10
- 10
app/Http/Controllers/WeiboController.php View File

@ -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);
}


+ 19
- 6
app/Services/FileService.php View File

@ -1,11 +1,16 @@
<?php
namespace App\Services;
use DateTime;
use Log;
use Symfony\Component\Finder\Finder;
use App\Services\QueuedFfmpegService;
class FileService {
private $queuedFfmpegService;
public function __construct() {
$this->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);
}
}


+ 8
- 8
app/Services/GooglePhotoSyncService.php View File

@ -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",


+ 28
- 6
app/Services/QueuedFfmpegService.php View File

@ -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;


+ 13
- 0
app/Utils/helper.php View File

@ -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;
}

+ 2
- 0
fail.log View File

@ -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

Loading…
Cancel
Save