<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
//use App\Services\FileService;
|
|
use App\Services\GooglePhotoSyncService;
|
|
|
|
//use App\Services\LiveStreamService;
|
|
use GuzzleHttp\Client;
|
|
use GuzzleHttp\Psr7\Request;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\Redis;
|
|
|
|
class TestCommand extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'test:all';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Command description';
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle()
|
|
{
|
|
// $this->test02();
|
|
// exit;
|
|
$this->test5();exit;
|
|
$this->test01();exit;
|
|
$this->test04();exit;
|
|
|
|
// echo strlen("[VLOG] 메이드와 단 둘이 청소하실래요-ㅣ메이드복 입고 청소하기__ㅣ모델 일상 코스프레 브이로그ㅣCleaning Maid Cosplayㅣメイドといっしょに掃除しませんか?");exit;
|
|
// $service = new GooglePhotoSyncService();
|
|
// $service->syncDBToRedis();exit;
|
|
// $service->insertMappings();exit;
|
|
// $service->syncImageFiles();
|
|
// exit;
|
|
// $baseDir = "/Users/shixuesen/Documents/sync/image";
|
|
$baseDir = "/Users/shixuesen/Documents/otherSync/very";
|
|
$baseDir = "/Users/shixuesen/Downloads/y";
|
|
$dirs = ["mv"];
|
|
$files = [];
|
|
foreach ($dirs as $dir) {
|
|
$currentFiles = scandir($baseDir . DIRECTORY_SEPARATOR . $dir);
|
|
foreach ($currentFiles as $file) {
|
|
if ($file == "." || $file == ".." || $file == ".DS_Store" || is_dir($baseDir . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . $file)) {
|
|
continue;
|
|
}
|
|
$files[] = $baseDir . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . $file;
|
|
}
|
|
|
|
// $files = array_merge($files, $currentFiles);
|
|
}
|
|
|
|
$md5Set = [];
|
|
|
|
// $newDir = "/Users/shixuesen/Downloads/y/Nagisa魔物喵202003fantia会员合集/魔物喵__001";
|
|
// mkdir($newDir);
|
|
$i = 0;
|
|
foreach ($files as $file) {
|
|
if ($file == "." || $file == ".." || $file == ".DS_Store") {
|
|
continue;
|
|
}
|
|
$hash = md5_file($file);
|
|
if (array_key_exists($hash, $md5Set)) {
|
|
echo "file is same $file, and {$md5Set[$hash]} \n";
|
|
// rename($dir . DIRECTORY_SEPARATOR . $file, $newDir . DIRECTORY_SEPARATOR . $file);
|
|
// exit;
|
|
$i++;
|
|
} else {
|
|
$md5Set[$hash] = $file;
|
|
}
|
|
}
|
|
echo "all same file count is $i";
|
|
exit;
|
|
// $pid = pcntl_fork();
|
|
$childs = array();
|
|
|
|
$cmds = array(
|
|
array('/Users/shixuesen/Downloads/temp/dir1/1.txt', '/Users/shixuesen/Downloads/temp/dir2/1.txt'),
|
|
array('/Users/shixuesen/Downloads/temp/dir1/1.txt', '/Users/shixuesen/Downloads/temp/dir3/1.txt'),
|
|
array('/Users/shixuesen/Downloads/temp/dir1/1.txt', '/Users/shixuesen/Downloads/temp/dir4/1.txt')
|
|
);
|
|
|
|
echo 'begin';
|
|
echo date("Y-m-d H:i:s");
|
|
|
|
foreach ($cmds as $cmd) {
|
|
$pid = pcntl_fork();
|
|
if ($pid == -1) {// process creation failed
|
|
die('fork child process failure!');
|
|
} else if ($pid) {// parent process logic
|
|
$childs[] = $pid;
|
|
pcntl_wait($status, WNOHANG);
|
|
} else {// sub-process processing logic
|
|
pcntl_exec('/bin/cp', $cmd);
|
|
}
|
|
}
|
|
while (count($childs) > 0) {
|
|
foreach ($childs as $key => $pid) {
|
|
$res = pcntl_waitpid($pid, $status, WNOHANG);
|
|
|
|
//1 for error, greater than 0 representative process has been withdrawn, returns to the pid of the sub-process, and 0 representatives have not been able to take the exit sub-process when it is not blocked
|
|
if ($res == -1 || $res > 0)
|
|
unset($childs[$key]);
|
|
}
|
|
|
|
sleep(1);
|
|
}
|
|
|
|
echo "start sleep";
|
|
sleep(100);
|
|
echo date("Y-m-d H:i:s");
|
|
echo 'done';
|
|
exit;
|
|
echo time() . "\n";
|
|
$pid = pcntl_fork();
|
|
if ($pid == -1) {
|
|
die('could not fork');
|
|
} else if ($pid) {
|
|
// we are the parent
|
|
pcntl_wait($status); //Protect against Zombie children
|
|
} else {
|
|
// we are the child
|
|
pcntl_exec("/bin/cp", ["/Users/shixuesen/Downloads/temp/dir1/1.txt", "/Users/shixuesen/Downloads/temp/dir2/1.txt"]);
|
|
}
|
|
|
|
|
|
pcntl_exec("/bin/cp", ["/Users/shixuesen/Downloads/temp/dir1/1.txt", "/Users/shixuesen/Downloads/temp/dir3/1.txt"]);
|
|
pcntl_exec("/bin/cp", ["/Users/shixuesen/Downloads/temp/dir1/1.txt", "/Users/shixuesen/Downloads/temp/dir4/1.txt"]);
|
|
echo time();
|
|
exit;
|
|
|
|
$service = new GooglePhotoSyncService();
|
|
// $service->syncDBToRedis();exit;
|
|
// $service->insertMappings();exit;
|
|
$service->syncImageFiles();
|
|
exit;
|
|
// $service = new FileService();
|
|
// $service->queryFileTime("/Users/shixuesen/Documents/sync/image/instagram/mobe_carrie0223/mobe__0020/82339160_561812341080795_8865402232426240219_n.jpg");exit;
|
|
// echo $service->processDirAndFindLastFileMTime("/Users/shixuesen/Documents/sync/image/weibo/");exit;
|
|
// $service = new LiveStreamService();
|
|
// $service->moveFilesAndRenameFiles("/Users/shixuesen/Downloads/rsyncFiles/a", "/Users/shixuesen/Downloads/rsyncFiles/b");
|
|
// exit;
|
|
// $a = str_replace("/", "", "aaaaa/bbbb");
|
|
// echo $a;exit;
|
|
//
|
|
$file = "/Volumes/Crucial X6/Image/weibo/image/一只小短短OwO--7f605a17gy1gxpb0pg31vj22eo37k1kz.jpg";
|
|
$file = "/Users/shixuesen/Documents/sync/image/instagram/Likes/eeelyeee_277962893_719835709026094_2370282265319075961_n.jpg";
|
|
// $file = "/Users/shixuesen/OneDrive/Pictures/instagram/Likes_new/eeelyeee_277962893_719835709026094_2370282265319075961_n.jpg";
|
|
|
|
|
|
$file = "/Users/shixuesen/Documents/sync/image/instagram/boram__jj/277958530_1581189285586989_5049761303029075957_n.jpg";
|
|
// $file = "/Users/shixuesen/OneDrive/Pictures/instagram/boram__jj/277958530_1581189285586989_5049761303029075957_n.jpg";
|
|
$mtime = date("Y-m-d H:i:s", filemtime($file));
|
|
$atime = date("Y-m-d H:i:s", fileatime($file));
|
|
$ctime = date("Y-m-d H:i:s", filectime($file));
|
|
// $stat = stat($file);
|
|
echo "file mtime is $mtime, atime is $atime, ctime is $ctime";
|
|
// dump($stat);
|
|
|
|
}
|
|
|
|
public function test01()
|
|
{
|
|
$keys = Redis::connection("cache_txy4")->lrange("file_to_encode", 0, -1);
|
|
foreach ($keys as $key) {
|
|
if (str_contains($key, "崔兔子")) {
|
|
// echo $key;
|
|
Redis::connection("cache_txy4")->lrem("file_to_encode", 0, $key);
|
|
}
|
|
}
|
|
// dump($keys);
|
|
// echo Redis::connection("cache_txy4")->get("aaaaaa");exit;
|
|
}
|
|
|
|
public function test02()
|
|
{
|
|
$url = "https://wx4.sinaimg.cn/large/a2ca2fd3ly1hdcbwq251wj20h70fi0zi.jpg";
|
|
$urlInfo = parse_url($url);
|
|
$host = $urlInfo["host"];
|
|
$client = new Client();
|
|
$headers = [
|
|
'authority' => $host,
|
|
'accept' => 'image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8',
|
|
'accept-language' => 'zh-CN,zh;q=0.9',
|
|
'cache-control' => 'no-cache',
|
|
'pragma' => 'no-cache',
|
|
'referer' => 'https://m.weibo.cn/',
|
|
'sec-ch-ua' => '"Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"',
|
|
'sec-ch-ua-mobile' => '?0',
|
|
'sec-ch-ua-platform' => '"macOS"',
|
|
'sec-fetch-dest' => 'image',
|
|
'sec-fetch-mode' => 'no-cors',
|
|
'sec-fetch-site' => 'cross-site',
|
|
'user-agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36'
|
|
];
|
|
$request = new Request('GET', $url, $headers);
|
|
$res = $client->sendAsync($request)->wait();
|
|
return $res->getBody();
|
|
}
|
|
|
|
public function test03()
|
|
{
|
|
$list = Redis::connection()->smembers("永远别问为什么");
|
|
$files = scandir("/Volumes/Xcode");
|
|
foreach ($files as $file) {
|
|
if ($file == "." || $file == "..") {
|
|
continue;
|
|
}
|
|
if (!in_array($file, $list)) {
|
|
echo "$file not in array \n";
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public function test04()
|
|
{
|
|
// $baseDir = "/Volumes/Xcode/";
|
|
$baseDir = "/Users/shixuesen/Documents/otherSync/very";
|
|
$dirs = ["weibo_image03"];
|
|
$files = [];
|
|
foreach ($dirs as $dir) {
|
|
$currentFiles = scandir($baseDir . DIRECTORY_SEPARATOR . $dir);
|
|
foreach ($currentFiles as $file) {
|
|
if ($file == "." || $file == ".." || $file == ".DS_Store" || is_dir($baseDir . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . $file)) {
|
|
continue;
|
|
}
|
|
$files[] = $baseDir . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . $file;
|
|
}
|
|
|
|
// $files = array_merge($files, $currentFiles);
|
|
}
|
|
|
|
$md5Set = [];
|
|
|
|
// $newDir = "/Users/shixuesen/Downloads/y/Nagisa魔物喵202003fantia会员合集/魔物喵__001";
|
|
// mkdir($newDir);
|
|
$i = 0;
|
|
foreach ($files as $file) {
|
|
if ($file == "." || $file == ".." || $file == ".DS_Store") {
|
|
continue;
|
|
}
|
|
$hash = md5_file($file);
|
|
if (array_key_exists($hash, $md5Set)) {
|
|
echo "file is same $file, and {$md5Set[$hash]} \n";
|
|
// rename($dir . DIRECTORY_SEPARATOR . $file, $newDir . DIRECTORY_SEPARATOR . $file);
|
|
// exit;
|
|
$i++;
|
|
} else {
|
|
$md5Set[$hash] = $file;
|
|
}
|
|
}
|
|
echo "all same file count is $i";
|
|
exit;
|
|
}
|
|
|
|
public function test5()
|
|
{
|
|
$dir = "/Volumes/Crucial X6/Image/6001-6050/6001-6050.7z";
|
|
$files = scandir($dir);
|
|
$set = [];
|
|
foreach ($files as $file) {
|
|
if ($file == "." || $file == ".." || $file == ".DS_Store") {
|
|
continue;
|
|
}
|
|
preg_match("#NO.\d+\s(\S+)\[#", $file, $matches);
|
|
$owner_name = $matches[1];
|
|
if (array_key_exists($owner_name, $set)) {
|
|
dump("$owner_name exists");
|
|
} else {
|
|
$set[$owner_name] = 1;
|
|
}
|
|
// dump($owner_name);
|
|
|
|
|
|
}
|
|
|
|
}
|
|
}
|