diff --git a/app/Console/Commands/CommonTest.php b/app/Console/Commands/CommonTest.php index 0e0bba7..26ead61 100644 --- a/app/Console/Commands/CommonTest.php +++ b/app/Console/Commands/CommonTest.php @@ -8,6 +8,7 @@ use App\Services\FfmpegService; use App\Services\FileService; use App\Utils\FileUtils; use Illuminate\Console\Command; +use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Redis; @@ -44,6 +45,7 @@ class CommonTest extends Command */ public function handle() { + echo App::environment();exit; // $list = BilibiliVideos::where("created_at", ">", "2021-09-09 00:00:00")->get(); // dump($list[0]->getAttributes());exit; date_default_timezone_set('PRC'); diff --git a/app/Http/Controllers/GooglePhotoController.php b/app/Http/Controllers/GooglePhotoController.php index 98520a0..325dea2 100644 --- a/app/Http/Controllers/GooglePhotoController.php +++ b/app/Http/Controllers/GooglePhotoController.php @@ -8,7 +8,7 @@ use Illuminate\Http\Request; class GooglePhotoController extends Controller { public function connect(Request $request) { - connectWithGooglePhotos($request, + return connectWithGooglePhotos($request, ['https://www.googleapis.com/auth/photoslibrary'], config('app.albums_authentication_redirect_url') ); diff --git a/app/Services/BilibiliServiceV2.php b/app/Services/BilibiliServiceV2.php index 3a1eea7..7e88d83 100644 --- a/app/Services/BilibiliServiceV2.php +++ b/app/Services/BilibiliServiceV2.php @@ -7,6 +7,7 @@ use App\BilibiliCollections; use App\BilibiliUpVideos; use App\BilibiliVideoParts; use App\BilibiliVideos; +use Exception; use GuzzleHttp\Client; use Illuminate\Support\Arr; use Illuminate\Support\Facades\DB; @@ -43,7 +44,7 @@ class BilibiliServiceV2 /** * 获取各个 up 主的视频 id * @param int $mediaId - * @throws \Exception + * @throws Exception */ public function queryUpVideoList($mediaId = 320491072) { @@ -147,7 +148,7 @@ class BilibiliServiceV2 /** * 手动执行查询 * @param int $mediaId - * @throws \Exception + * @throws Exception */ public function queryLocalUpVideoList($mediaId = 320491072) { @@ -261,17 +262,20 @@ class BilibiliServiceV2 $videoPartsMap[$vItem["aid"]] = $vItem["total_parts"]; echo "当前 up名称是: " . $item["up_name"] . " 当前下载的视频 title: " . $vItem["title"] . " 当前下载的视频 aid 是:" . $vItem["aid"] . "\n" ; Log::info("当前 up名称是: " . $item["up_name"] . " 当前下载的视频 title: " . $vItem["title"] . " 当前下载的视频 aid 是:" . $vItem["aid"]); + $result = false; if ($item['mid'] == 27174777) { - $this->partDownloadBSitePlaylist($videoPartsMap, "/Volumes/WD/tmp/bilibili/", "女团"); + $result = $this->partDownloadBSitePlaylist($videoPartsMap, "/Volumes/WD/tmp/bilibili/", "女团"); } 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) { - $this->partDownloadBSitePlaylist($videoPartsMap, "/Volumes/WD/tmp/bilibili/", "佳佳"); + $result = $this->partDownloadBSitePlaylist($videoPartsMap, "/Volumes/WD/tmp/bilibili/", "佳佳"); } 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 { usleep(random_int(10, 100) * 1000); - } catch (\Exception $e) { + } catch (Exception $e) { } } break; @@ -626,7 +630,7 @@ class BilibiliServiceV2 $list = BilibiliVideos::simplePaginate(50, null, 'page', $i); try { usleep(random_int(10, 1000) * 1000); - } catch (\Exception $e) { + } catch (Exception $e) { } } @@ -849,7 +853,7 @@ class BilibiliServiceV2 Log::info("current download result: " . $downloadResult); try { usleep(random_int(1000, 10000) * 1000); - } catch (\Exception $e) { + } catch (Exception $e) { } } } @@ -880,12 +884,17 @@ class BilibiliServiceV2 for i in $(seq 1 ' . $parts . ') do annie -f 64 $url$i -done ' ); +done && echo "ok"' ); Log::info($downloadResult); - Log::info("current download result: " . $downloadResult); + Log::info("$aid current download result: " . $downloadResult); try { usleep(random_int(1000, 10000) * 1000); - } catch (\Exception $e) { + } catch (Exception $e) { + } + if (trim($downloadResult) == 'ok') { + return true; + } else { + return false; } } } diff --git a/app/Services/DistributeTaskService.php b/app/Services/DistributeTaskService.php new file mode 100644 index 0000000..6c2c352 --- /dev/null +++ b/app/Services/DistributeTaskService.php @@ -0,0 +1,26 @@ + true, + 'ssh' => array( + 'host' => 'myhost.com', + 'private_key' => '/my/key' + ) + ); + $rsync = new Rsync($config); + + // change options programatically + $rsync->setFollowSymlinks(false); + + $rsync->sync($originDir, $targetDir); + + } + +} diff --git a/app/Utils/helper.php b/app/Utils/helper.php index c53b245..19ff4f7 100644 --- a/app/Utils/helper.php +++ b/app/Utils/helper.php @@ -37,8 +37,9 @@ function connectWithGooglePhotos($request, array $scopes, $redirectURI) $authenticationUrl = $oauth2->buildFullAuthorizationUri(['access_type' => 'offline']); // dump($authenticationUrl); // redirect($authenticationUrl); - header("Location: " . $authenticationUrl); +// header("Location: " . $authenticationUrl); // redirect()->to($authenticationUrl); + redirect($authenticationUrl); } else { dump("code is " . $code); // With the code returned by the OAuth flow, we can retrieve the refresh token. diff --git a/composer.json b/composer.json index 702f189..ad35dd0 100644 --- a/composer.json +++ b/composer.json @@ -11,6 +11,7 @@ "php": "^7.1.3", "ext-curl": "^7.1", "ext-json": "*", + "albertofem/rsync-lib": "1.0.0", "barryvdh/laravel-ide-helper": "^2.5", "doctrine/dbal": "^2.9", "encore/laravel-admin": "^1.7",