Browse Source

modify encode complete

feature/new_bilibili_and_instagram_sxs20191126
shixuesen 3 years ago
parent
commit
fae4494075
13 changed files with 630 additions and 482 deletions
  1. +1
    -0
      .gitignore
  2. +3
    -1
      .idea/php.xml
  3. +1
    -0
      app/Console/Commands/InstagramScrape.php
  4. +1
    -0
      app/Console/Commands/QueueFfmpegCommand.php
  5. +10
    -10
      app/Http/Controllers/WeiboController.php
  6. +9
    -0
      app/Services/BilibiliServiceV2.php
  7. +8
    -3
      app/Services/FfmpegService.php
  8. +5
    -0
      app/Services/FileService.php
  9. +3
    -2
      app/Services/InstagramService.php
  10. +27
    -2
      app/Services/QueuedFfmpegService.php
  11. +2
    -1
      composer.json
  12. +560
    -463
      composer.lock
  13. BIN
      mgp25.zip

+ 1
- 0
.gitignore View File

@ -23,6 +23,7 @@ Homestead.json
/.vagrant /.vagrant
.phpunit.result.cache .phpunit.result.cache
.idea/* .idea/*
.idea/php.xml
.DS_Store .DS_Store
.env.local .env.local
.env.prod .env.prod


+ 3
- 1
.idea/php.xml View File

@ -183,9 +183,11 @@
<path value="$PROJECT_DIR$/vendor/prettus/laravel-validation" /> <path value="$PROJECT_DIR$/vendor/prettus/laravel-validation" />
<path value="$PROJECT_DIR$/vendor/prettus/l5-repository" /> <path value="$PROJECT_DIR$/vendor/prettus/l5-repository" />
<path value="$PROJECT_DIR$/vendor/albertofem/rsync-lib" /> <path value="$PROJECT_DIR$/vendor/albertofem/rsync-lib" />
<path value="$PROJECT_DIR$/vendor/google/longrunning" />
<path value="$PROJECT_DIR$/vendor/brianholle/mgp25" />
</include_path> </include_path>
</component> </component>
<component name="PhpProjectSharedConfiguration" php_language_level="7.1">
<component name="PhpProjectSharedConfiguration" php_language_level="7.4">
<option name="suggestChangeDefaultLanguageLevel" value="false" /> <option name="suggestChangeDefaultLanguageLevel" value="false" />
</component> </component>
<component name="PhpUnit"> <component name="PhpUnit">


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

@ -49,6 +49,7 @@ class InstagramScrape extends Command
// // $userList = ['1992.ai_']; // // $userList = ['1992.ai_'];
// print_r($userList);exit; // print_r($userList);exit;
$ins = new InstagramService(); $ins = new InstagramService();
exit;
// $ins->getUserNameById('4156629214');exit; // $ins->getUserNameById('4156629214');exit;
// $ins->scrapeUsersInFile("/Users/shixuesen/OneDrive/Pictures/instagram/user_0.txt");exit; // $ins->scrapeUsersInFile("/Users/shixuesen/OneDrive/Pictures/instagram/user_0.txt");exit;


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

@ -46,6 +46,7 @@ class QueueFfmpegCommand extends Command
if ($command == "add") { if ($command == "add") {
$queuedFfmpegService->processDir($path); $queuedFfmpegService->processDir($path);
} else { } else {
$queuedFfmpegService->setDestinationDirectory("/mnt/e/rec_encode/");
$queuedFfmpegService->processQueue(); $queuedFfmpegService->processQueue();
// $ffmpeg = new FfmpegService(); // $ffmpeg = new FfmpegService();
// $ffmpeg->setNeedRemoveExistFiles(false); // $ffmpeg->setNeedRemoveExistFiles(false);


+ 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; // $url[] = 'https://m.weibo.cn/api/container/getIndex?containerid=1076035893812490&openApp=0&page='.$i;
// for( $i = 100; $i >= 1 ; $i-- ) // for( $i = 100; $i >= 1 ; $i-- )
// $url[] = 'https://m.weibo.cn/api/container/getIndex?containerid=2304133907143723&openApp=0&page='.$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--) { // for ($i = $size; $i >= 1; $i--) {
// $url[] = 'https://m.weibo.cn/api/container/getIndex?containerid=230259&page=' . $i; // $url[] = 'https://m.weibo.cn/api/container/getIndex?containerid=230259&page=' . $i;
// } // }
@ -111,8 +111,8 @@ class WeiboController extends Controller
// die(); // die();
// Log::info($request->input()); // Log::info($request->input());
$weibo = new WeiboService(); $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); return response()->json($result);
} }


+ 9
- 0
app/Services/BilibiliServiceV2.php View File

@ -664,11 +664,20 @@ class BilibiliServiceV2
while ($list->isNotEmpty()) { while ($list->isNotEmpty()) {
foreach ($list->items() as $item) { foreach ($list->items() as $item) {
// dump("current item", [$item->getAttributes()]); // dump("current item", [$item->getAttributes()]);
if ($item->is_download == 0) {
// 不需要下载
continue;
}
$response = $this->requestVideoParts($item->aid); $response = $this->requestVideoParts($item->aid);
dump($response); dump($response);
$responseJson = json_decode($response, true); $responseJson = json_decode($response, true);
if ($responseJson["code"] !== 0) { if ($responseJson["code"] !== 0) {
Log::error("response is error, aid: " . $item->aid . " response: " . $response); Log::error("response is error, aid: " . $item->aid . " response: " . $response);
if ($responseJson["code"] == -404 || $responseJson["code"] == "-404" || $responseJson["message"] == "啥都木有") {
Log::error("response is error and save is_download = 0, aid: " . $item->aid . " response: " . $response);
$item->is_download = 0;
$item->save();
}
continue; continue;
} }
$partList = Arr::get($responseJson, "data"); $partList = Arr::get($responseJson, "data");


+ 8
- 3
app/Services/FfmpegService.php View File

@ -7,7 +7,7 @@ use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis; use Illuminate\Support\Facades\Redis;
use Mhor\MediaInfo\MediaInfo; use Mhor\MediaInfo\MediaInfo;
use FFMpeg\FFProbe; use FFMpeg\FFProbe;
use Throwable;
class FfmpegService class FfmpegService
@ -125,8 +125,13 @@ class FfmpegService
public function processVideo($pathFile) public function processVideo($pathFile)
{ {
Log::info("current process pathFile " . $pathFile);
try {
$mime = mime_content_type($pathFile); $mime = mime_content_type($pathFile);
$mediaInfo = new MediaInfo();
} catch (Throwable $e) {
Log::error("mime_content_type has exception " . $e->getMessage());
}
$mediaInfo = new MediaInfo();
$mediaInfo->setConfig('use_oldxml_mediainfo_output_format', true); $mediaInfo->setConfig('use_oldxml_mediainfo_output_format', true);
if (strstr($mime, "video/") || strstr($mime, "application/octet-stream")) { if (strstr($mime, "video/") || strstr($mime, "application/octet-stream")) {
if (is_file($pathFile)) { if (is_file($pathFile)) {
@ -303,7 +308,7 @@ class FfmpegService
->videos() // filters video streams ->videos() // filters video streams
->first() // returns the first video stream ->first() // returns the first video stream
->get('codec_name'); ->get('codec_name');
} catch (\Throwable $e) {
} catch (Throwable $e) {
echo "error $file \n"; echo "error $file \n";
Log::error("ffprobe has error just return false for test, exception: ". $e->getMessage()); Log::error("ffprobe has error just return false for test, exception: ". $e->getMessage());
return false; return false;


+ 5
- 0
app/Services/FileService.php View File

@ -1268,6 +1268,11 @@ class FileService {
} }
} }
public function mvFile($file, $destDirectory): bool
{
return rename($file, $destDirectory . DIRECTORY_SEPARATOR . basename($file));
}
public function queryNewerFilesInDirectory($dir, $lastTime) public function queryNewerFilesInDirectory($dir, $lastTime)
{ {
$list = []; $list = [];


+ 3
- 2
app/Services/InstagramService.php View File

@ -17,11 +17,12 @@ use InstagramAPI\Response\Model\Item;
class InstagramService class InstagramService
{ {
private $username = "nicksxs"; private $username = "nicksxs";
// private $password = '949sxs949@S';
private $password = 'mff@5201314'; private $password = 'mff@5201314';
// private $username = "sili1024"; // private $username = "sili1024";
// private $password = 'Qwer2020'; // private $password = 'Qwer2020';
private $debug = false;
private $truncatedDebug = false;
private $debug = true;
private $truncatedDebug = true;
private $ig; private $ig;
public function __construct() public function __construct()


+ 27
- 2
app/Services/QueuedFfmpegService.php View File

@ -15,13 +15,36 @@ class QueuedFfmpegService {
private $ffmpegService; private $ffmpegService;
private $fileService;
private $destinationDirectory;
public function __construct() public function __construct()
{ {
$this->ffmpegService = new FfmpegService(); $this->ffmpegService = new FfmpegService();
$this->ffmpegService->setNeedRemoveAfterEncode(true); $this->ffmpegService->setNeedRemoveAfterEncode(true);
$this->ffmpegService->setNeedRemoveExistFiles(false); $this->ffmpegService->setNeedRemoveExistFiles(false);
$this->fileService = new FileService();
} }
/**
* @return mixed
*/
public function getDestinationDirectory()
{
return $this->destinationDirectory;
}
/**
* @param mixed $destinationDirectory
*/
public function setDestinationDirectory($destinationDirectory): void
{
$this->destinationDirectory = $destinationDirectory;
}
public function processDir($path) public function processDir($path)
{ {
$files = scandir($path); $files = scandir($path);
@ -43,7 +66,7 @@ class QueuedFfmpegService {
{ {
// BilibiliEncode::dispatch($file); // BilibiliEncode::dispatch($file);
Log::info("add $file to ffmpeg process queue"); Log::info("add $file to ffmpeg process queue");
Redis::connection()->rpush("file_to_encode", $file);
Redis::connection()->lpush("file_to_encode", $file);
// $result = Redis::publish("file_to_process", $file); // $result = Redis::publish("file_to_process", $file);
// echo $result; // echo $result;
} }
@ -57,8 +80,10 @@ class QueuedFfmpegService {
while ($item != null) { while ($item != null) {
echo $item . "\n"; echo $item . "\n";
$empty = false; $empty = false;
$item = Redis::connection()->rpop("file_to_encode");
$this->ffmpegService->processVideo($item); $this->ffmpegService->processVideo($item);
$this->fileService->mvFile($item, $this->getDestinationDirectory());
$item = Redis::connection()->rpop("file_to_encode");
} }
if ($empty) { if ($empty) {
Log::info("process end sleep 300 seconds"); Log::info("process end sleep 300 seconds");


+ 2
- 1
composer.json View File

@ -10,9 +10,11 @@
"require": { "require": {
"php": "^7.1.3", "php": "^7.1.3",
"ext-curl": "^7.1", "ext-curl": "^7.1",
"ext-fileinfo": "*",
"ext-json": "*", "ext-json": "*",
"albertofem/rsync-lib": "1.0.0", "albertofem/rsync-lib": "1.0.0",
"barryvdh/laravel-ide-helper": "^2.5", "barryvdh/laravel-ide-helper": "^2.5",
"brianholle/mgp25": "^1.0",
"doctrine/dbal": "^2.9", "doctrine/dbal": "^2.9",
"encore/laravel-admin": "^1.7", "encore/laravel-admin": "^1.7",
"fideloper/proxy": "^4.0", "fideloper/proxy": "^4.0",
@ -24,7 +26,6 @@
"laravel/framework": "5.7.*", "laravel/framework": "5.7.*",
"laravel/tinker": "^1.0", "laravel/tinker": "^1.0",
"league/oauth2-client": "dev-master", "league/oauth2-client": "dev-master",
"mgp25/instagram-php": "dev-master",
"mhor/php-mediainfo": "^4.1", "mhor/php-mediainfo": "^4.1",
"microsoft/microsoft-graph": "^1.6", "microsoft/microsoft-graph": "^1.6",
"mnapoli/front-yaml": "^1.8", "mnapoli/front-yaml": "^1.8",


+ 560
- 463
composer.lock
File diff suppressed because it is too large
View File


BIN
mgp25.zip View File


Loading…
Cancel
Save