Browse Source

add some code

feature/new_bilibili_and_instagram_sxs20191126
shixuesen 5 years ago
parent
commit
e09013f79e
13 changed files with 1203 additions and 145 deletions
  1. +6
    -0
      .idea/php.xml
  2. +8
    -4
      app/Console/Commands/BiliVideoCode.php
  3. +1
    -0
      app/Console/Commands/HandBrakeCommand.php
  4. +5
    -2
      app/Console/Commands/InstagramScrape.php
  5. +2
    -1
      app/Console/Commands/RenameTest.php
  6. +2
    -2
      app/Http/Controllers/WeiboController.php
  7. +2
    -1
      app/Services/BilibiliService.php
  8. +64
    -1
      app/Services/HandBrakeService.php
  9. +160
    -0
      app/Services/Ins24Service.php
  10. +1
    -1
      app/Services/RenameService.php
  11. +4
    -4
      app/Services/WeiboService.php
  12. +5
    -0
      composer.json
  13. +943
    -129
      composer.lock

+ 6
- 0
.idea/php.xml View File

@ -158,6 +158,12 @@
<path value="$PROJECT_DIR$/vendor/nexmo/client-core" />
<path value="$PROJECT_DIR$/vendor/mgp25/instagram-php" />
<path value="$PROJECT_DIR$/vendor/mhor/php-mediainfo" />
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php80" />
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php70" />
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-intl-normalizer" />
<path value="$PROJECT_DIR$/vendor/league/mime-type-detection" />
<path value="$PROJECT_DIR$/vendor/symfony/deprecation-contracts" />
<path value="$PROJECT_DIR$/vendor/james-heinrich/getid3" />
</include_path>
</component>
<component name="PhpProjectSharedConfiguration" php_language_level="7.1" />


+ 8
- 4
app/Console/Commands/BiliVideoCode.php View File

@ -42,15 +42,19 @@ class BiliVideoCode extends Command
// dump($this->arguments());exit;
//
$bilibili = new BilibiliService();
// $bilibili->checkVideoHasDownload();
// $bilibili->queryLocalUpVideoList();exit;
// $bilibili->insertDBTest();exit;
// $bilibili->queryPlayList();
$bilibili->queryUpVideoList(10278125);
// $bilibili->queryUpVideoList(10278125);
// exit;
$bilibili->queryDBCollectionList();
$bilibili->queryForVideoParts();
$bilibili->compareAndDownloadUpVideos();
// $bilibili->queryDBCollectionList();
// $bilibili->queryForVideoParts();
// $bilibili->compareAndDownloadUpVideos();
// exit;
$bilibili->compareAndDownloadCollectionVideos();
// $bilibili->queryCollectionList();
// $bilibili->compareAndDownloadNewVideos();


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

@ -41,5 +41,6 @@ class HandBrakeCommand extends Command
//
$service = new HandBrakeService();
$service->processDir();
// $service->processUnCompleteDir();
}
}

+ 5
- 2
app/Console/Commands/InstagramScrape.php View File

@ -2,6 +2,7 @@
namespace App\Console\Commands;
use App\Services\Ins24Service;
use App\Services\InstagramService;
use Illuminate\Console\Command;
@ -39,10 +40,12 @@ class InstagramScrape extends Command
public function handle()
{
//
$ins = new InstagramService();
$ins->scrapeUsers();
// $ins = new InstagramService();
// $ins->scrapeUsers();
// $ins->getUserNameById();
// $ins->queryFollowUsers();
// $ins->commonRequest();
$ins24 = new Ins24Service();
$ins24->scrapeUsers();
}
}

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

@ -40,7 +40,8 @@ class RenameTest extends Command
{
//
$rename = new RenameService();
$rename->rename("/Users/shixuesen/Documents/tmp/魔物喵/", "魔物喵-");
// $rename->rename("/Volumes/WD/tmp/尤果网/尤G网", "尤果网-");
$rename->rename("/Users/shixuesen/Documents/tmp/PartyCat轰趴猫&PDL潘多拉-TLoB", "PartyCat轰趴猫&PDL潘多拉-TLoB-");
// $rename->rename();
// $rename->mvFiles("/Users/shixuesen/Documents/tmp/秀人旗下《MFStar模范学院》套图及视频写真-TLoB/视频/");
}


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

@ -30,8 +30,8 @@ class WeiboController extends Controller
$url = array();
for( $i = 842; $i >= 1 ; $i-- )
$url[] = 'https://m.weibo.cn/api/container/getIndex?containerid=230259&openApp=0&page='.$i;
for( $i = 341; $i >= 1 ; $i-- )
$url[] = 'https://m.weibo.cn/api/container/getIndex?containerid=1076035893812490&openApp=0&page='.$i;
return response()->json($url);
}


+ 2
- 1
app/Services/BilibiliService.php View File

