Skip to content

Commit

Permalink
First commit of tvdb code
Browse files Browse the repository at this point in the history
  • Loading branch information
mclaughlin.matt committed Apr 16, 2010
1 parent f229ad8 commit 59ef9d4
Show file tree
Hide file tree
Showing 81 changed files with 11,091 additions and 0 deletions.
47 changes: 47 additions & 0 deletions NiftyLayout.css
@@ -0,0 +1,47 @@
html,body{margin:0;padding:0}
body{font: 85%/1.3 Verdana,Arial,sans-serif;
text-align: center;background: #757D88;padding-bottom:20px}
p{margin-top:0}
h1,h2,h3{font: normal normal 200% "Trebuchet MS",Arial,sans-serif}
h2{font-size:160%}
h3{font-size:120%}

div#header{width:100%;overflow:hidden;background: #595D66}
div#header h1,div#menu{width:770px;margin:0 auto;text-align:left}
div#header h1{padding: 30px 0 10px;color: #FFF}

ul#nav,ul#nav li{list-style-type:none;margin:0;padding:0}
ul#nav{float:right;font-size: 80%}
ul#nav li{float:left;margin-left: 3px;text-align: center}
ul#nav a{float:left;width: 95px;padding: 5px 0;background: #369A3D;text-decoration:none;color: #FFC}
ul#nav a:hover{background: #CDFFA1;color: #006A35}
ul#nav li.activelink a,ul#nav li.activelink a:hover{background: #FFF;color: #003}

div#container{width:770px;margin:0 auto 10px;padding:20px 0 10px;text-align:left;background:#FFF}
div#content{float:left;display:inline;width:560px;margin:0 0 10px 10px}

ul#intro,ul#intro li{list-style-type:none;margin:0;padding:0}
ul#intro{width:100%;overflow:hidden;margin-bottom:20px}
ul#intro li{float:left;width:180px;margin-right:10px;padding: 10px 0}
li#mission{background: #E65714}
li#services{background: #42B4AC}
ul#intro li#more{margin-right:0;background: #7D63A9}
ul#intro p,ul#intro h3{margin:0;padding: 0 10px}
ul#intro h3{text-transform:uppercase;padding-bottom:3px;color: #FFF}

div#content h2{margin: 10px 0;color: #007BC4}
div.date{float:left;width: 4em;padding: 5px 0;background: #F1DDC4;color:#B0001E;
text-align:center;margin: 0 4px 4px 0;font-size: 80%;line-height:0.9}
div.date span{display:block;font-size: 150%;font-weight:bold}

div.comments div{background: #EEE;margin-bottom:10px}
div.comments p{padding: 10px;margin:0}
div.comments div.odd{background:#DAE6FE}

div#side{float:right;display:inline;width: 180px;background:#F3CF00; margin:0 10px 10px 0}
div#side p{margin:5px 0 10px;padding: 0 10px}
div#side div{margin: 0 0 10px;padding: 10px 0}

div#footer{clear:both;width:750px;margin:0 10px 0;padding: 10px 0;
background: #586695;color: #FFF;text-align:center}
div#footer p{margin:0}
149 changes: 149 additions & 0 deletions api/GetSeries.php
@@ -0,0 +1,149 @@
<?php ## Interface that allows clients to get
## seriesid using seriesname
## Parameters:
## $_REQUEST["seriesname"]
## $_REQUEST["language"] (optional)
## $_REQUEST["user"] (optional... overrides language setting)
##
## Returns:
## XML item holding the series id that matches the seriesname

## Include functions, db connection, etc
include("include.php");
?>
<?php
## Prepare the search string
$seriesname = $_REQUEST["seriesname"];
$language = $_REQUEST["language"];
$user = $_REQUEST["user"];
if ($seriesname == "") {
print "<Error>seriesname is required</Error>\n";
exit;
}
else {
if (strpos($seriesname,", The")){$seriesname = "The ".substr($seriesname,0,strpos($seriesname,", The"));}
if (strpos($seriesname,"'")){$seriesname = str_replace("\'","",$seriesname);} ##To be removed if someone can figure out hwo to do this in sphinx
print "<Data>\n";
}


## Get the languageid from the abbreviation
if ($language && $language != "all") {
$query = "SELECT id FROM languages WHERE abbreviation='$language' LIMIT 1";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$db = mysql_fetch_object($result);
if ($db->id) {
$languageid = $db->id;
}
else {
$languageid = 7;
}
}
## If language wasn't passed in
elseif ($language != "all") {
## Get the user's preferred language if possible
if ($user) {
$query = "SELECT languageid FROM users WHERE uniqueid='$user' LIMIT 1";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$db = mysql_fetch_object($result);
if ($db->languageid) {
$languageid = $db->languageid;
}
else {
$languageid = 7;
}
}
else {
$languageid = 7;
}
}

## Run the query
include('../sphinxapi.php');
$cl = new SphinxClient();
$cl->SetServer( "localhost", 3312 );
$cl->SetMatchMode( SPH_MATCH_ALL );
$cl->SetLimits(0, 100);
$cl->SetSortMode ( SPH_SORT_EXTENDED, "@weight DESC, languageid ASC" );

if ($languageid) {
$cl->SetFilter('languageid', array( $languageid, 7 ));
$cl->SetSortMode ( SPH_SORT_EXTENDED, "@weight DESC, languageid DESC" );
}

$result = $cl->Query( "START_ " . $seriesname . " _END", 'seriesname', "seriesname");

if ( $result === false ) {
echo "Query failed: " . $cl->GetLastError() . ".\n";
}
else {
if ( !empty($result["matches"]) ) {
foreach ($result["matches"] AS $id => $junk) {

## Get base information
$subquery = "SELECT seriesid, languageid, (SELECT abbreviation FROM languages WHERE id=translation_seriesname.languageid) AS language, translation AS SeriesName FROM translation_seriesname WHERE id=$id";
$subresult = mysql_query($subquery) or die('Query failed: ' . mysql_error());
$db = mysql_fetch_object($subresult);
if (!$db->seriesid) {
continue;
}

## Get top banner
$subquery = "SELECT filename FROM banners WHERE keytype='series' AND keyvalue=$db->seriesid ORDER BY (SELECT AVG(rating) FROM ratings WHERE itemtype='banner' AND itemid=banners.id) DESC,RAND() LIMIT 1";
$subresult = mysql_query($subquery) or die('Query failed: ' . mysql_error());
if ($subdb = mysql_fetch_object($subresult)) {
$db->banner = $subdb->filename;
}

## Get additional information (overview)
$subquery = "SELECT translation FROM translation_seriesoverview WHERE seriesid=$db->seriesid AND (languageid=$db->languageid OR languageid=7) AND translation IS NOT NULL ORDER BY languageid DESC LIMIT 2";
$subresult = mysql_query($subquery) or die('Query failed: ' . mysql_error());
if ($subdb = mysql_fetch_object($subresult)) {
$db->Overview = $subdb->translation;
}

## Get additional information (FirstAired, network, IMDB_id, zap2it_id)
$subquery = "SELECT FirstAired, Network, IMDB_ID, zap2it_id FROM tvseries WHERE id=$db->seriesid LIMIT 1";
$subresult = mysql_query($subquery) or die('Query failed: ' . mysql_error());
if ($subdb = mysql_fetch_object($subresult)) {
if ($subdb->FirstAired) {
$db->FirstAired = $subdb->FirstAired;
}
if ($subdb->network) {
$db->Network = $subdb->network;
}
if ($subdb->IMDB_ID) {
$db->IMDB_ID = $subdb->IMDB_ID;
}
if ($subdb->zap2it_id) {
$db->zap2it_id = $subdb->zap2it_id;
}
}

## Remove fields
unset($db->languageid);

## Duplicate series id as id for posterity
$db->id = $db->seriesid;

## Start XML item
print "<Series>\n";

## Loop through each field for this item
foreach ($db as $key => $value) {

## Prepare the string for output
$value = xmlformat($value, $key);

## Print the string
print "<$key>$value</$key>\n";

}

## End XML item
print "</Series>\n";
}
}
}
?>
</Data>
69 changes: 69 additions & 0 deletions api/Updates.php
@@ -0,0 +1,69 @@
<?php ## Interface that returns all updates since a given time
## Parameters:
## $_REQUEST["time"]
## $_REQUEST["type"] [series(default)|episode|all]
##
## Returns:
## XML items for each series or episode that was updated since "time"

## Include functions, db connection, etc
include("include.php");
?>
<?php
## Prepare the search string
$time = $_REQUEST["time"];
$type = $_REQUEST["type"];
$actualtime = time();


## If type is none, just return the time
if ($type == "none") {
print "<Items>\n";
print "<Time>" . time() . "</Time>\n";
print "</Items>\n";
exit;
}


## Time is a required field
if ($time == "") {
print "<Error>Time is required</Error>\n";
exit;
}
## This interface only allows lookups within the last 30 days
elseif ($time - $actualtime > 2592000) {
print "<Error>Time is greater than 30 days. Please do a full download of all series.</Error>\n";
exit;
}
## Type can only be series, episode, all, or blank
elseif ($type != "series" && $type != "episode" && $type != "all" && $type != "") {
print "<Error>Unknown value for type</Error>\n";
exit;
}
## No errors, so we continue
else {
print "<Items>\n";
print "<Time>" . time() . "</Time>\n";
}


## Query for series (if desired)
if ($type == "series" || $type == "all" || $type == "") {
$query = "SELECT id FROM tvseries WHERE lastupdated>=$time LIMIT 1000";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
while ($db = mysql_fetch_object($result)) {
print "<Series>$db->id</Series>\n";
}
}


## Query for episodes (if desired)
if ($type == "episode" || $type == "all") {
$query = "SELECT id FROM tvepisodes WHERE lastupdated>=$time LIMIT 1000";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
while ($db = mysql_fetch_object($result)) {
print "<Episode>$db->id</Episode>\n";
}
}
?>
</Items>
86 changes: 86 additions & 0 deletions api/User_Favorites.php
@@ -0,0 +1,86 @@
<?php ## Interface that allows clients to add series to their favorites
## Parameters:
## $_REQUEST["accountid"]
## $_REQUEST["seriesid"]
## $_REQUEST["type"] (add|remove|null)
##
## Returns:
## Success

## Include functions, db connection, etc
include("include.php");
?>
<?php
## Prepare the search string
$accountid = $_REQUEST["accountid"];
$seriesid = $_REQUEST["seriesid"];
$type = $_REQUEST["type"];
if ($accountid == "") {
print "<Error>accountid is required</Error>\n";
exit;
}
elseif (($type == "add" || $type == "remove") && $seriesid == "") {
print "<Error>seriesid is required for adding and deleting</Error>\n";
exit;
}
else {
print "<Favorites>\n";
}


## Run the query
$query = "SELECT id, favorites FROM users WHERE uniqueid='$accountid' LIMIT 1";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$db = mysql_fetch_object($result);


## If we've found a valid user
if ($db->id) {
## Split their current favorites into an array, add new item,
## and rejoin list
$favorites = array();
if ($type == "remove") {
$temp = explode(",", $db->favorites);
foreach ($temp AS $id) {
if ($id != $seriesid) {
array_push($favorites, $id);
}
}
$favorites = array_unique($favorites);
$favoriteslist = implode(",", $favorites);

## Insert replacement value into database
$query = "UPDATE users SET favorites='$favoriteslist' WHERE id=$db->id";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

## Print new favorites list
foreach ($favorites AS $id) {
print "<Series>$id</Series>\n";
}
}
elseif ($type == "add") {
$favorites = explode(",", $db->favorites);
array_push($favorites, $seriesid);
$favorites = array_unique($favorites);
$favoriteslist = implode(",", $favorites);

## Insert replacement value into database
$query = "UPDATE users SET favorites='$favoriteslist' WHERE id=$db->id";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

## Print new favorites list
foreach ($favorites AS $id) {
print "<Series>$id</Series>\n";
}
}
else {
## Print new favorites list
$temp = explode(",", $db->favorites);
foreach ($temp AS $id) {
print "<Series>$id</Series>\n";
}
}

}
?>
</Favorites>

0 comments on commit 59ef9d4

Please sign in to comment.