Skip to content
Snippets Groups Projects
Select Git revision
  • master default
1 result

api.php

Blame
  • api.php 7.16 KiB
    <?php
    include_once 'config.php';
    
    if ($_GET['get'] == 'shows' && $_GET['limit'] && isset($_GET['offset'])) {
    
    	$sbdb = new PDO('sqlite:'.$sbPath.'/sickbeard.db');
    
    	$shows = $sbdb->query("SELECT tvdb_id AS id, show_name AS name, location FROM tv_shows ORDER BY show_name ASC LIMIT ".$_GET['limit']." OFFSET ".$_GET['offset'].";");
    	$output = array();
    	foreach($shows as $show) {
    		$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();
    		foreach($rows as $row) {
    			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'] == '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');
    
    	if(!file_exists($poster)) {
    
    		if($_GET['show'] && $_GET['season'])