2017-01-27 12:35:28 -05:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
/**
|
2017-02-15 16:13:32 -05:00
|
|
|
* Hummingbird Anime List Client
|
2017-01-27 12:35:28 -05:00
|
|
|
*
|
|
|
|
* An API client for Kitsu and MyAnimeList to manage anime and manga watch lists
|
|
|
|
*
|
|
|
|
* PHP version 7
|
|
|
|
*
|
2017-02-15 16:13:32 -05:00
|
|
|
* @package HummingbirdAnimeClient
|
2017-01-27 12:35:28 -05:00
|
|
|
* @author Timothy J. Warren <tim@timshomepage.net>
|
|
|
|
* @copyright 2015 - 2017 Timothy J. Warren
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
|
|
|
* @version 4.0
|
2017-03-07 20:53:58 -05:00
|
|
|
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
|
2017-01-27 12:35:28 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Aviat\AnimeClient\Command;
|
|
|
|
|
2017-02-14 15:29:13 -05:00
|
|
|
use function Amp\{all, wait};
|
|
|
|
|
|
|
|
use Amp\Artax\Client;
|
2017-03-29 12:32:36 -04:00
|
|
|
use Aviat\AnimeClient\API\{
|
|
|
|
JsonAPI,
|
|
|
|
ParallelAPIRequest,
|
|
|
|
Mapping\AnimeWatchingStatus,
|
|
|
|
Mapping\MangaReadingStatus
|
|
|
|
};
|
|
|
|
use Aviat\AnimeClient\API\MAL\Transformer\{
|
|
|
|
AnimeListTransformer as ALT,
|
|
|
|
MangaListTransformer as MLT
|
|
|
|
};
|
2017-02-14 15:29:13 -05:00
|
|
|
use Aviat\Ion\Json;
|
2017-01-27 12:35:28 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears the API Cache
|
|
|
|
*/
|
|
|
|
class SyncKitsuWithMal extends BaseCommand {
|
2017-02-08 15:48:20 -05:00
|
|
|
|
2017-02-17 10:55:17 -05:00
|
|
|
/**
|
|
|
|
* Model for making requests to Kitsu API
|
2017-02-22 14:46:35 -05:00
|
|
|
* @var \Aviat\AnimeClient\API\Kitsu\Model
|
2017-02-17 10:55:17 -05:00
|
|
|
*/
|
2017-01-27 12:35:28 -05:00
|
|
|
protected $kitsuModel;
|
2017-03-31 13:37:53 -04:00
|
|
|
|
2017-02-17 10:55:17 -05:00
|
|
|
/**
|
|
|
|
* Model for making requests to MAL API
|
2017-02-22 14:46:35 -05:00
|
|
|
* @var \Aviat\AnimeClient\API\MAL\Model
|
2017-02-17 10:55:17 -05:00
|
|
|
*/
|
2017-02-08 15:48:20 -05:00
|
|
|
protected $malModel;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run the image conversion script
|
|
|
|
*
|
|
|
|
* @param array $args
|
|
|
|
* @param array $options
|
|
|
|
* @return void
|
|
|
|
* @throws \ConsoleKit\ConsoleException
|
|
|
|
*/
|
|
|
|
public function execute(array $args, array $options = [])
|
|
|
|
{
|
|
|
|
$this->setContainer($this->setupContainer());
|
|
|
|
$this->setCache($this->container->get('cache'));
|
|
|
|
$this->kitsuModel = $this->container->get('kitsu-model');
|
|
|
|
$this->malModel = $this->container->get('mal-model');
|
2017-03-27 10:09:45 -04:00
|
|
|
|
2017-03-29 12:32:36 -04:00
|
|
|
$this->syncAnime();
|
|
|
|
$this->syncManga();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function syncAnime()
|
|
|
|
{
|
|
|
|
$malCount = count($this->malModel->getAnimeList());
|
|
|
|
$kitsuCount = $this->kitsuModel->getAnimeListCount();
|
2017-03-27 10:09:45 -04:00
|
|
|
|
2017-03-29 12:32:36 -04:00
|
|
|
$this->echoBox("Number of MAL anime list items: {$malCount}");
|
|
|
|
$this->echoBox("Number of Kitsu anime list items: {$kitsuCount}");
|
2017-03-27 10:09:45 -04:00
|
|
|
|
|
|
|
$data = $this->diffAnimeLists();
|
2017-03-29 12:32:36 -04:00
|
|
|
|
|
|
|
$this->echoBox("Number of anime items that need to be added to MAL: " . count($data['addToMAL']));
|
2017-03-27 10:09:45 -04:00
|
|
|
|
2017-02-17 10:55:17 -05:00
|
|
|
if ( ! empty($data['addToMAL']))
|
2017-02-14 15:29:13 -05:00
|
|
|
{
|
2017-03-29 12:32:36 -04:00
|
|
|
$this->echoBox("Adding missing anime list items to MAL");
|
2017-03-31 13:37:53 -04:00
|
|
|
$this->createMALListItems($data['addToMAL'], 'anime');
|
2017-02-14 15:29:13 -05:00
|
|
|
}
|
2017-03-28 16:52:27 -04:00
|
|
|
|
2017-03-29 12:32:36 -04:00
|
|
|
$this->echoBox('Number of anime items that need to be added to Kitsu: ' . count($data['addToKitsu']));
|
2017-03-28 16:52:27 -04:00
|
|
|
|
|
|
|
if ( ! empty($data['addToKitsu']))
|
|
|
|
{
|
2017-03-29 12:32:36 -04:00
|
|
|
$this->echoBox("Adding missing anime list items to Kitsu");
|
2017-04-03 15:46:16 -04:00
|
|
|
$this->createKitsuListItems($data['addToKitsu'], 'anime');
|
2017-03-28 16:52:27 -04:00
|
|
|
}
|
2017-02-08 15:48:20 -05:00
|
|
|
}
|
2017-03-27 10:09:45 -04:00
|
|
|
|
2017-03-29 12:32:36 -04:00
|
|
|
public function syncManga()
|
2017-02-14 15:29:13 -05:00
|
|
|
{
|
2017-03-29 12:32:36 -04:00
|
|
|
$malCount = count($this->malModel->getMangaList());
|
|
|
|
$kitsuCount = $this->kitsuModel->getMangaListCount();
|
2017-03-27 10:09:45 -04:00
|
|
|
|
2017-03-29 12:32:36 -04:00
|
|
|
$this->echoBox("Number of MAL manga list items: {$malCount}");
|
|
|
|
$this->echoBox("Number of Kitsu manga list items: {$kitsuCount}");
|
2017-03-27 10:09:45 -04:00
|
|
|
|
2017-03-29 12:32:36 -04:00
|
|
|
$data = $this->diffMangaLists();
|
2017-02-17 10:55:17 -05:00
|
|
|
|
2017-03-29 12:32:36 -04:00
|
|
|
$this->echoBox("Number of manga items that need to be added to MAL: " . count($data['addToMAL']));
|
2017-02-08 15:48:20 -05:00
|
|
|
|
2017-03-29 12:32:36 -04:00
|
|
|
if ( ! empty($data['addToMAL']))
|
2017-02-14 15:29:13 -05:00
|
|
|
{
|
2017-03-29 12:32:36 -04:00
|
|
|
$this->echoBox("Adding missing manga list items to MAL");
|
2017-03-31 13:37:53 -04:00
|
|
|
$this->createMALListItems($data['addToMAL'], 'manga');
|
2017-02-14 15:29:13 -05:00
|
|
|
}
|
2017-02-17 10:55:17 -05:00
|
|
|
|
2017-03-29 12:32:36 -04:00
|
|
|
$this->echoBox('Number of manga items that need to be added to Kitsu: ' . count($data['addToKitsu']));
|
2017-02-08 15:48:20 -05:00
|
|
|
|
2017-03-29 12:32:36 -04:00
|
|
|
if ( ! empty($data['addToKitsu']))
|
|
|
|
{
|
|
|
|
$this->echoBox("Adding missing manga list items to Kitsu");
|
2017-03-31 13:37:53 -04:00
|
|
|
$this->createKitsuListItems($data['addToKitsu'], 'manga');
|
2017-03-29 12:32:36 -04:00
|
|
|
}
|
2017-02-08 15:48:20 -05:00
|
|
|
}
|
2017-03-27 10:09:45 -04:00
|
|
|
|
2017-03-29 12:32:36 -04:00
|
|
|
public function filterMappings(array $includes, string $type = 'anime'): array
|
2017-01-27 12:35:28 -05:00
|
|
|
{
|
2017-02-14 15:29:13 -05:00
|
|
|
$output = [];
|
2017-03-27 10:09:45 -04:00
|
|
|
|
2017-02-14 15:29:13 -05:00
|
|
|
foreach($includes as $id => $mapping)
|
2017-01-27 12:35:28 -05:00
|
|
|
{
|
2017-03-29 12:32:36 -04:00
|
|
|
if ($mapping['externalSite'] === "myanimelist/{$type}")
|
2017-02-14 15:29:13 -05:00
|
|
|
{
|
|
|
|
$output[$id] = $mapping;
|
|
|
|
}
|
2017-01-27 12:35:28 -05:00
|
|
|
}
|
2017-03-27 10:09:45 -04:00
|
|
|
|
2017-02-14 15:29:13 -05:00
|
|
|
return $output;
|
|
|
|
}
|
2017-03-27 10:09:45 -04:00
|
|
|
|
|
|
|
public function formatMALAnimeList()
|
2017-02-14 15:29:13 -05:00
|
|
|
{
|
2017-03-29 12:32:36 -04:00
|
|
|
$orig = $this->malModel->getAnimeList();
|
2017-02-14 15:29:13 -05:00
|
|
|
$output = [];
|
2017-03-27 10:09:45 -04:00
|
|
|
|
2017-02-14 15:29:13 -05:00
|
|
|
foreach($orig as $item)
|
2017-01-27 12:35:28 -05:00
|
|
|
{
|
2017-02-14 15:29:13 -05:00
|
|
|
$output[$item['series_animedb_id']] = [
|
|
|
|
'id' => $item['series_animedb_id'],
|
|
|
|
'data' => [
|
2017-03-07 20:49:31 -05:00
|
|
|
'status' => AnimeWatchingStatus::MAL_TO_KITSU[$item['my_status']],
|
2017-02-14 15:29:13 -05:00
|
|
|
'progress' => $item['my_watched_episodes'],
|
|
|
|
'reconsuming' => (bool) $item['my_rewatching'],
|
|
|
|
'reconsumeCount' => array_key_exists('times_rewatched', $item)
|
|
|
|
? $item['times_rewatched']
|
|
|
|
: 0,
|
|
|
|
// 'notes' => ,
|
2017-03-28 16:52:27 -04:00
|
|
|
'rating' => $item['my_score'] / 2,
|
2017-02-14 15:29:13 -05:00
|
|
|
'updatedAt' => (new \DateTime())
|
|
|
|
->setTimestamp((int)$item['my_last_updated'])
|
|
|
|
->format(\DateTime::W3C),
|
|
|
|
]
|
|
|
|
];
|
2017-01-27 12:35:28 -05:00
|
|
|
}
|
2017-03-27 10:09:45 -04:00
|
|
|
|
2017-02-14 15:29:13 -05:00
|
|
|
return $output;
|
2017-01-27 12:35:28 -05:00
|
|
|
}
|
2017-03-27 10:09:45 -04:00
|
|
|
|
2017-03-29 12:32:36 -04:00
|
|
|
public function formatMALMangaList()
|
|
|
|
{
|
|
|
|
$orig = $this->malModel->getMangaList();
|
|
|
|
$output = [];
|
|
|
|
|
|
|
|
foreach($orig as $item)
|
|
|
|
{
|
|
|
|
$output[$item['series_mangadb_id']] = [
|
|
|
|
'id' => $item['series_mangadb_id'],
|
|
|
|
'data' => [
|
|
|
|
'my_status' => $item['my_status'],
|
|
|
|
'status' => MangaReadingStatus::MAL_TO_KITSU[$item['my_status']],
|
|
|
|
'progress' => $item['my_read_chapters'],
|
2017-03-31 13:37:53 -04:00
|
|
|
'volumes' => $item['my_read_volumes'],
|
2017-03-29 12:32:36 -04:00
|
|
|
'reconsuming' => (bool) $item['my_rereadingg'],
|
|
|
|
/* 'reconsumeCount' => array_key_exists('times_rewatched', $item)
|
|
|
|
? $item['times_rewatched']
|
|
|
|
: 0, */
|
|
|
|
// 'notes' => ,
|
|
|
|
'rating' => $item['my_score'] / 2,
|
|
|
|
'updatedAt' => (new \DateTime())
|
|
|
|
->setTimestamp((int)$item['my_last_updated'])
|
|
|
|
->format(\DateTime::W3C),
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
2017-03-27 10:09:45 -04:00
|
|
|
public function filterKitsuAnimeList()
|
2017-01-27 12:35:28 -05:00
|
|
|
{
|
2017-03-07 18:41:51 -05:00
|
|
|
$data = $this->kitsuModel->getFullAnimeList();
|
2017-02-14 15:29:13 -05:00
|
|
|
$includes = JsonAPI::organizeIncludes($data['included']);
|
|
|
|
$includes['mappings'] = $this->filterMappings($includes['mappings']);
|
2017-03-27 10:09:45 -04:00
|
|
|
|
2017-02-14 15:29:13 -05:00
|
|
|
$output = [];
|
2017-03-27 10:09:45 -04:00
|
|
|
|
2017-02-14 15:29:13 -05:00
|
|
|
foreach($data['data'] as $listItem)
|
|
|
|
{
|
|
|
|
$animeId = $listItem['relationships']['anime']['data']['id'];
|
|
|
|
$potentialMappings = $includes['anime'][$animeId]['relationships']['mappings'];
|
2017-02-17 10:55:17 -05:00
|
|
|
$malId = NULL;
|
2017-03-27 10:09:45 -04:00
|
|
|
|
2017-02-14 15:29:13 -05:00
|
|
|
foreach ($potentialMappings as $mappingId)
|
|
|
|
{
|
|
|
|
if (array_key_exists($mappingId, $includes['mappings']))
|
|
|
|
{
|
|
|
|
$malId = $includes['mappings'][$mappingId]['externalId'];
|
|
|
|
}
|
|
|
|
}
|
2017-03-27 10:09:45 -04:00
|
|
|
|
2017-02-14 15:29:13 -05:00
|
|
|
// Skip to the next item if there isn't a MAL ID
|
2017-02-17 10:55:17 -05:00
|
|
|
if (is_null($malId))
|
2017-02-14 15:29:13 -05:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2017-03-27 10:09:45 -04:00
|
|
|
|
2017-02-14 15:29:13 -05:00
|
|
|
$output[$listItem['id']] = [
|
|
|
|
'id' => $listItem['id'],
|
|
|
|
'malId' => $malId,
|
|
|
|
'data' => $listItem['attributes'],
|
|
|
|
];
|
|
|
|
}
|
2017-03-27 10:09:45 -04:00
|
|
|
|
2017-02-14 15:29:13 -05:00
|
|
|
return $output;
|
|
|
|
}
|
2017-02-08 15:48:20 -05:00
|
|
|
|
2017-03-29 12:32:36 -04:00
|
|
|
public function filterKitsuMangaList()
|
2017-02-14 15:29:13 -05:00
|
|
|
{
|
2017-03-29 12:32:36 -04:00
|
|
|
$data = $this->kitsuModel->getFullMangaList();
|
|
|
|
$includes = JsonAPI::organizeIncludes($data['included']);
|
|
|
|
$includes['mappings'] = $this->filterMappings($includes['mappings'], 'manga');
|
|
|
|
|
|
|
|
$output = [];
|
|
|
|
|
|
|
|
foreach($data['data'] as $listItem)
|
|
|
|
{
|
|
|
|
$mangaId = $listItem['relationships']['manga']['data']['id'];
|
|
|
|
$potentialMappings = $includes['manga'][$mangaId]['relationships']['mappings'];
|
|
|
|
$malId = NULL;
|
|
|
|
|
|
|
|
foreach ($potentialMappings as $mappingId)
|
|
|
|
{
|
|
|
|
if (array_key_exists($mappingId, $includes['mappings']))
|
|
|
|
{
|
|
|
|
$malId = $includes['mappings'][$mappingId]['externalId'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Skip to the next item if there isn't a MAL ID
|
|
|
|
if (is_null($malId))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$output[$listItem['id']] = [
|
|
|
|
'id' => $listItem['id'],
|
|
|
|
'malId' => $malId,
|
|
|
|
'data' => $listItem['attributes'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function diffMangaLists()
|
|
|
|
{
|
|
|
|
$kitsuList = $this->filterKitsuMangaList();
|
|
|
|
$malList = $this->formatMALMangaList();
|
|
|
|
|
|
|
|
$itemsToAddToMAL = [];
|
|
|
|
$itemsToAddToKitsu = [];
|
|
|
|
|
|
|
|
$malIds = array_column($malList, 'id');
|
|
|
|
$kitsuMalIds = array_column($kitsuList, 'malId');
|
|
|
|
$missingMalIds = array_diff($malIds, $kitsuMalIds);
|
|
|
|
|
|
|
|
foreach($missingMalIds as $mid)
|
|
|
|
{
|
|
|
|
$itemsToAddToKitsu[] = array_merge($malList[$mid]['data'], [
|
|
|
|
'id' => $this->kitsuModel->getKitsuIdFromMALId($mid, 'manga'),
|
|
|
|
'type' => 'manga'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach($kitsuList as $kitsuItem)
|
|
|
|
{
|
|
|
|
if (in_array($kitsuItem['malId'], $malIds))
|
|
|
|
{
|
|
|
|
// Eventually, compare the list entries, and determine which
|
|
|
|
// needs to be updated
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Looks like this item only exists on Kitsu
|
|
|
|
$itemsToAddToMAL[] = [
|
|
|
|
'mal_id' => $kitsuItem['malId'],
|
|
|
|
'data' => $kitsuItem['data']
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
'addToMAL' => $itemsToAddToMAL,
|
|
|
|
'addToKitsu' => $itemsToAddToKitsu
|
|
|
|
];
|
2017-02-08 15:48:20 -05:00
|
|
|
}
|
|
|
|
|
2017-03-27 10:09:45 -04:00
|
|
|
public function diffAnimeLists()
|
2017-02-08 15:48:20 -05:00
|
|
|
{
|
|
|
|
// Get libraryEntries with media.mappings from Kitsu
|
|
|
|
// Organize mappings, and ignore entries without mappings
|
2017-03-27 10:09:45 -04:00
|
|
|
$kitsuList = $this->filterKitsuAnimeList();
|
2017-02-08 15:48:20 -05:00
|
|
|
|
|
|
|
// Get MAL list data
|
2017-03-27 10:09:45 -04:00
|
|
|
$malList = $this->formatMALAnimeList();
|
|
|
|
|
2017-02-14 15:29:13 -05:00
|
|
|
$itemsToAddToMAL = [];
|
2017-03-28 16:52:27 -04:00
|
|
|
$itemsToAddToKitsu = [];
|
2017-03-31 13:37:53 -04:00
|
|
|
$malUpdateItems = [];
|
|
|
|
$kitsuUpdateItems = [];
|
2017-03-28 16:52:27 -04:00
|
|
|
|
|
|
|
$malIds = array_column($malList, 'id');
|
|
|
|
$kitsuMalIds = array_column($kitsuList, 'malId');
|
|
|
|
$missingMalIds = array_diff($malIds, $kitsuMalIds);
|
|
|
|
|
|
|
|
foreach($missingMalIds as $mid)
|
|
|
|
{
|
|
|
|
// print_r($malList[$mid]);
|
|
|
|
$itemsToAddToKitsu[] = array_merge($malList[$mid]['data'], [
|
|
|
|
'id' => $this->kitsuModel->getKitsuIdFromMALId($mid),
|
|
|
|
'type' => 'anime'
|
|
|
|
]);
|
|
|
|
}
|
2017-03-27 10:09:45 -04:00
|
|
|
|
2017-02-14 15:29:13 -05:00
|
|
|
foreach($kitsuList as $kitsuItem)
|
|
|
|
{
|
2017-03-28 16:52:27 -04:00
|
|
|
if (in_array($kitsuItem['malId'], $malIds))
|
2017-02-14 15:29:13 -05:00
|
|
|
{
|
2017-03-27 10:09:45 -04:00
|
|
|
// Eventually, compare the list entries, and determine which
|
2017-02-14 15:29:13 -05:00
|
|
|
// needs to be updated
|
|
|
|
continue;
|
|
|
|
}
|
2017-03-27 10:09:45 -04:00
|
|
|
|
2017-02-14 15:29:13 -05:00
|
|
|
// Looks like this item only exists on Kitsu
|
|
|
|
$itemsToAddToMAL[] = [
|
|
|
|
'mal_id' => $kitsuItem['malId'],
|
|
|
|
'data' => $kitsuItem['data']
|
|
|
|
];
|
2017-03-27 10:09:45 -04:00
|
|
|
|
2017-02-14 15:29:13 -05:00
|
|
|
}
|
2017-02-08 15:48:20 -05:00
|
|
|
|
|
|
|
// Compare each list entry
|
|
|
|
// If a list item exists only on MAL, create it on Kitsu with the existing data from MAL
|
|
|
|
// If a list item exists only on Kitsu, create it on MAL with the existing data from Kitsu
|
|
|
|
// If an item already exists on both APIS:
|
|
|
|
// Compare last updated dates, and use the later one
|
|
|
|
// Otherwise, use rewatch count, then episode progress as critera for selecting the more up
|
|
|
|
// to date entry
|
|
|
|
// Based on the 'newer' entry, update the other api list item
|
2017-03-27 10:09:45 -04:00
|
|
|
|
2017-02-14 15:29:13 -05:00
|
|
|
return [
|
|
|
|
'addToMAL' => $itemsToAddToMAL,
|
2017-03-31 13:37:53 -04:00
|
|
|
'updateMAL' => $malUpdateItems,
|
|
|
|
'addToKitsu' => $itemsToAddToKitsu,
|
|
|
|
'updateKitsu' => $kitsuUpdateItems
|
2017-02-14 15:29:13 -05:00
|
|
|
];
|
2017-01-27 12:35:28 -05:00
|
|
|
}
|
2017-02-08 15:48:20 -05:00
|
|
|
|
2017-04-03 15:46:16 -04:00
|
|
|
public function createKitsuListItems($itemsToAdd, $type = 'anime')
|
2017-03-29 12:32:36 -04:00
|
|
|
{
|
|
|
|
$requester = new ParallelAPIRequest();
|
|
|
|
foreach($itemsToAdd as $item)
|
|
|
|
{
|
|
|
|
$requester->addRequest($this->kitsuModel->createListItem($item));
|
|
|
|
}
|
|
|
|
|
|
|
|
$responses = $requester->makeRequests();
|
2017-03-28 16:52:27 -04:00
|
|
|
|
|
|
|
foreach($responses as $key => $response)
|
|
|
|
{
|
|
|
|
$id = $itemsToAdd[$key]['id'];
|
|
|
|
if ($response->getStatus() === 201)
|
|
|
|
{
|
2017-03-31 13:37:53 -04:00
|
|
|
$this->echoBox("Successfully created Kitsu {$type} list item with id: {$id}");
|
2017-03-28 16:52:27 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
echo $response->getBody();
|
2017-03-31 13:37:53 -04:00
|
|
|
$this->echoBox("Failed to create Kitsu {$type} list item with id: {$id}");
|
2017-03-28 16:52:27 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-31 13:37:53 -04:00
|
|
|
public function createMALListItems($itemsToAdd, $type = 'anime')
|
2017-02-14 15:29:13 -05:00
|
|
|
{
|
|
|
|
$transformer = new ALT();
|
2017-03-29 12:32:36 -04:00
|
|
|
$requester = new ParallelAPIRequest();
|
2017-03-27 10:09:45 -04:00
|
|
|
|
2017-02-14 15:29:13 -05:00
|
|
|
foreach($itemsToAdd as $item)
|
|
|
|
{
|
|
|
|
$data = $transformer->untransform($item);
|
2017-03-31 13:37:53 -04:00
|
|
|
$requester->addRequest($this->malModel->createFullListItem($data, $type));
|
2017-02-14 15:29:13 -05:00
|
|
|
}
|
2017-02-17 10:55:17 -05:00
|
|
|
|
2017-03-29 12:32:36 -04:00
|
|
|
$responses = $requester->makeRequests();
|
2017-02-17 10:55:17 -05:00
|
|
|
|
2017-02-14 15:29:13 -05:00
|
|
|
foreach($responses as $key => $response)
|
|
|
|
{
|
|
|
|
$id = $itemsToAdd[$key]['mal_id'];
|
|
|
|
if ($response->getBody() === 'Created')
|
|
|
|
{
|
2017-03-31 13:37:53 -04:00
|
|
|
$this->echoBox("Successfully created MAL {$type} list item with id: {$id}");
|
2017-02-14 15:29:13 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-31 13:37:53 -04:00
|
|
|
$this->echoBox("Failed to create MAL {$type} list item with id: {$id}");
|
2017-02-14 15:29:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-02-08 15:48:20 -05:00
|
|
|
}
|