<?php
|
|
namespace App\Services;
|
|
use Illuminate\Support\Facades\Redis;
|
|
use Log;
|
|
use QL\QueryList;
|
|
|
|
class FullSiteService {
|
|
|
|
public function fullSiteDownloadImage()
|
|
{
|
|
$dir = "/Volumes/WD/tmp/site/mm24.cc/simu/";
|
|
$files = scandir($dir);
|
|
dump("total files count is " . count($files));
|
|
// $files = array_slice($files, 38300);
|
|
$ql = QueryList::getInstance();
|
|
$i = 0;
|
|
foreach ($files as $file) {
|
|
$i++;
|
|
if ($i % 100 == 0) {
|
|
dump("current counter i is ". $i . "\n");
|
|
}
|
|
if ($file == "." || $file == ".." || $file == ".DS_Store") {
|
|
continue;
|
|
}
|
|
// $htmlNum = substr($file, 0, 4);
|
|
// if ((int)$htmlNum < 3776) {
|
|
// continue;
|
|
// }
|
|
if (str_contains($file, "html")) {
|
|
dump($file);
|
|
$ql = $ql->html(file_get_contents($dir. "/" . $file));
|
|
$rt = $ql->find('img')->attrs('src');
|
|
dump($rt);
|
|
foreach ($rt as $r) {
|
|
$filePathInfo = pathinfo($r);
|
|
// 获取相对路径
|
|
$path = parse_url($filePathInfo['dirname'])['path'];
|
|
if (str_contains($path, "..")) {
|
|
$localFilePath = $dir . $path . "/";
|
|
} else {
|
|
$localFilePath = $dir . "../" . $path . "/";
|
|
}
|
|
if (is_file($localFilePath . $filePathInfo["basename"])) {
|
|
continue;
|
|
}
|
|
if (!is_dir($localFilePath)) {
|
|
mkdir($localFilePath, 0777, true);
|
|
}
|
|
try {
|
|
$content = file_get_contents($r);
|
|
} catch (\Exception $e) {
|
|
Log::error("current url is " . $r . " trace: " . $e->getTraceAsString());
|
|
continue;
|
|
}
|
|
file_put_contents($dir . "../" . $path . "/" .$filePathInfo["basename"], $content);
|
|
usleep(100 * random_int(1000, 10000));
|
|
}
|
|
// dump($rt);exit;
|
|
}
|
|
}
|
|
}
|
|
|
|
public function replaceImagePath()
|
|
{
|
|
$dir = "/Volumes/WD/tmp/site/mm24.cc/iess/";
|
|
$files = scandir($dir);
|
|
dump("total files count is " . count($files));
|
|
$flag = true;
|
|
foreach ($files as $file) {
|
|
if ($file == "." || $file == ".." || $file == ".DS_Store") {
|
|
continue;
|
|
}
|
|
dump($file);
|
|
if ($flag) {
|
|
$isExist = Redis::exists("fullSet");
|
|
if (!$isExist) {
|
|
continue;
|
|
} else {
|
|
$flag = false;
|
|
}
|
|
}
|
|
$content = file_get_contents($dir . $file);
|
|
if (str_contains($content, "http://img.huangguogan.net")) {
|
|
file_put_contents($dir . $file, str_replace("http://img.huangguogan.net", "..", file_get_contents($dir . $file)));
|
|
}
|
|
Redis::set("fullSet", $file);
|
|
// exit;
|
|
}
|
|
exit;
|
|
for ($i = 1; $i <= 46; $i++) {
|
|
if ($i == 1) {
|
|
$file = "4063.html";
|
|
} else {
|
|
$file = "4063_" . $i . ".html";
|
|
}
|
|
file_put_contents($dir . $file, str_replace("http://img.huangguogan.net", "..", file_get_contents($dir . $file)));
|
|
}
|
|
}
|
|
}
|