/tmp/hongkong.xml
/usr/bin/mythfilldatabase --file 1 1 /tmp/hongkong.xml
make sure the filltv file is chmod +x
Quick hack to generate xmltv listings from TVxb style .ini files.
*/
// seriously it's this bad..
error_reporting(E_ALL & ~E_STRICT &~E_NOTICE);
if (!extension_loaded('mbstring')) {
dl('mbstring.so');
}
define ('QUOTE', '"');
class XML_Tv
{
var $config; // configuration array.
var $date; // date we are fetching
var $channels; // details on the channels.
function start($ini)
{
// load the ini file.
require_once 'JSON.php';
$j = new Services_JSON();
$conf = (array)($j->decode(file_get_contents($ini)));
//$conf = (array)json_decode(file_get_contents($ini));
//print_r($conf);
foreach($conf as $k=>$v) {
$conf[$k] = (array)$v;
}
$this->channels = $conf;
$this->config = $conf['global'];
unset($this->channels['global']);
//print_r($this->channels);
$this->date = time();
foreach($this->channels as $k=>$v) {
for ($i=0;$i< (isset($v['days']) ? $v['days'] : $conf['days']);$i++) {
$this->grabChannel($k,$i);
// break;
}
//break;
}
echo $this->toXML();
}
function grabChannel($k,$dayoffset)
{
$cinfo = $this->channels[$k];
//print_r($cinfo);
// exit;
$date = $this->date + ($dayoffset * 24 * 60 * 60 );
$url = strftime( $cinfo['url'], $date);
$this->debug($url );
//echo "GET $url\n";
$data = @file_get_contents($url);
if (empty($data)) {
$this->debug("NO DATA");
// something went wrong..
return;
}
$odata = $data;
$map = array(
array("0x22", "0x09", "0x0a"),
array('"', "\t", "\n")
);
$hs = $cinfo['htmlstart'] === false ? false : str_replace($map[0],$map[1],$cinfo['htmlstart']);
//echo $hs;
$he= str_replace($map[0],$map[1],$cinfo['htmlend']);
//echo $he;
if ($hs !== false) {
list( , $data) = explode($hs,$data);
}
if (!empty($he)) {
list($data,) = explode($he ,$data);
}
//$this->debug("DATA:".$data);
$method = 'parse'.$cinfo['htmlparsetype'];
$chid = isset($cinfo['id']) ? $cinfo['id'] : $k;
// for multiday html layout of atv:
if (!empty($cinfo['htmldaysep'])) {
$days = explode($cinfo['htmldaysep'], $data);
// kludge. = first monday of current week..
// loook for...
2007-12-31 Mon
$start = preg_match('/
([0-9]{4}-[0-9]{2}-[0-9]{2}) Mon/i', $odata, $matches);
$start = isset($matches[1]) ? $matches[1] : 0; // first monday..
$use_cols = 1;
foreach($days as $i=>$ddata) {
$cols = explode(',',$cinfo['htmlcols']);
$dn = strtotime($start) + (($i * $use_cols) * 24 * 60 * 60 );
$res = $this->$method($ddata,$cols,date('Y-m-d',$dn));
if (is_string($res)) {
$start = $res;
$use_cols =0;
continue;
}
if (!is_array($res)) {
continue;
}
$day_id = strtotime($start) + (($i * $use_cols ) * 24 * 60 * 60 );
//print_r($res);
if (empty($this->schedule[$chid][$day_id])) {
$this->schedule[$chid][$day_id] = array();
}
$this->schedule[$chid][$day_id] = array_merge($this->schedule[$chid][$day_id], $res);
}
return;
}
$cols = explode(',',$cinfo['htmlcols']);
//print_r(array($data,$cols));
$this->schedule[$k][$this->date + ($dayoffset * 24 * 60 * 60 )] = $this->$method($data,$cols);
//print_r($this->schedule);
}
//tvb +???
function parseTable($data,$colnames)
{
$rows = preg_split('/
]*>/i', $r);
$rdata = array();
if (!isset($cols[2])) {
continue;
}
//PRINT_r($cols);
$c= $cols[2];
//var_dump($c);
// look for time..
if (!preg_match('/^[0-9]+:[0-9]+/', $c)) {
continue;
}
//$this->debug("GOT HOUR: $c");
$rdata['hour'] = trim(array_shift(explode('<', $c)));
$c = $cols[3];
$kv = preg_split('/ /',$c); $c = $kv[0]; $c = str_ireplace(' ',' ', $c); $c = str_ireplace(' ',' ', $c); $c = str_replace("\n",' ', $c); $c = str_replace("\r",' ', $c); $c = preg_replace('/\<[^>]+\>/', ' ', $c); $rdata['description2'] = trim($c); $c = isset($kv[1]) ? $kv[1] : ''; $c = str_ireplace(' ',' ', $c); $c = str_ireplace(' ',' ', $c); $c = str_replace("\n",' ', $c); $c = str_replace("\r",' ', $c); $c = preg_replace('/\<[^>]+\>/', ' ', $c); $rdata['description'] = trim($c); $rdata['day'] = $day; //print_R($rdata); $ret[] = $rdata; } //print_r($ret); exit; return $ret; } /* function parseTableCells($data,$colnames, $day) { $rows = preg_split('/ |
]*>/i', $r);
$rdata = array();
$c= $cols[1];
//var_dump($c);
// look for time..
if (!preg_match('/^[0-9]+:[0-9]+\s/', $c)) {
continue;
}
$c = str_ireplace(' ',' ', $c); $c = str_ireplace(' ',' ', $c); $c = str_replace("\n",' ', $c); $c = str_replace("\r",' ', $c); $c = preg_replace('/\<[^>]+\>/', ' ', $c); $c = trim($c); $kv = preg_split("/\s+/", $c, 2); $rdata[$colnames[0]] = trim($kv[0]); $rdata[$colnames[1]] = trim($kv[1]); //print_r($kv); if (count(array_values($rdata)) != count(array_values($colnames))) { continue; } $rdata['day'] = $day; $ret[] = $rdata; } //print_r($ret); return $ret; } */ /* |