Browse Source

add some

feature/new_bilibili_and_instagram_sxs20191126
shixuesen 5 years ago
parent
commit
29fc69333f
8 changed files with 206 additions and 9 deletions
  1. +1
    -1
      app/Console/Commands/HandBrakeCommand.php
  2. +1
    -1
      app/Console/Commands/RenameTest.php
  3. +12
    -0
      app/Console/Kernel.php
  4. +3
    -1
      app/Http/Controllers/WeiboController.php
  5. +43
    -0
      app/Services/HandBrakeService.php
  6. +139
    -1
      app/Services/NewXiuGirlsService.php
  7. +5
    -5
      app/Services/RenameService.php
  8. +2
    -0
      app/Services/WeiboService.php

+ 1
- 1
app/Console/Commands/HandBrakeCommand.php View File

@ -40,6 +40,6 @@ class HandBrakeCommand extends Command
{
//
$service = new HandBrakeService();
$service->handleVideos();
$service->processDir();
}
}

+ 1
- 1
app/Console/Commands/RenameTest.php View File

@ -40,7 +40,7 @@ class RenameTest extends Command
{
//
$rename = new RenameService();
$rename->rename("/Users/shixuesen/Documents/tmp/柚木/");
$rename->rename("/Users/shixuesen/Documents/tmp/魔物喵/", "魔物喵-");
// $rename->rename();
// $rename->mvFiles("/Users/shixuesen/Documents/tmp/秀人旗下《MFStar模范学院》套图及视频写真-TLoB/视频/");
}


+ 12
- 0
app/Console/Kernel.php View File

@ -5,7 +5,9 @@ namespace App\Console;
use App\Services\BilibiliService;
use App\Services\CompressImageService;
use App\Services\DailySignService;
use App\Services\NewNvshenService;
use App\Services\NewXiuGirlsService;
use App\Services\TujiguService;
use App\Services\XiuGirlsService;
use App\Services\VitabioticsService;
use App\Services\YouKnowService;
@ -124,6 +126,16 @@ class Kernel extends ConsoleKernel
$xiuService = new NewXiuGirlsService();
$xiuService->scrapeXiuGirls();
// })->everyMinute();
})->dailyAt('05:00');
$schedule->call(function () {
$nvshenService = new NewNvshenService();
$nvshenService->scrapeNvshenGirls();
// })->cron("0 */3 * * *");
})->dailyAt('04:00');
$schedule->call(function () {
$tuji = new TujiguService();
$tuji->scrapeTujiguGirls();
// })->cron("30 */3 * * *");
})->dailyAt('05:00');
$schedule->call(function () {
$dailySignService = new DailySignService();


+ 3
- 1
app/Http/Controllers/WeiboController.php View File

@ -24,11 +24,13 @@ class WeiboController extends Controller
// https://m.weibo.cn/api/container/getIndex?containerid=1076035123577126&openApp=0&page='.$i;
// Fan_Cam_4K 1076035733650527 page 902
// 儒雅随和 1076035123577126 page 139
// 徐圣佑 1076035893812490 page 283
// https://m.weibo.cn/api/container/getIndex?containerid=230259&openApp=0
$url = array();
for( $i = 783 ; $i >= 1 ; $i-- )
for( $i = 842; $i >= 1 ; $i-- )
$url[] = 'https://m.weibo.cn/api/container/getIndex?containerid=230259&openApp=0&page='.$i;
return response()->json($url);
}


+ 43
- 0
app/Services/HandBrakeService.php View File

@ -50,4 +50,47 @@ class HandBrakeService
print_r($files);
}
public function processDir($baseDir = "/Users/shixuesen/Documents/tmp/魔物喵/")
{
$files = scandir($baseDir);
foreach ($files as $file) {
if ($file == "." || $file == "..") {
continue;
}
$subDir = implode("/", [$baseDir, $file]);
$isDir = is_dir($subDir);
if ($isDir) {
$this->processDir($subDir);
} else {
$this->processVideo($subDir);
}
}
}
public function processVideo($pathFile)
{
$mime = mime_content_type($pathFile);
// dump("file type", [$mime, $subPathFile]);
// continue;
if (strstr($mime, "video/")) {
if (is_file($pathFile)) {
$fileInfo = pathinfo($pathFile);
dump("fileInfo", $fileInfo);
if (ends_with($fileInfo["filename"], "-1")) {
return;
}
if (is_file($fileInfo["dirname"] . '/' .$fileInfo["filename"] . '-1'. '.' . $fileInfo["extension"])) {
unlink($pathFile);
return;
}
$targetFile = $fileInfo["dirname"] . '/' .$fileInfo["filename"] . '-1'. '.' . $fileInfo["extension"];
dump("targetFile", [$targetFile]);
// $result = shell_exec("handBrakeCli -Z 'Very Fast 720p30' -i '". $subPathFile ."' -o '". $targetFile . " && echo 'success'");
$result = shell_exec("handBrakeCli -Z 'Very Fast 720p30' -i '". $pathFile ."' -o '". $targetFile . "'");
dump($result);
}
}
}
}

