MythWebRSS
From MythTV
This is a PHP file that you can add to the MythWeb folder to generate an RSS feed of the Previous Recordings page.
To get it to work
- Place the file rss.php in your MythWeb directory (with mythweb.php)
- Make sure your web browser can read it
- (Optional) Change the $MythWeb_Site variable (for the links in the feed to work)
- Point your feed reader to http://your.mythtv.host/mythweb/rss.php
Note:
- This script has been tested on 0.19. It may work on SVN as well. It will not work with 0.18.
- In order to get the dates to come out properly I had to change date('c', $show->starttime) into date('r', $show->starttime) below - ncw 2007-01-30
- In version 0.20.2 (fedora rpm) I had to allow rss.php to have access to the PHP vars in .htaccess. Change line 41 of .htacess to be:
<Files ~ "(mythweb|rss).*">
- In versoin 0.20.2 (Ubuntu Hardy Heron) I also had to change the include path in /etc/apache2/sites-available/mythweb.conf line 76
setenv include_path "/usr/share/mythtv/mythweb:/usr/share/mythtv/mythweb/modules/tv/:"
Additions:
- Add preview images to the feed. Modify the description line below to include the following:
$xml .= "<description>".htmlspecialchars("<img src=\"".$MythWeb_Site."data/cache/".basename($show->filename).".png"."\" />
".$show->description,ENT_QUOTES)."</description>\n";
[edit]
The PHP file: rss.php
<?
header('Content-type: application/xml');
// Constants
$List_Recordings = 20;
$MythWeb_Site = "http://your.mythtv.host/mythweb/";
// Which section are we in?
// define('section', 'tv');
// Initialize the script, database, etc.
require_once "includes/init.php";
require_once "includes/programs.php";
require_once "includes/sorting.php";
/* If you get errors like the following
Error at includes/css.php, line 34:
Invalid argument supplied for foreach()
you can override the errorhandler by uncommenting the following two lines */
// set_error_handler('errorHandlerTemp');
// function errorHandlerTemp() {}
// Parse the program list
$warning = NULL;
$recordings = get_backend_rows('QUERY_RECORDINGS Delete');
while (true) {
$Total_Used = 0;
$Total_Programs = 0;
$Programs = array();
$Groups = array();
$Program_Titles = array();
foreach ($recordings as $key => $record) {
// Skip the offset
if ($key === 'offset') // WHY IN THE WORLD DOES 0 == 'offset'?!?!? so we use ===
continue;
// Get the length (27 == recendts; 26 == recstartts)
$length = $record[27] - $record[26];
// keep track of their names and how many episodes we have recorded
$Total_Programs++;
$Groups[$record[30]]++;
// Hide LiveTV recordings from the title list
if (($_GET['recgroup'] && $_GET['recgroup'] == $record[30]) || (!$_GET['recgroup'] && $record[30] != 'LiveTV'))
$Program_Titles[$record[0]]++;
// Skip files with no chanid, or with zero length
if (!$record[4] || $length < 1)
continue;
// Hide livetv recordings from the default view
if (empty($_GET['recgroup']) && $record[30] == 'LiveTV')
continue;
// Make sure that everything we're dealing with is an array
if (!is_array($Programs[$record[0]]))
$Programs[$record[0]] = array();
// Assign a reference to this show to the various arrays
$Programs[$record[0]][] = $record;
}
// Did the best we could to find some programs; let's move on.
break;
}
// Now that we've selected only certain shows, load them into objects
$All_Shows = array();
foreach ($Programs as $title => $shows) {
foreach ($shows as $key => $record) {
// Create a new program object
$show =& new Program($record);
// Assign a reference to this show to the various arrays
$All_Shows[] =& $show;
$Programs[$title][$key] =& $show;
$Channels[$show->chanid]->programs[] =& $show;
unset($show);
}
}
// Sort the program titles
ksort($Program_Titles);
// The default sorting choice isn't so good for recorded programs, so we'll set our own default
if (!is_array($_SESSION['recorded_sortby']) || !count($_SESSION['recorded_sortby']))
$_SESSION['recorded_sortby'] = array(array('field' => 'airdate',
'reverse' => true),
array('field' => 'title',
'reverse' => false));
// Create the show listings
if (count($All_Shows)) {
// Sort the programs
sort_programs($All_Shows, 'recorded_sortby');
// Create the top section
$builddate = date("r", time());
$xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
$xml .= "<rss version=\"2.0\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n";
$xml .= "<channel>\n";
$xml .= "<title>MythTV Latest Recordings</title>\n";
$xml .= "<link>".$MythWeb_Site."</link>\n";
$xml .= "<description>List of the Last ".$List_Recordings." MythTV Recordings</description>\n";
$xml .= "<language>en-us</language>\n";
$xml .= "<lastBuildDate>{$builddate}</lastBuildDate>\n";
// Create the per-show listing
if (sizeof($All_Shows) > 0) {
$i = 1;
foreach ($All_Shows as $show) {
// Create the title from the show title and subtitle (if it exists)
if ($show->subtitle) $title = $show->title . ' (' . $show->subtitle . ')'; else $title = $show->title;
$xml .= "<item>\n";
$xml .= "<title>".htmlspecialchars($title,ENT_QUOTES)."</title>\n";
$xml .= "<link>".$MythWeb_Site."tv/recorded?title=".urlencode($show->title)."</link>\n";
$xml .= "<description>".htmlspecialchars($show->description,ENT_QUOTES)."</description>\n";
$xml .= "<pubDate>".htmlspecialchars(date('c', $show->starttime),ENT_QUOTES)."</pubDate>\n";
$xml .= "</item>\n";
if ($i++ >= $List_Recordings) break;
}
}
$xml .= "</channel>\n";
$xml .= "</rss>\n";
} else {
// No shows to list (error?)
$xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
$xml .= "<sitedata>";
$xml .= "<error>No recordings could be found</error>";
$xml .= "</sitedata>";
}
// Print the listing
print $xml;
?>