@ -286,7 +286,8 @@ class BilibiliService
$videoMap[$value] = $vItem->total_parts;
if ($item['title'] == "默认收藏夹") {
dump("xxxxxxxxxxxx----------------");
$this->partDownloadBSitePlaylist($videoMap, $this->baseDir, "bilibili");
$this->partDownloadBSitePlaylist($videoMap, "/Volumes/WD/tmp/", "bilibili");
// $this->partDownloadBSitePlaylist($videoMap, $this->baseDir, "bilibili");
} else if ($item['title'] == '少女时代') {
$this->partDownloadBSitePlaylist($videoMap, "/Volumes/WD/tmp/bilibili/少女时代", "");
} else {


+ 64
- 1
app/Services/HandBrakeService.php View File

@ -2,6 +2,8 @@
namespace App\Services;
use Mhor\MediaInfo\MediaInfo;
class HandBrakeService
@ -50,7 +52,8 @@ class HandBrakeService
print_r($files);
}
public function processDir($baseDir = "/Users/shixuesen/Documents/tmp/魔物喵/")
public function processDir($baseDir = "/Volumes/WD/tmp/探花系列【AI高清2K修复】大合集")
// public function processDir($baseDir = "/Volumes/Backup/iPhone nPlayer/")
{
$files = scandir($baseDir);
foreach ($files as $file) {
@ -93,4 +96,64 @@ class HandBrakeService
}
}
public function processUnCompleteDir($baseDir = "/Volumes/WD/tmp/探花系列【AI高清2K修复】大合集")
// public function processDir($baseDir = "/Volumes/Backup/iPhone nPlayer/")
{
$files = scandir($baseDir);
foreach ($files as $file) {
if ($file == "." || $file == "..") {
continue;
}
$subDir = implode("/", [$baseDir, $file]);
$isDir = is_dir($subDir);
if ($isDir) {
$this->processUnCompleteDir($subDir);
} else {
$this->processUnCompleteVideo($subDir);
}
}
}
public function processUnCompleteVideo($pathFile)
{
//...
$mediaInfo = new MediaInfo();
$mediaInfo->setConfig('use_oldxml_mediainfo_output_format', true);
$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"])) {
$mediaInfoContainer1 = $mediaInfo->getInfo($fileInfo["dirname"] . '/' .$fileInfo["filename"] . '-1'. '.' . $fileInfo["extension"]);
$millSecond1 = $mediaInfoContainer1->getGeneral()->get("duration")->getMilliseconds();
echo gettype($millSecond1) . "\n";
// ["duration"] . "\n";
$mediaInfoContainer = $mediaInfo->getInfo($pathFile);
$millSecond = $mediaInfoContainer->getGeneral()->get("duration")->getMilliseconds();
echo gettype($millSecond) . "\n";
if (abs(intval($millSecond) - intval($millSecond1)) > 100) {
echo $pathFile . "\n";
echo abs(intval($millSecond) - intval($millSecond1)) . "\n";
}
// 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);
}
}
}
}

+ 160
- 0
app/Services/Ins24Service.php View File

