2016-10-20 22:09:36 -04:00
|
|
|
<?php declare(strict_types=1);
|
2016-04-19 13:02:50 -04:00
|
|
|
/**
|
2016-12-20 12:58:37 -05:00
|
|
|
* Anime List Client
|
2016-04-19 13:02:50 -04:00
|
|
|
*
|
2016-12-20 12:58:37 -05:00
|
|
|
* An API client for Kitsu and MyAnimeList to manage anime and manga watch lists
|
2016-04-19 13:02:50 -04:00
|
|
|
*
|
2016-10-20 22:09:36 -04:00
|
|
|
* PHP version 7
|
2016-08-30 10:01:18 -04:00
|
|
|
*
|
2016-12-20 12:58:37 -05:00
|
|
|
* @package AnimeListClient
|
2016-08-30 10:01:18 -04:00
|
|
|
* @author Timothy J. Warren <tim@timshomepage.net>
|
|
|
|
* @copyright 2015 - 2016 Timothy J. Warren
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
2016-12-20 12:58:37 -05:00
|
|
|
* @version 4.0
|
2016-04-19 13:02:50 -04:00
|
|
|
* @link https://github.com/timw4mail/HummingBirdAnimeClient
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Aviat\AnimeClient\Command;
|
|
|
|
|
2016-07-27 14:32:37 -04:00
|
|
|
use Aviat\AnimeClient\Util;
|
2016-10-20 22:32:17 -04:00
|
|
|
|
2016-04-19 13:02:50 -04:00
|
|
|
/**
|
|
|
|
* Generates thumbnail image cache so that cover images load faster
|
|
|
|
*/
|
|
|
|
class CacheImages extends BaseCommand {
|
|
|
|
|
2016-08-30 10:57:41 -04:00
|
|
|
/**
|
|
|
|
* Manga Model
|
|
|
|
*
|
|
|
|
* @var Aviat\AnimeClient\Model\Manga
|
|
|
|
*/
|
2016-04-19 13:02:50 -04:00
|
|
|
protected $mangaModel;
|
2016-08-30 10:57:41 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Anime Model
|
|
|
|
*
|
|
|
|
* @var Aviat\AnimeClient\Model\Anime
|
|
|
|
*/
|
2016-04-19 13:02:50 -04:00
|
|
|
protected $animeModel;
|
2016-08-30 10:57:41 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Miscellaneous helper methods
|
|
|
|
*
|
|
|
|
* @var Aviat\AnimeClient\Util
|
|
|
|
*/
|
2016-07-27 14:32:37 -04:00
|
|
|
protected $util;
|
2016-04-19 13:02:50 -04:00
|
|
|
|
2016-08-30 10:57:41 -04:00
|
|
|
/**
|
2016-04-19 13:02:50 -04:00
|
|
|
* Convert manga images
|
|
|
|
*
|
|
|
|
* @throws \ConsoleKit\ConsoleException
|
2016-08-30 10:57:41 -04:00
|
|
|
* @return void
|
2016-04-19 13:02:50 -04:00
|
|
|
*/
|
|
|
|
protected function getMangaImages()
|
|
|
|
{
|
|
|
|
$raw_list = $this->mangaModel->_get_list_from_api();
|
|
|
|
$manga_list = array_column($raw_list, 'manga');
|
|
|
|
|
|
|
|
$total = count($raw_list);
|
|
|
|
$current = 0;
|
|
|
|
foreach($manga_list as $item)
|
|
|
|
{
|
2016-07-27 14:32:37 -04:00
|
|
|
$this->util->get_cached_image($item['poster_image'], $item['id'], 'manga');
|
2016-04-19 13:02:50 -04:00
|
|
|
$current++;
|
|
|
|
|
|
|
|
echo "Cached {$current} of {$total} manga images. \n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert anime images
|
|
|
|
*
|
|
|
|
* @throws \ConsoleKit\ConsoleException
|
2016-08-30 10:57:41 -04:00
|
|
|
* @return void
|
2016-04-19 13:02:50 -04:00
|
|
|
*/
|
|
|
|
protected function getAnimeImages()
|
|
|
|
{
|
|
|
|
$raw_list = $this->animeModel->get_raw_list();
|
|
|
|
|
|
|
|
$total = count($raw_list);
|
|
|
|
$current = 0;
|
|
|
|
foreach($raw_list as $item)
|
|
|
|
{
|
2016-07-27 14:32:37 -04:00
|
|
|
$this->util->get_cached_image($item['anime']['cover_image'], $item['anime']['slug'], 'anime');
|
2016-04-19 13:02:50 -04:00
|
|
|
$current++;
|
|
|
|
|
|
|
|
echo "Cached {$current} of {$total} anime images. \n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run the image conversion script
|
|
|
|
*
|
|
|
|
* @param array $args
|
|
|
|
* @param array $options
|
|
|
|
* @return void
|
|
|
|
* @throws \ConsoleKit\ConsoleException
|
|
|
|
*/
|
2016-08-30 10:01:18 -04:00
|
|
|
public function execute(array $args, array $options = [])
|
2016-04-19 13:02:50 -04:00
|
|
|
{
|
|
|
|
$this->setContainer($this->setupContainer());
|
2016-07-27 14:32:37 -04:00
|
|
|
$this->util = new Util($this->container);
|
2016-04-19 13:02:50 -04:00
|
|
|
$this->animeModel = $this->container->get('anime-model');
|
|
|
|
$this->mangaModel = $this->container->get('manga-model');
|
|
|
|
|
|
|
|
$this->echoBox('Starting image conversion');
|
|
|
|
|
|
|
|
$this->echoBox('Converting manga images');
|
|
|
|
$this->getMangaImages();
|
|
|
|
|
|
|
|
$this->echoBox('Converting anime images');
|
|
|
|
$this->getAnimeImages();
|
|
|
|
|
|
|
|
$this->echoBox('Finished image conversion');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// End of CacheImages.php
|