Change AniDB support a bit

This commit is contained in:
DariusIII
2017-04-18 15:50:24 +02:00
parent 7b92de73d0
commit b44db312b6
3 changed files with 60 additions and 14 deletions
+4 -2
View File
@@ -4,6 +4,7 @@
*/
require_once dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'bootstrap.php';
use nntmux\ColorCLI;
use nntmux\db\DB;
use nntmux\db\populate\AniDB;
@@ -16,9 +17,10 @@ if ($argc > 1 && $argv[1] === 'true' && isset($argv[2])) {
(new AniDB(['Settings' => $pdo, 'Echo' => true]))->populateTable('info');
}
} else {
$pdo->log->doEcho(PHP_EOL . $pdo->log->error(
ColorCLI::doEcho(PHP_EOL . ColorCLI::error(
'To execute this script you must provide a boolean argument.' . PHP_EOL .
'Argument1: true|false to run this script or not' . PHP_EOL .
'Argument2: full|info for what type of data to populate'), true
'Argument2: full|info for what type of data to populate.' . PHP_EOL .
'WARNING: Argument "info" will get you banned from AniDB almost instantly'), true
);
}
+52 -8
View File
@@ -2,6 +2,7 @@
namespace nntmux\db\populate;
use GuzzleHttp\Client;
use app\models\Settings;
use nntmux\ColorCLI;
use nntmux\ReleaseImage;
@@ -71,6 +72,7 @@ class AniDB
$this->echooutput = ($options['Echo'] && NN_ECHOCLI);
$this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB());
$this->guzzleclient = new Client();
$anidbupdint = Settings::value('APIs.AniDB.max_update_frequency');
$lastupdated = Settings::value('APIs.AniDB.last_full_update');
@@ -86,17 +88,17 @@ class AniDB
/**
* Main switch that initiates AniDB table population
*
* @param string $type
* @param string $type
* @param int|string $anidbId
*/
public function populateTable($type = '')
public function populateTable($type = '', $anidbId = '')
{
switch ($type) {
case 'full':
$this->populateMainTable();
$this->populateInfoTable();
break;
case 'info':
$this->populateInfoTable();
$this->populateInfoTable($anidbId);
break;
}
}
@@ -145,7 +147,7 @@ class AniDB
$AniDBAPIArray = [];
if (!$apiresponse) {
if ($apiresponse === false) {
echo 'AniDB: Error getting response.' . PHP_EOL;
} elseif (preg_match('/\<error\>Banned\<\/error\>/', $apiresponse)) {
$this->banned = true;
@@ -414,11 +416,52 @@ class AniDB
/**
* Directs flow for populating the AniDB Info/Episodes table
*
* @param string $anidbId
*/
private function populateInfoTable()
private function populateInfoTable($anidbId = '')
{
$anidbIds = $this->pdo->query(sprintf('SELECT DISTINCT anidbid AS anidbid FROM anidb_titles'));
foreach ($anidbIds as $anidbId) {
if ($anidbId === '') {
$anidbIds = $this->pdo->query(sprintf(
'SELECT DISTINCT at.anidbid AS anidbid, ai.updated
FROM anidb_titles at
LEFT JOIN anidb_info ai ON ai.anidbid = at.anidbid
WHERE ai.updated IS NULL'
)
);
foreach ($anidbIds as $anidbId) {
$AniDBAPIArray = $this->getAniDbAPI($anidbId['anidbid']);
if ($this->banned === true) {
ColorCLI::doEcho(
ColorCLI::error(
'AniDB Banned, import will fail, please wait 24 hours before retrying.'
),
true
);
exit;
}
if ($AniDBAPIArray === false && $this->echooutput) {
ColorCLI::doEcho(
ColorCLI::info(
'Anime ID: ' . $anidbId['anidbid'] . ' not available for update yet.'
),
true
);
} else {
$this->updateAniChildTables($AniDBAPIArray, $anidbId);
if (NN_DEBUG) {
ColorCLI::doEcho(
ColorCLI::headerOver(
'Added/Updated AniDB ID: ' . $anidbId['anidbid']
),
true
);
}
}
}
} else {
$AniDBAPIArray = $this->getAniDbAPI($anidbId['anidbid']);
if ($this->banned === true) {
@@ -506,6 +549,7 @@ class AniDB
* Directs flow for updating child AniDB tables
*
* @param array $AniDBInfoArray
* @param $anidbId
*/
private function updateAniChildTables($AniDBInfoArray = [], $anidbId)
{
+4 -4
View File
@@ -26,7 +26,7 @@ class AniDB
public $padb;
/**
* @var \nntmux\db\Settings
* @var DB
*/
public $pdo;
@@ -192,10 +192,10 @@ class AniDB
private function getAnidbByName($searchName = '')
{
return $this->pdo->queryOneRow(
sprintf("
sprintf('
SELECT at.anidbid, at.title
FROM anidb_titles AS at
WHERE at.title %s",
WHERE at.title %s',
$this->pdo->likeString($searchName, true, true)
)
);
@@ -237,7 +237,7 @@ class AniDB
if ($updatedAni === false) {
if ($this->updateTimeCheck($anidbId['anidbid']) !== false) {
$this->padb->populateTable('info', $anidbId['anidbid']);
$this->padb->populateTable('info', $anidbId);
$this->doRandomSleep();
$updatedAni = $this->checkAniDBInfo($anidbId['anidbid']);
$type = 'Remote';