2018-10-10 16:04:58 -04:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
/**
|
|
|
|
* Hummingbird Anime List Client
|
|
|
|
*
|
|
|
|
* An API client for Kitsu to manage anime and manga watch lists
|
|
|
|
*
|
2020-04-10 15:39:39 -04:00
|
|
|
* PHP version 7.4
|
2018-10-10 16:04:58 -04:00
|
|
|
*
|
|
|
|
* @package HummingbirdAnimeClient
|
|
|
|
* @author Timothy J. Warren <tim@timshomepage.net>
|
2020-01-08 15:39:49 -05:00
|
|
|
* @copyright 2015 - 2020 Timothy J. Warren
|
2018-10-10 16:04:58 -04:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
2020-08-04 09:30:21 -04:00
|
|
|
* @version 5.1
|
2018-10-10 16:04:58 -04:00
|
|
|
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Aviat\AnimeClient\Command;
|
|
|
|
|
2020-04-10 20:01:46 -04:00
|
|
|
use Aviat\AnimeClient\API\Kitsu\Model as KitsuModel;
|
2019-05-08 13:19:03 -04:00
|
|
|
use Aviat\AnimeClient\Controller\Images;
|
2018-10-10 16:04:58 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears out image cache directories, then re-creates the image cache
|
|
|
|
* for manga and anime
|
|
|
|
*/
|
2018-11-01 22:15:20 -04:00
|
|
|
final class UpdateThumbnails extends ClearThumbnails {
|
2018-10-10 16:04:58 -04:00
|
|
|
/**
|
|
|
|
* Model for making requests to Kitsu API
|
2020-04-10 20:01:46 -04:00
|
|
|
* @var KitsuModel
|
2018-10-10 16:04:58 -04:00
|
|
|
*/
|
2020-04-10 20:01:46 -04:00
|
|
|
protected KitsuModel $kitsuModel;
|
2018-10-10 16:04:58 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The default controller, which has the method to cache the images
|
|
|
|
*/
|
2020-04-10 20:01:46 -04:00
|
|
|
protected Images $controller;
|
2018-10-10 16:04:58 -04:00
|
|
|
|
|
|
|
public function execute(array $args, array $options = []): void
|
|
|
|
{
|
|
|
|
$this->setContainer($this->setupContainer());
|
|
|
|
$this->setCache($this->container->get('cache'));
|
|
|
|
|
2019-05-08 13:19:03 -04:00
|
|
|
$this->controller = new Images($this->container);
|
2018-10-10 16:04:58 -04:00
|
|
|
$this->kitsuModel = $this->container->get('kitsu-model');
|
|
|
|
|
2020-10-21 17:06:50 -04:00
|
|
|
// Clear the existing thumbnails
|
2018-11-01 22:15:20 -04:00
|
|
|
parent::execute($args, $options);
|
2018-10-10 16:04:58 -04:00
|
|
|
|
|
|
|
$ids = $this->getImageList();
|
|
|
|
|
|
|
|
// Resave the images
|
|
|
|
foreach($ids as $type => $typeIds)
|
|
|
|
{
|
|
|
|
foreach ($typeIds as $id)
|
|
|
|
{
|
2019-05-08 13:19:03 -04:00
|
|
|
$this->controller->cache($type, "{$id}.jpg", FALSE);
|
2018-10-10 16:04:58 -04:00
|
|
|
}
|
2018-10-19 09:30:27 -04:00
|
|
|
|
|
|
|
$this->echoBox("Finished regenerating {$type} thumbnails");
|
2018-10-10 16:04:58 -04:00
|
|
|
}
|
|
|
|
|
2018-10-19 09:30:27 -04:00
|
|
|
$this->echoBox('Finished regenerating all thumbnails');
|
2018-10-10 16:04:58 -04:00
|
|
|
}
|
|
|
|
|
2019-12-06 15:46:56 -05:00
|
|
|
/**
|
2019-12-09 14:34:23 -05:00
|
|
|
* @return array array-key[][]
|
2019-12-06 15:46:56 -05:00
|
|
|
* @psalm-return array{anime: list<array-key>, manga: list<array-key>}
|
|
|
|
*/
|
|
|
|
public function getImageList(): array
|
2018-10-10 16:04:58 -04:00
|
|
|
{
|
2020-10-21 17:06:50 -04:00
|
|
|
$animeIds = array_map(
|
|
|
|
fn ($item) => $item['media']['id'],
|
|
|
|
$this->kitsuModel->getThumbList('ANIME')
|
|
|
|
);
|
|
|
|
$mangaIds = array_map(
|
|
|
|
fn ($item) => $item['media']['id'],
|
|
|
|
$this->kitsuModel->getThumbList('MANGA')
|
|
|
|
);
|
2018-10-10 16:04:58 -04:00
|
|
|
|
|
|
|
return [
|
|
|
|
'anime' => $animeIds,
|
|
|
|
'manga' => $mangaIds,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|