Browse Source

add rsync

feature/new_bilibili_and_instagram_sxs20191126
nicksxs 4 years ago
parent
commit
5f56a71e93
6 changed files with 55 additions and 16 deletions
  1. +2
    -0
      app/Console/Commands/CommonTest.php
  2. +1
    -1
      app/Http/Controllers/GooglePhotoController.php
  3. +23
    -14
      app/Services/BilibiliServiceV2.php
  4. +26
    -0
      app/Services/DistributeTaskService.php
  5. +2
    -1
      app/Utils/helper.php
  6. +1
    -0
      composer.json

+ 2
- 0
app/Console/Commands/CommonTest.php View File

@ -8,6 +8,7 @@ use App\Services\FfmpegService;
use App\Services\FileService; use App\Services\FileService;
use App\Utils\FileUtils; use App\Utils\FileUtils;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Redis; use Illuminate\Support\Facades\Redis;
@ -44,6 +45,7 @@ class CommonTest extends Command
*/ */
public function handle() public function handle()
{ {
echo App::environment();exit;
// $list = BilibiliVideos::where("created_at", ">", "2021-09-09 00:00:00")->get(); // $list = BilibiliVideos::where("created_at", ">", "2021-09-09 00:00:00")->get();
// dump($list[0]->getAttributes());exit; // dump($list[0]->getAttributes());exit;
date_default_timezone_set('PRC'); date_default_timezone_set('PRC');


+ 1
- 1
app/Http/Controllers/GooglePhotoController.php View File

@ -8,7 +8,7 @@ use Illuminate\Http\Request;
class GooglePhotoController extends Controller { class GooglePhotoController extends Controller {
public function connect(Request $request) public function connect(Request $request)
{ {
connectWithGooglePhotos($request,
return connectWithGooglePhotos($request,
['https://www.googleapis.com/auth/photoslibrary'], ['https://www.googleapis.com/auth/photoslibrary'],
config('app.albums_authentication_redirect_url') config('app.albums_authentication_redirect_url')
); );


+ 23
- 14
app/Services/BilibiliServiceV2.php View File

@ -7,6 +7,7 @@ use App\BilibiliCollections;
use App\BilibiliUpVideos; use App\BilibiliUpVideos;
use App\BilibiliVideoParts; use App\BilibiliVideoParts;
use App\BilibiliVideos; use App\BilibiliVideos;
use Exception;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
@ -43,7 +44,7 @@ class BilibiliServiceV2
/** /**
* 获取各个 up 主的视频 id * 获取各个 up 主的视频 id
* @param int $mediaId * @param int $mediaId
* @throws \Exception
* @throws Exception
*/ */
public function queryUpVideoList($mediaId = 320491072) public function queryUpVideoList($mediaId = 320491072)
{ {
@ -147,7 +148,7 @@ class BilibiliServiceV2
/** /**
* 手动执行查询 * 手动执行查询
* @param int $mediaId * @param int $mediaId
* @throws \Exception
* @throws Exception
*/ */
public function queryLocalUpVideoList($mediaId = 320491072) public function queryLocalUpVideoList($mediaId = 320491072)
{ {
@ -261,17 +262,20 @@ class BilibiliServiceV2
$videoPartsMap[$vItem["aid"]] = $vItem["total_parts"]; $videoPartsMap[$vItem["aid"]] = $vItem["total_parts"];
echo "当前 up名称是: " . $item["up_name"] . " 当前下载的视频 title: " . $vItem["title"] . " 当前下载的视频 aid 是:" . $vItem["aid"] . "\n" ; echo "当前 up名称是: " . $item["up_name"] . " 当前下载的视频 title: " . $vItem["title"] . " 当前下载的视频 aid 是:" . $vItem["aid"] . "\n" ;
Log::info("当前 up名称是: " . $item["up_name"] . " 当前下载的视频 title: " . $vItem["title"] . " 当前下载的视频 aid 是:" . $vItem["aid"]); Log::info("当前 up名称是: " . $item["up_name"] . " 当前下载的视频 title: " . $vItem["title"] . " 当前下载的视频 aid 是:" . $vItem["aid"]);
$result = false;
if ($item['mid'] == 27174777) { if ($item['mid'] == 27174777) {
$this->partDownloadBSitePlaylist($videoPartsMap, "/Volumes/WD/tmp/bilibili/", "女团");
$result = $this->partDownloadBSitePlaylist($videoPartsMap, "/Volumes/WD/tmp/bilibili/", "女团");
} else if ($item["mid"] == 391316322) { } else if ($item["mid"] == 391316322) {
$this->partDownloadBSitePlaylist($videoPartsMap, "/Volumes/WD/tmp/bilibili/", "娜娜");
$result = $this->partDownloadBSitePlaylist($videoPartsMap, "/Volumes/WD/tmp/bilibili/", "娜娜");
} else if ($item["mid"] == 396501206) { } else if ($item["mid"] == 396501206) {
$this->partDownloadBSitePlaylist($videoPartsMap, "/Volumes/WD/tmp/bilibili/", "佳佳");
$result = $this->partDownloadBSitePlaylist($videoPartsMap, "/Volumes/WD/tmp/bilibili/", "佳佳");
} else { } else {
$this->partDownloadBSitePlaylist($videoPartsMap, $this->baseDir . "bilibili/", $item['up_name']);
$result = $this->partDownloadBSitePlaylist($videoPartsMap, $this->baseDir . "bilibili/", $item['up_name']);
}
if ($result) {
$vItem["is_downloaded"] = 1;
$vItem->save();
} }
$vItem["is_downloaded"] = 1;
$vItem->save();
} }
} }
} }
@ -618,7 +622,7 @@ class BilibiliServiceV2
} }
try { try {
usleep(random_int(10, 100) * 1000); usleep(random_int(10, 100) * 1000);
} catch (\Exception $e) {
} catch (Exception $e) {
} }
} }
break; break;
@ -626,7 +630,7 @@ class BilibiliServiceV2
$list = BilibiliVideos::simplePaginate(50, null, 'page', $i); $list = BilibiliVideos::simplePaginate(50, null, 'page', $i);
try { try {
usleep(random_int(10, 1000) * 1000); usleep(random_int(10, 1000) * 1000);
} catch (\Exception $e) {
} catch (Exception $e) {
} }
} }
@ -849,7 +853,7 @@ class BilibiliServiceV2
Log::info("current download result: " . $downloadResult); Log::info("current download result: " . $downloadResult);
try { try {
usleep(random_int(1000, 10000) * 1000); usleep(random_int(1000, 10000) * 1000);
} catch (\Exception $e) {
} catch (Exception $e) {
} }
} }
} }
@ -880,12 +884,17 @@ class BilibiliServiceV2
for i in $(seq 1 ' . $parts . ') for i in $(seq 1 ' . $parts . ')
do do
annie -f 64 $url$i annie -f 64 $url$i
done ' );
done && echo "ok"' );
Log::info($downloadResult); Log::info($downloadResult);
Log::info("current download result: " . $downloadResult);
Log::info("$aid current download result: " . $downloadResult);
try { try {
usleep(random_int(1000, 10000) * 1000); usleep(random_int(1000, 10000) * 1000);
} catch (\Exception $e) {
} catch (Exception $e) {
}
if (trim($downloadResult) == 'ok') {
return true;
} else {
return false;
} }
} }
} }


