Select Git revision
api.php 4.47 KiB
<?php
include_once 'config.php';
if ($_GET['get'] == 'shows') {
$sbdb = new SQLite3($sbPath.'/sickbeard.db');
$shows = $sbdb->query("SELECT tvdb_id AS id, show_name AS name, location FROM tv_shows ORDER BY show_name ASC;");
$output = array();
while ($show = $shows->fetchArray()) {
$rows = $sbdb->query("SELECT season, COUNT(episode_id) AS count FROM tv_episodes WHERE showid = '".$show['id']."' GROUP BY season ORDER BY season ASC");
$seasons = array();
while ($row = $rows->fetchArray()) {
array_push($seasons, array("season" => $row['season'], "count" => $row['count']));
}
array_push($output, array(
"id" => $show['id'],
"name" => $show['name'],
"folder" => str_replace($showsPath.'/', '', $show['location']),
"thumb" => cleanName($show['name']),
"seasons" => $seasons
));
unset($seasons);
}
echo json_encode($output);
die;
}
if ($_GET['get'] == 'poster' && !empty($_GET['show'])) {
if($_GET['season'])
$poster = get_absolute_path('poster/'.cleanName($_GET['show']).'-S'.$_GET['season'].'.jpg');
else
$poster = get_absolute_path('poster/'.cleanName($_GET['show']).'.jpg');
if(!file_exists($poster)) {
if($_GET['season'])
$source = '/'.get_absolute_path($showsPath.'/'.$_GET['show'].'/season'.$_GET['season'].'-poster.jpg');
else
$source = '/'.get_absolute_path($showsPath.'/'.$_GET['show'].'/poster.jpg');
if(file_exists($source)) {
$img = new Imagick();
$img->setOption('jpeg:size', '800x532');
$img->readImage($source);
$img->thumbnailImage(0, 220);
$img->setImageCompression(Imagick::COMPRESSION_JPEG);
$img->setImageCompressionQuality(80);
$img->writeImage($poster);
}elseif($_GET['season'] != '') {
header("HTTP/1.0 404 Not Found");
die;
}else{
$poster = 'img/no_poster.jpg';
}
}
header('Content-type: image/jpeg');
header('Content-length: '.filesize($poster));
readfile($poster);
die;
}
if ($_GET['get'] == 'fanart' && !empty($_GET['show'])) {
$fanart = get_absolute_path('fanart/'.cleanName($_GET['show']).'.jpg');
if(!file_exists($fanart)) {