+ 139
- 1
app/Services/NewXiuGirlsService.php View File

@ -105,7 +105,7 @@ class NewXiuGirlsService
}
// $items = array_slice($items, 1);
// print_r($items);exit;
print_r($items);continue;
foreach ($items as $item) {
usleep(random_int(1000, 10000) * 1000);
echo "相册子链接: " .$item . "\n";
@ -306,4 +306,142 @@ class NewXiuGirlsService
// exit;
}
}
public function singleAlbum($iUser = "ycc", $albumOuterCode = 21429)
{
$NUM_OF_ATTEMPTS = 50;
// self::$name_dir[1];
print_r([self::$name_dir[$iUser]]);
foreach ([self::$name_dir[$iUser]] as $username => $name) {
$username = $iUser;
dump("here {$username}, {$name['code']}");
usleep(random_int(1000, 10000) * 1000);
$peopleUrl = "https://xsnvshen.com/girl/";
$peopleUrl .= $name['code'];
$albumSelector = ".entryAblum > .star-mod-bd > ul > li > a";
$baseQl = QueryList::get($peopleUrl);
$ql = $baseQl->find($albumSelector)->attrs("href");
$items = $ql->all();
// $items = array_slice($items, 49);
// print_r($items);exit;
$baseUrl = "https://www.xsnvshen.com";
// $baseDir = "/Users/shixuesen/Documents/xg/" . $name['dir']. "/";
$baseDir = "/Volumes/intel660p/image/xg/" . $name['dir'] . "/";
if (!file_exists($baseDir)) {
mkdir($baseDir);
}
// $items = array_slice($items, 1);
print_r($items);
$items = ["/album/21429"];
foreach ($items as $item) {
print_r($item);
if ($item != "/album/" . $albumOuterCode) {
echo $item . "\t" . "/album/" . $albumOuterCode . "\n";
echo "000000000000000000";
continue;
}
usleep(random_int(1000, 10000) * 1000);
echo "相册子链接: " .$item . "\n";
$queryItemUrlTimes = 1;
do {
try {
$html = (new \QL\QueryList)->get($baseUrl . $item);
} catch (\Exception $e) {
\Log::error("查询相册子链接失败,将重试, 异常信息: " . $e->getMessage());
$sleepTime = 1000 * random_int(1000, 10000);
echo "查询相册子链接失败 sleep {$sleepTime} nano second \n";
usleep($sleepTime);
$queryItemUrlTimes++;
}
break;
} while ($queryItemUrlTimes < 10);
$title = $html->find("h1 > a")->texts();
dump($title);
echo "相册名: " . $title[0] . "\n";
while (trim($title[0]) == "古诗文") {
echo "here error happenned \n";
// dump($html->getHtml());
usleep(random_int(1, 1000) * 50000);
$html = QueryList::get($baseUrl. $item);
$title = $html->find("h1 > a")->texts();
// continue;
}
// break;
$albumPath = "";
$albumCode = explode("/", $item)[2];
if (!file_exists($baseDir .explode("/", $item)[2] . "-" .$title[0])) {
mkdir($baseDir .explode("/", $item)[2]. "-" .$title[0]);
}
$albumPath = $baseDir.explode("/", $item)[2] . "-" . $title[0];
$attempts = 0;
$images = [];
do {
try {
$images = QueryList::get($baseUrl . $item)->find(".swi-hd > img")->attrs("src");
} catch (\Exception $e) {
echo $e->getTraceAsString() . "\n";
$sleepTime = 10000 * random_int(100, 1000);
echo "sleep {$sleepTime} nano second \n";
usleep($sleepTime);
$attempts ++;
continue;
}
break;
} while ($attempts <= $NUM_OF_ATTEMPTS);
foreach ($images as $image) {
if (strpos($image, "thumb_600x900") !== false) {
$image = str_replace( "thumb_600x900/", "", $image);
}
/**
* todo 修改
* CommonService::downloadImage($albumPath, "https:" . $image);
*/
if (file_exists($albumPath."/".pathinfo("http:".$image)['filename'].".jpg") || file_exists($albumPath . "/" . $username . "-" . $albumCode . "-" . pathinfo("http:".$image)['filename'].".jpg")) {
continue;
}
$opts = array('http'=> ['header' =>
"User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36 \r\n
Referer:".$baseUrl.$item."\r\n"
]);
$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,"https:".$image);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2000);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36');
curl_setopt($curl_handle, CURLOPT_REFERER, $baseUrl . $item);
$query = curl_exec($curl_handle);
$i = 1;
while ($query === false) {
echo 'Curl error: ' . curl_error($curl_handle) ."\n";
echo "retry times: " .$i++ ." times \n";
sleep(1);
$sleepTime = 1000 * random_int(1000, 10000);
echo "retry sleep {$sleepTime} nano second \n";
usleep($sleepTime);
$query = curl_exec($curl_handle);
if ($i >= 100) {
break;
}
}
echo curl_error($curl_handle);
$fp = fopen($albumPath . "/" . $username . "-" . $albumCode . "-" . pathinfo("http:".$image)['filename'].".jpg", 'x');
fwrite($fp, $query);
fclose($fp);
$sleepTime = 1000 * random_int(100, 1000);
echo "after write image sleep {$sleepTime} nano second \n";
usleep($sleepTime);
}
usleep(1000 * random_int(100, 1000));
}
}
exit;
}
}