@ -0,0 +1,160 @@
<?php
namespace App\Services;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Log;
use InstagramAPI\Response\Model\Item;
class Ins24Service
{
public function scrapeUsers()
{
$baseImageDir = "/Users/shixuesen/OneDrive/Pictures/instagram/";
try {
$userList = file("/Users/shixuesen/OneDrive/Pictures/instagram/user.txt");
// $userList = array_slice($userList, 17);
// $userList = ['1992.ai_'];
// print_r($userList);exit;
// print_r($userList);
foreach ($userList as $userName) {
usleep(random_int(100, 1000) * 10000);
$trueName = trim($userName);
$thisUserImageDir = $baseImageDir . $trueName . "/";
$maxId = "";
$pageNo = 1;
for (; ;) {
try {
$data = $this->queryImage($trueName, $pageNo, $maxId);
foreach ($data["resourceList"] as $resource) {
$res = $this->downloadFile($resource["mediaURL"], 0, $thisUserImageDir);
usleep(random_int(100, 1000) * 10000);
if ($res == 0) {
break 2;
}
}
$maxId = $data["maxId"];
$pageNo ++;
} catch (\Exception $e) {
Log::error("ins get user id for name error: " . $e->getMessage() . " username is " . $userName);
}
}
}
} catch (\Exception $e) {
}
}
private function queryImage($userName, $pageNo = 1, $maxId = "") {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://www.ins246.com/ins/search.html",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
// CURLOPT_POSTFIELDS => "search=https%3A%2F%2Fwww.instagram.com%2Fnz0502%2F&pageNo=1&type=1&maxId=",
CURLOPT_POSTFIELDS => "search=https://www.instagram.com/$userName/&pageNo=$pageNo&type=1&maxId=$maxId",
CURLOPT_HTTPHEADER => array(
"authority: www.ins246.com",
"pragma: no-cache",
"cache-control: no-cache",
"accept: */*",
"x-requested-with: XMLHttpRequest",
"user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36",
"content-type: application/x-www-form-urlencoded; charset=UTF-8",
"origin: https://www.ins246.com",
"sec-fetch-site: same-origin",
"sec-fetch-mode: cors",
"sec-fetch-dest: empty",
"referer: https://www.ins246.com/ins/gosearch.html",
"accept-language: en-US,en;q=0.9,zh-TW;q=0.8,zh;q=0.7,ja;q=0.6,zh-CN;q=0.5",
"cookie: __cfduid=d94e7974e4bbec11a34d72efca94204591604573518; JSESSIONID=EF65EB47872FB6EFEFADA05C8CD140EA; _ga=GA1.2.343334980.1604573522; _gid=GA1.2.1674010257.1604573522; JSESSIONID=6A642D962A119268816A05B9B3D7C8A0"
),
));
$response = curl_exec($curl);
curl_close($curl);
$formatResponse = json_decode($response, true);
if ($formatResponse["code"] == 200) {
return $formatResponse["data"];
}
// echo $response;
}
function downloadFile($filenameUrl, $flag = 0, $filePrefix = "")
{
//echo $filenameUrl;exit;
$filePathInfo = pathinfo($filenameUrl);
$filename = $filePathInfo['filename'];
// echo $filename;
// echo "\n";
$pos = strpos($filename, "?");
// echo "pos: ".$pos;
// echo "\n";
if ($pos > 0) {
$filename = substr($filename, 0, $pos);
}
// echo $filename;exit;
// if ($filename == "33020038_640464766303508_27725890796388352_n.jpg"){
// $flag = 1;
// }
if (file_exists($filePrefix . $filename) || file_exists($filePrefix . $filename . ".back")) {
echo "\n file exists " . $filePrefix . $filename;
return 0;
}
try {
$cn_match = "https://www.ins246.com/ins/gosearch.html";
$options = array(
'ssl' => array(
'verify_peer' => true,
'cafile' => "/Users/shixuesen/Downloads/cacert.pem",
'ciphers' => 'HIGH:TLSv1.2:TLSv1.1:TLSv1.0:!SSLv3:!SSLv2',
'CN_match' => $cn_match,
'disable_compression' => true,
)
);
$context = stream_context_create($options);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $filenameUrl);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, false);
curl_setopt($ch, CURLOPT_REFERER, "https://www.ins246.com/ins/gosearch.html");
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$image = curl_exec($ch);
curl_close($ch);
// $image = file_get_contents($filenameUrl, false, null);
} catch (\Throwable $e) {
var_dump($e->getMessage());
$this->logFailUrl($filePrefix, $filenameUrl);
return -1;
}
echo "new filename: " . $filePrefix . $filename . "\n";
$downloadResult = file_put_contents($filePrefix . $filename, $image);
if (!$downloadResult) {
$this->logFailUrl($filePrefix, $filenameUrl);
return -1;
} else {
return 1;
}
}
}

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

@ -38,7 +38,7 @@ class RenameService
if (is_dir($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")) {
if (is_file($dir . "/" .$file) && (pathinfo($file, PATHINFO_EXTENSION) == "JPG" || pathinfo($file, PATHINFO_EXTENSION) == "jpg" || pathinfo($file, PATHINFO_EXTENSION) == "jpeg" || pathinfo($file, PATHINFO_EXTENSION) == "png" || pathinfo($file, PATHINFO_EXTENSION) == "mp4")) {
echo $dir;
echo "\n";
echo $file;


+ 4
- 4
app/Services/WeiboService.php View File

@ -23,11 +23,11 @@ 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/people/徐圣佑/video";
$image_dir = "/Volumes/Samsung/weibo/people/徐圣佑/image";
$video_dir = "/Volumes/Samsung/weibo/video";
$image_dir = "/Volumes/Samsung/weibo/image";
// $video_dir = "/Volumes/Samsung/weibo/video";
// $image_dir = "/Volumes/Samsung/weibo/image";
try {
if (strlen($content) > 0) {


+ 5
- 0
composer.json View File

@ -18,6 +18,7 @@
"google/apiclient": "^2.0",
"guzzlehttp/guzzle": "~6.0",
"jaeger/querylist": "^4.1",
"james-heinrich/getid3": "^1.9",
"laravel/framework": "5.7.*",
"laravel/tinker": "^1.0",
"league/oauth2-client": "dev-master",
@ -82,6 +83,10 @@
"0": {
"type": "vcs",
"url": "https://github.com/PHP-FFMpeg/BinaryDriver.git"
},
"packagist": {
"type": "composer",
"url": "https://mirrors.aliyun.com/composer/"
}
}
}

+ 943
- 129
composer.lock
File diff suppressed because it is too large
View File


Loading…
Cancel
Save