|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Hummingbird Anime Client |
|
4
|
|
|
* |
|
5
|
|
|
* An API client for Hummingbird to manage anime and manga watch lists |
|
6
|
|
|
* |
|
7
|
|
|
* @package HummingbirdAnimeClient |
|
8
|
|
|
* @author Timothy J. Warren |
|
9
|
|
|
* @copyright Copyright (c) 2015 - 2016 |
|
10
|
|
|
* @link https://github.com/timw4mail/HummingBirdAnimeClient |
|
11
|
|
|
* @license MIT |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Aviat\AnimeClient\Command; |
|
15
|
|
|
|
|
16
|
|
|
use Aviat\AnimeClient\Model; |
|
17
|
|
|
/** |
|
18
|
|
|
* Generates thumbnail image cache so that cover images load faster |
|
19
|
|
|
*/ |
|
20
|
|
|
class CacheImages extends BaseCommand { |
|
21
|
|
|
|
|
22
|
|
|
protected $mangaModel; |
|
23
|
|
|
protected $animeModel; |
|
24
|
|
|
protected $model; |
|
25
|
|
|
|
|
26
|
|
|
/* |
|
27
|
|
|
* Convert manga images |
|
28
|
|
|
* |
|
29
|
|
|
* @throws \ConsoleKit\ConsoleException |
|
30
|
|
|
*/ |
|
31
|
|
|
protected function getMangaImages() |
|
32
|
|
|
{ |
|
33
|
|
|
$raw_list = $this->mangaModel->_get_list_from_api(); |
|
34
|
|
|
$manga_list = array_column($raw_list, 'manga'); |
|
35
|
|
|
|
|
36
|
|
|
$total = count($raw_list); |
|
37
|
|
|
$current = 0; |
|
38
|
|
|
foreach($manga_list as $item) |
|
39
|
|
|
{ |
|
40
|
|
|
$this->model->get_cached_image($item['poster_image'], $item['id'], 'manga'); |
|
41
|
|
|
$current++; |
|
42
|
|
|
|
|
43
|
|
|
echo "Cached {$current} of {$total} manga images. \n"; |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Convert anime images |
|
49
|
|
|
* |
|
50
|
|
|
* @throws \ConsoleKit\ConsoleException |
|
51
|
|
|
*/ |
|
52
|
|
|
protected function getAnimeImages() |
|
53
|
|
|
{ |
|
54
|
|
|
$raw_list = $this->animeModel->get_raw_list(); |
|
55
|
|
|
|
|
56
|
|
|
$total = count($raw_list); |
|
57
|
|
|
$current = 0; |
|
58
|
|
|
foreach($raw_list as $item) |
|
59
|
|
|
{ |
|
60
|
|
|
$this->model->get_cached_image($item['anime']['cover_image'], $item['anime']['slug'], 'anime'); |
|
61
|
|
|
$current++; |
|
62
|
|
|
|
|
63
|
|
|
echo "Cached {$current} of {$total} anime images. \n"; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Run the image conversion script |
|
69
|
|
|
* |
|
70
|
|
|
* @param array $args |
|
71
|
|
|
* @param array $options |
|
72
|
|
|
* @return void |
|
73
|
|
|
* @throws \ConsoleKit\ConsoleException |
|
74
|
|
|
*/ |
|
75
|
|
|
public function execute(array $args, array $options = array()) |
|
76
|
|
|
{ |
|
77
|
|
|
$this->setContainer($this->setupContainer()); |
|
78
|
|
|
$this->model = new Model($this->container); |
|
79
|
|
|
$this->animeModel = $this->container->get('anime-model'); |
|
80
|
|
|
$this->mangaModel = $this->container->get('manga-model'); |
|
81
|
|
|
|
|
82
|
|
|
$this->echoBox('Starting image conversion'); |
|
83
|
|
|
|
|
84
|
|
|
$this->echoBox('Converting manga images'); |
|
85
|
|
|
$this->getMangaImages(); |
|
86
|
|
|
|
|
87
|
|
|
$this->echoBox('Converting anime images'); |
|
88
|
|
|
$this->getAnimeImages(); |
|
89
|
|
|
|
|
90
|
|
|
$this->echoBox('Finished image conversion'); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
// End of CacheImages.php |