|
|
@ -1,9 +1,12 @@ |
|
|
<?php |
|
|
<?php |
|
|
namespace App\Http\Controllers; |
|
|
namespace App\Http\Controllers; |
|
|
|
|
|
|
|
|
|
|
|
use App\GooglePhoto; |
|
|
use Google\ApiCore\ApiException; |
|
|
use Google\ApiCore\ApiException; |
|
|
use Google\Photos\Library\V1\PhotosLibraryClient; |
|
|
use Google\Photos\Library\V1\PhotosLibraryClient; |
|
|
|
|
|
use Google\Photos\Types\Album; |
|
|
use Illuminate\Http\Request; |
|
|
use Illuminate\Http\Request; |
|
|
|
|
|
use Illuminate\Support\Facades\Log; |
|
|
|
|
|
|
|
|
class GooglePhotoController extends Controller { |
|
|
class GooglePhotoController extends Controller { |
|
|
public function connect(Request $request) |
|
|
public function connect(Request $request) |
|
|
@ -17,6 +20,7 @@ class GooglePhotoController extends Controller { |
|
|
public function index() |
|
|
public function index() |
|
|
{ |
|
|
{ |
|
|
$credentials = session("credentials"); |
|
|
$credentials = session("credentials"); |
|
|
|
|
|
// $credentials = null;
|
|
|
if ($credentials == null || $credentials == "") { |
|
|
if ($credentials == null || $credentials == "") { |
|
|
return view("albums/connect"); |
|
|
return view("albums/connect"); |
|
|
} |
|
|
} |
|
|
@ -24,27 +28,58 @@ class GooglePhotoController extends Controller { |
|
|
try { |
|
|
try { |
|
|
// $options['proxy'] = 'http://127.0.0.1:1087';
|
|
|
// $options['proxy'] = 'http://127.0.0.1:1087';
|
|
|
// $pagedResponse = $photosLibraryClient->listAlbums();
|
|
|
// $pagedResponse = $photosLibraryClient->listAlbums();
|
|
|
// $options['pageSize'] = 5;
|
|
|
|
|
|
$pagedResponse = $photosLibraryClient->listMediaItems(); |
|
|
|
|
|
|
|
|
// $iterator = $pagedResponse->iterateAllElements();
|
|
|
|
|
|
// for ($i = 0; $i < 300; $i++) {
|
|
|
|
|
|
// $album = $iterator->current();
|
|
|
|
|
|
// Log::info("album name is" . $album->getTitle() . " id is " . $album->getId());
|
|
|
|
|
|
// $iterator->next();
|
|
|
|
|
|
// }
|
|
|
|
|
|
// exit;
|
|
|
|
|
|
$options['pageSize'] = 100; |
|
|
|
|
|
$pagedResponse = $photosLibraryClient->listMediaItems($options); |
|
|
|
|
|
// $album = new Album();
|
|
|
|
|
|
// $album->setTitle("ycc_gc");
|
|
|
|
|
|
// $album = $photosLibraryClient->createAlbum($album);
|
|
|
|
|
|
// Log::info($album->getId());
|
|
|
// echo 111;
|
|
|
// echo 111;
|
|
|
// var_dump($pagedResponse->iterateAllElements());exit;
|
|
|
// var_dump($pagedResponse->iterateAllElements());exit;
|
|
|
$iterator = $pagedResponse->iterateAllElements(); |
|
|
$iterator = $pagedResponse->iterateAllElements(); |
|
|
$albums = []; |
|
|
$albums = []; |
|
|
$yccImages = []; |
|
|
$yccImages = []; |
|
|
while (true) { |
|
|
while (true) { |
|
|
for ($i = 0; $i < 100; $i++) { |
|
|
|
|
|
$album = $iterator->current(); |
|
|
|
|
|
if (strstr($album->getFilename(), "ycc")) { |
|
|
|
|
|
$yccImages[] = $album->getId(); |
|
|
|
|
|
|
|
|
for ($i = 0; $i < 100000; $i++) { |
|
|
|
|
|
if ($i < 5600) { |
|
|
|
|
|
$iterator->next(); |
|
|
} |
|
|
} |
|
|
|
|
|
$photo = $iterator->current(); |
|
|
|
|
|
// Log::info($photo);
|
|
|
|
|
|
Log::info($photo->getFilename()); |
|
|
|
|
|
GooglePhoto::firstOrCreate(["photo_id" => $photo->getId()], |
|
|
|
|
|
["photo_id" => $photo->getId(), |
|
|
|
|
|
"filename" => $photo->getFilename(), |
|
|
|
|
|
"product_url" => $photo->getProductUrl(), |
|
|
|
|
|
"creation_time" => date("Y-m-d H:i:s", $photo->getMediaMetadata()->getCreationTime()->getSeconds())] |
|
|
|
|
|
); |
|
|
|
|
|
// exit;
|
|
|
|
|
|
// dump($photo);
|
|
|
|
|
|
// if (strstr($photo->getFilename(), "ycc")) {
|
|
|
|
|
|
// $yccImages[] = $photo->getId();
|
|
|
|
|
|
// }
|
|
|
$iterator->next(); |
|
|
$iterator->next(); |
|
|
} |
|
|
} |
|
|
if (count($yccImages) > 1) { |
|
|
|
|
|
$photosLibraryClient->batchAddMediaItemsToAlbum("AN5jk26M4hJ-wxLPKSzIDyjruMMkWjlDlVkgNaWWk3d3c7TGhm1vKU-YM0JhfgK5CfcfneoIx_8E", $yccImages); |
|
|
|
|
|
echo "add " . count($yccImages) . " images to ycc\n"; |
|
|
|
|
|
$yccImages = []; |
|
|
|
|
|
} |
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
// if (count($yccImages) > 1) {
|
|
|
|
|
|
// $yccImages = array_slice($yccImages, 89);
|
|
|
|
|
|
// Log::info( "prepare add " . count($yccImages) . " images to ycc");
|
|
|
|
|
|
// Log::info("imageIDs", $yccImages);
|
|
|
|
|
|
// try {
|
|
|
|
|
|
// $photosLibraryClient->batchAddMediaItemsToAlbum("AN5jk27_faHwGa9qT0SALztx3zxTk4HUiqhVIDjxHQBxZ59v1ljIyA8Klsn2ZaxlFrRJwBAPPdmZ", $yccImages);
|
|
|
|
|
|
// } catch (ApiException $e) {
|
|
|
|
|
|
// Log::error($e->getMessage());
|
|
|
|
|
|
// }
|
|
|
|
|
|
// Log::info( "add " . count($yccImages) . " images to ycc");
|
|
|
|
|
|
// $yccImages = [];
|
|
|
|
|
|
// }
|
|
|
|
|
|
// break;
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|