Add API testing scripts

This commit is contained in:
DariusIII
2015-12-15 14:30:16 +01:00
parent d873f8395d
commit d4a7a31576
7 changed files with 125 additions and 5 deletions
+12 -4
View File
@@ -7,13 +7,14 @@ use newznab\processing\tv\TVDB;
$c = new newznab\ColorCLI();
$tvdb = new TVDB();
if (!empty($argv[1]) && is_numeric($argv[2]) && is_numeric($argv[3])) {
if (isset($argv[1]) && !empty($argv[1]) && isset($argv[2]) && is_numeric($argv[2]) && isset($argv[3]) && is_numeric($argv[3])) {
// Test if your TvDB API key and configuration are working
// If it works you should get a var dumped array of the show/season/episode entered
$season = (int)$argv[2];
$episode = (int)$argv[3];
$day = (isset($argv[4]) && is_numeric($argv[4]) ? $argv[4] : '');
$serverTime = $tvdb->client->getServerTime();
@@ -26,18 +27,23 @@ if (!empty($argv[1]) && is_numeric($argv[2]) && is_numeric($argv[3])) {
echo PHP_EOL . $c->info("Server Time: " . $serverTime) . PHP_EOL;
print_r($series[0]);
if ($season > 0 AND $episode > 0) {
if ($season > 0 && $episode > 0 && $day === '') {
$episodeObj = $tvdb->client->getEpisode($series[0]->id, $season, $episode, 'en');
if ($episodeObj) {
print_r($episodeObj);
}
} else if ($season == 0 && $episode == 0) {
$episodeObj = $tvdb->client->getSerieEpisodes($series[0]->id, 'en');
if ($episodeObj['episodes'] instanceof \Traversable) {
if (is_array($episodeObj['episodes'])) {
foreach ($episodeObj['episodes'] AS $ep) {
print_r($ep);
}
}
} else if (preg_match('#^(19|20)\d{2}\/\d{2}\/\d{2}$#', $season . '/' . $episode . '/' . $day, $airdate)) {
$episodeObj = $tvdb->client->getEpisodeByAirDate($series[0]->id, (string)$airdate[0], 'en');
if ($episodeObj) {
print_r($episodeObj);
}
} else {
exit($c->error("Invalid episode data returned from TVDB API."));
}
@@ -47,5 +53,7 @@ if (!empty($argv[1]) && is_numeric($argv[2]) && is_numeric($argv[3])) {
}
} else {
exit($c->error("Invalid arguments. This script requires a text string (show name) followed by a season and episode number."));
exit($c->error("Invalid arguments. This script requires a text string (show name) followed by a season and episode number." . PHP_EOL .
"You can also optionally supply 'YYYY' 'MM' 'DD' arguments instead of season/episode for an airdate lookup.")
);
}