Do you wish to register an account?
API client for Kitsu.io, with optional Anime collection, and optional Anilist syncing.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
2.4KB

  1. <?php declare(strict_types=1);
  2. /**
  3. * Hummingbird Anime List Client
  4. *
  5. * An API client for Kitsu to manage anime and manga watch lists
  6. *
  7. * PHP version 7.1
  8. *
  9. * @package HummingbirdAnimeClient
  10. * @author Timothy J. Warren <tim@timshomepage.net>
  11. * @copyright 2015 - 2018 Timothy J. Warren
  12. * @license http://www.opensource.org/licenses/mit-license.html MIT License
  13. * @version 4.1
  14. * @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
  15. */
  16. namespace Aviat\AnimeClient\Command;
  17. use Aviat\AnimeClient\API\JsonAPI;
  18. use Aviat\AnimeClient\Controller\Index;
  19. /**
  20. * Clears out image cache directories, then re-creates the image cache
  21. * for manga and anime
  22. */
  23. final class UpdateThumbnails extends BaseCommand {
  24. /**
  25. * Model for making requests to Kitsu API
  26. * @var \Aviat\AnimeClient\API\Kitsu\Model
  27. */
  28. protected $kitsuModel;
  29. /**
  30. * The default controller, which has the method to cache the images
  31. */
  32. protected $controller;
  33. public function execute(array $args, array $options = []): void
  34. {
  35. $this->setContainer($this->setupContainer());
  36. $this->setCache($this->container->get('cache'));
  37. $this->controller = new Index($this->container);
  38. $this->kitsuModel = $this->container->get('kitsu-model');
  39. $this->clearThumbs();
  40. $ids = $this->getImageList();
  41. // print_r($ids);
  42. // echo json_encode($ids, \JSON_PRETTY_PRINT);
  43. // Resave the images
  44. foreach($ids as $type => $typeIds)
  45. {
  46. foreach ($typeIds as $id)
  47. {
  48. $this->controller->images($type, "{$id}.jpg", FALSE);
  49. }
  50. $this->echoBox("Finished regenerating {$type} thumbnails");
  51. }
  52. $this->echoBox('Finished regenerating all thumbnails');
  53. }
  54. public function clearThumbs()
  55. {
  56. $imgDir = realpath(__DIR__ . '/../../public/images');
  57. $paths = [
  58. 'anime/*.jpg',
  59. 'anime/*.webp',
  60. 'manga/*.jpg',
  61. 'manga/*.webp',
  62. 'characters/*.jpg',
  63. 'characters/*.webp',
  64. ];
  65. foreach($paths as $path)
  66. {
  67. $cmd = "rm -rf {$imgDir}/{$path}";
  68. exec($cmd);
  69. }
  70. }
  71. public function getImageList()
  72. {
  73. $mangaList = $this->kitsuModel->getFullRawMangaList();
  74. $includes = JsonAPI::organizeIncludes($mangaList['included']);
  75. $mangaIds = array_keys($includes['manga']);
  76. $animeList = $this->kitsuModel->getFullRawAnimeList();
  77. $includes = JsonAPI::organizeIncludes($animeList['included']);
  78. $animeIds = array_keys($includes['anime']);
  79. // print_r($mangaIds);
  80. // die();
  81. return [
  82. 'anime' => $animeIds,
  83. 'manga' => $mangaIds,
  84. ];
  85. }
  86. }