+ 26
- 0
app/Services/DistributeTaskService.php View File

@ -0,0 +1,26 @@
<?php
namespace App\Services;
use AFM\Rsync\Rsync;
class DistributeTaskService {
public function syncData($originDir, $targetDir)
{
$config = array(
'delete_from_target' => true,
'ssh' => array(
'host' => 'myhost.com',
'private_key' => '/my/key'
)
);
$rsync = new Rsync($config);
// change options programatically
$rsync->setFollowSymlinks(false);
$rsync->sync($originDir, $targetDir);
}
}

+ 2
- 1
app/Utils/helper.php View File

@ -37,8 +37,9 @@ function connectWithGooglePhotos($request, array $scopes, $redirectURI)
$authenticationUrl = $oauth2->buildFullAuthorizationUri(['access_type' => 'offline']); $authenticationUrl = $oauth2->buildFullAuthorizationUri(['access_type' => 'offline']);
// dump($authenticationUrl); // dump($authenticationUrl);
// redirect($authenticationUrl); // redirect($authenticationUrl);
header("Location: " . $authenticationUrl);
// header("Location: " . $authenticationUrl);
// redirect()->to($authenticationUrl); // redirect()->to($authenticationUrl);
redirect($authenticationUrl);
} else { } else {
dump("code is " . $code); dump("code is " . $code);
// With the code returned by the OAuth flow, we can retrieve the refresh token. // With the code returned by the OAuth flow, we can retrieve the refresh token.


+ 1
- 0
composer.json View File

@ -11,6 +11,7 @@
"php": "^7.1.3", "php": "^7.1.3",
"ext-curl": "^7.1", "ext-curl": "^7.1",
"ext-json": "*", "ext-json": "*",
"albertofem/rsync-lib": "1.0.0",
"barryvdh/laravel-ide-helper": "^2.5", "barryvdh/laravel-ide-helper": "^2.5",
"doctrine/dbal": "^2.9", "doctrine/dbal": "^2.9",
"encore/laravel-admin": "^1.7", "encore/laravel-admin": "^1.7",


Loading…
Cancel
Save