Select Git revision
api.php 8.03 KiB
<?php
include_once 'config.php';
if ($_GET['get'] == 'shows' && $_GET['limit'] && isset($_GET['offset'])) {
$output = array();
$data = querySB('shows');
uasort($data, function($a, $b) {
return strcmp($a['show_name'], $b['show_name']);
});
$shows = array_slice($data, $_GET['offset'], $_GET['limit'], true);
foreach($shows as $key => $show) {
$dataShow = querySB('show', $key);
$dataSeasons = querySB('show.seasons', $key);
$seasons = array();
foreach($dataSeasons as $season => $episodes) {
array_push($seasons, array("season" => $season, "count" => count($episodes)));
}
array_push($output, array(
"id" => $key,
"name" => $show['show_name'],
"folder" => str_replace($showsPath.'/', '', $dataShow['location']),
"thumb" => cleanName($show['show_name']),
"seasons" => $seasons
));
unset($seasons);
}
echo json_encode($output);
die;
}
if ($_GET['get'] == 'movies' && $_GET['limit'] && isset($_GET['offset'])) {
$cpdb = new PDO('sqlite:'.$cpPath.'/couchpotato.db');
$cpdb->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$movies = $cpdb->query("SELECT l.identifier AS imdb, lt.title, l.year, l.tagline, l.plot, s.label AS status FROM library AS l
JOIN librarytitle AS lt ON l.id=lt.libraries_id
JOIN movie AS m on l.id=m.library_id
JOIN status AS s ON m.status_id=s.id
WHERE m.status_id = 3 AND `default` = 1
ORDER BY title ASC LIMIT ".$_GET['limit']." OFFSET ".$_GET['offset'].";");
$output = array();
foreach ($movies as $movie) {
array_push($output, array(
"imdb" => $movie['imdb'],
"title" => $movie['title'],
"year" => $movie['year'],
"tagline" => $movie['tagline'],
"plot" => $movie['plot'],
"status" => $movie['status']
));
}
echo json_encode($output);
die;
}
if ($_GET['get'] == 'poster' && (!empty($_GET['show']) || !empty($_GET['movie']))) {
if($_GET['show'] && $_GET['season'])
$poster = get_absolute_path('poster/'.cleanName($_GET['show']).'-S'.$_GET['season'].'.jpg');
elseif($_GET['show'])
$poster = get_absolute_path('poster/'.cleanName($_GET['show']).'.jpg');
else
$poster = get_absolute_path('poster/'. cleanName($_GET['movie']).'.jpg');