Update api, Releases, anime

This commit is contained in:
DariusIII
2015-10-24 00:02:04 +02:00
parent 66ef6510d8
commit dd2a0271a8
7 changed files with 107 additions and 16 deletions
+1
View File
@@ -1,4 +1,5 @@
2015-10-23 DariusIII
Upd: Update api, Releases, anime etc
Chg: Add missing genres and groups output to api
Chg: Add the fixes from nZEDb/dev-tv branch
Chg: Revert the failed releases query in search
+75
View File
@@ -0,0 +1,75 @@
<?php
namespace newznab;
use newznab\db\Settings;
use newznab\utility\Versions;
class Capabilities
{
/**
* @var Settings
*/
public $pdo;
/**
* Construct.
*
* @param array $options Class instances.
*/
public function __construct(array $options = [])
{
$defaults = [
'Settings' => null,
];
$options += $defaults;
$this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings());
}
/**
* Collect and return various capability information for usage in API
*
* @return array
*/
public function getForMenu()
{
$serverroot = '';
$https = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? true : false);
if (isset($_SERVER['SERVER_NAME'])) {
$serverroot = (
($https === true ? 'https://' : 'http://') . $_SERVER['SERVER_NAME'] .
(($_SERVER['SERVER_PORT'] != '80' && $_SERVER['SERVER_PORT'] != '443') ? ':' . $_SERVER['SERVER_PORT'] : '') .
WWW_TOP . '/'
);
}
return [
'server' => [
'appversion' => (new Versions())->getTagVersion(),
'version' => '0.1',
'title' => $this->pdo->getSetting('title'),
'strapline' => $this->pdo->getSetting('strapline'),
'email' => $this->pdo->getSetting('email'),
'url' => $serverroot,
'image' => $serverroot . 'themes_shared/images/logo.png'
],
'limits' => [
'max' => 100,
'default' => 100
],
'registration' => [
'available' => 'yes',
'open' => $this->pdo->getSetting('registerstatus') == 0 ? 'yes' : 'no'
],
'searching' => [
['search' => 'yes'],
['supportedParams' => 'q'],
['tv-search' => 'yes'],
['supportedParams' => 'q, vid, tvdbid, traktid, rid, tvmazeid, imdbid, tmdbid, season, ep'],
['movie-search' => 'yes'],
['supportedParams' => 'q'],
['audio-search' => 'yes']
]
];
}
}
+10 -10
View File
@@ -1293,20 +1293,20 @@ class Releases
}
/**
* @param int $rageID
* @param $videoId
*
* @return int
* @return bool|\PDOStatement
*/
public function removeRageIdFromReleases($rageID)
public function removeVideoIdFromReleases($videoId)
{
$res = $this->pdo->queryOneRow(
sprintf('SELECT COUNT(r.id) AS num FROM releases r WHERE rageid = %d', $rageID)
return $this->pdo->queryExec(
sprintf('
UPDATE releases
SET videos_id = 0, tv_episodes_id = 0
WHERE videos_id = %d',
$videoId
)
);
$this->pdo->queryExec(
sprintf('UPDATE releases SET rageid = -1, seriesfull = NULL, season = NULL, episode = NULL WHERE rageid = %d', $rageID)
);
return ($res === false ? 0 : $res['num']);
}
/**
+1 -1
View File
@@ -9,7 +9,7 @@ $releases = new Releases(['Settings' => $page->settings]);
$success = false;
if (isset($_GET["id"])) {
$success = $releases->removeRageIdFromReleases($_GET["id"]);
$success = $releases->removeVideoIdFromReleases($_GET["id"]);
$page->smarty->assign('videoid', $_GET["id"]);
}
+1 -1
View File
@@ -13,7 +13,7 @@ $AniDB = new AniDB(['Settings' => $page->settings]);
if (isset($_GET['id']) && ctype_digit($_GET['id'])) {
# force the category to 5070 as it should be for anime, as $catarray was NULL and we know the category for sure for anime
$releases = $Releases->searchbyAnidbId($_GET['id'], 0, 1000, '', array('5070'), -1);
$releases = $Releases->searchbyAnidbId($_GET['id'], '', 0, 1000, '', ['5070'], -1);
$anidb = $AniDB->getAnimeInfo($_GET['id']);
if (!$releases && !$anidb) {
+16 -1
View File
@@ -6,6 +6,7 @@ use newznab\Releases;
use newznab\Category;
use newznab\Groups;
use newznab\Genres;
use newznab\Capabilities;
$rc = new ReleaseComments;
$groups = new Groups();
@@ -445,7 +446,21 @@ switch ($function) {
$genre = $genres->getGenres('', true);
$page->smarty->assign('genres', $genre);
header('Content-type: text/xml');
echo $page->smarty->fetch('apicaps.tpl');
if ($outputXML) { //use apicaps.tpl if xml is requested
$response = $page->smarty->fetch('apicaps.tpl');
header('Content-type: text/xml');
header('Content-Length: ' . strlen($response) );
echo $response;
} else { //otherwise construct array of capabilities and categories
//get capabilities
$caps = (new Capabilities(['Settings' => $page->settings]))->getForMenu();
$caps['categories'] = $cats;
//use json_encode
$response = encodeAsJSON($caps);
header('Content-type: application/json');
header('Content-Length: ' . strlen($response) );
echo $response;
}
break;
// Register request.
@@ -6,9 +6,9 @@
<limits max="100" default="100"/>
<registration available="yes" open="{if $site->registerstatus == 0}yes{else}no{/if}"/>
<searching>
<search available="yes"/>
<tv-search available="yes"/>
<movie-search available="yes"/>
<search available="yes" supportedParams="q" />
<tv-search available="yes" supportedParams="q, vid, tvdbid, traktid, rid, tvmazeid, imdbid, tmdbid, season, ep" />
<movie-search available="yes" supportedParams="q" />
<audio-search available="yes"/>
</searching>
<categories>