+ 5
- 5
app/Services/RenameService.php View File

@ -6,12 +6,12 @@ namespace App\Services;
class RenameService
{
public function rename($baseDir = "/Volumes/N/v/美腿骇客 Leghacker&Leglegs-TLoB/")
public function rename($baseDir = "/Volumes/N/v/美腿骇客 Leghacker&Leglegs-TLoB/", $prefix = "")
{
if (!is_dir($baseDir)) {
return;
}
$this->parseDir($baseDir);
$this->parseDir($baseDir, $prefix);
}
@ -24,7 +24,7 @@ class RenameService
}
private function parseDir($dir)
private function parseDir($dir, $prefix = "")
{
if (!is_dir($dir)) {
return;
@ -36,14 +36,14 @@ class RenameService
continue;
}
if (is_dir($dir . "/" .$file)) {
$this->parseDir($dir . "/" . $file);
$this->parseDir($dir . "/" . $file, $prefix);
}
if (is_file($dir . "/" .$file) && (pathinfo($file, PATHINFO_EXTENSION) == "JPG" || pathinfo($file, PATHINFO_EXTENSION) == "jpg" || pathinfo($file, PATHINFO_EXTENSION) == "jpeg" || pathinfo($file, PATHINFO_EXTENSION) == "mp4")) {
echo $dir;
echo "\n";
echo $file;
$dirList = explode("/", $dir);
$filePrefix = array_pop($dirList);
$filePrefix = $prefix . array_pop($dirList);
if (!str_contains($file, $filePrefix)) {
rename($dir . "/" . $file, $dir. "/". $filePrefix. "-" . $file);
}


+ 2
- 0
app/Services/WeiboService.php View File

@ -23,6 +23,8 @@ class WeiboService
// @mkdir('data/video');
// $video_dir = "/Volumes/intel660p/video/weibo/ruye";
// $image_dir = "/Volumes/intel660p/image/weibo/ruya";
// $video_dir = "/Volumes/Samsung/weibo/people/徐圣佑/video";
// $image_dir = "/Volumes/Samsung/weibo/people/徐圣佑/image";
$video_dir = "/Volumes/Samsung/weibo/video";
$image_dir = "/Volumes/Samsung/weibo/image";


Loading…
Cancel
Save