Tv.php
[lib.XML_Tv] / Tv.php
diff --git a/Tv.php b/Tv.php
index 7bfa68b..84dc4da 100644 (file)
--- a/Tv.php
+++ b/Tv.php
@@ -14,6 +14,10 @@ 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')) {
@@ -113,7 +117,7 @@ class XML_Tv
             // kludge. = first monday of current week..
             // loook for... <BR>2007-12-31 Mon
             $start = preg_match('/<BR>([0-9]{4}-[0-9]{2}-[0-9]{2}) Mon/i', $odata, $matches);
-            $start = isset($matches[1]) ? 0; // first monday..
+            $start = isset($matches[1]) ? $matches[1] : 0; // first monday..
             
             $use_cols = 1;
             foreach($days as $i=>$ddata) {
@@ -125,10 +129,20 @@ class XML_Tv
                 $res =  $this->$method($ddata,$cols,date('Y-m-d',$dn));
                 if (is_string($res)) {
                     $start = $res;
-                     $use_cols =0;
+                    $use_cols =0;
+                    continue;
+                }
+                if (!is_array($res)) {
                     continue;
                 }
-                $this->schedule[$chid][strtotime($start) + (($i *  $use_cols ) * 24 * 60 * 60 )]  = $res;
+                $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;
             
@@ -190,7 +204,7 @@ class XML_Tv
     
     }
     
-    function parseJade($data, $colnames)
+    function parseJade($data, $colnames, $day=0)
     {
         
         $rows = preg_split('#</li>#i', $data);
@@ -200,7 +214,7 @@ class XML_Tv
             $r = str_ireplace('&nbsp;',' ', $r);
             $rdata = array();
             
-            list($time,$r) = explode('</span>', $r, 2);
+            @list($time,$r) = explode('</span>', $r, 2);
             
             $rdata['hour'] = trim(strip_tags($time));
             if (!strlen($rdata['hour'])) {
@@ -226,9 +240,11 @@ class XML_Tv
         $lines = explode("\n",  trim($data));
         //var_dump($lines[1]);
         
-        if (preg_match('/<div/', trim($lines[1]))) {
+        
+        if (isset($lines[1]) && preg_match('/<div/', trim($lines[1]))) {
             
             preg_match('/<BR>([0-9]{4}-[0-9]{2}-[0-9]{2})/i', $lines[1], $matches);
+            //var_dump($matches[1]);
             return $matches[1];
             
         }
@@ -237,6 +253,7 @@ class XML_Tv
             //$this->debug(print_r($rows,true));
         }
         if ($day < date('Y-m-d')) {
+           // $this->debug("OLD DATA  $day");
             return array();
         }
         //$this->debug($day);
@@ -244,10 +261,10 @@ class XML_Tv
     //return; 
         array_shift($rows);
         
-        
-        $day = false;
+        $ret = array();
+        //$day = false;
         foreach($rows as $r) {
-            print_r($r);
+            //print_r($r);
             $cols = preg_split('/<td[^>]*>/i', $r);
             $rdata = array();
             
@@ -277,7 +294,7 @@ class XML_Tv
             
             
             
-            $c = $kv[1];
+            $c = isset($kv[1]) ? $kv[1] : ''; 
             $c = str_ireplace('<br>',' ', $c);
             $c = str_ireplace('&nbsp;',' ', $c);
             $c = str_replace("\n",' ', $c);
@@ -289,7 +306,7 @@ class XML_Tv
             $rdata['day'] = $day;
             
             
-            print_R($rdata);
+            //print_R($rdata);
             $ret[] = $rdata;
         }
         //print_r($ret); exit;
@@ -496,7 +513,7 @@ class XML_Tv
     {
         // remove sponsor message.
         $title_pre = '';
-        list($title, $fuldesc) = explode("&gt;&gt;",$description);
+        @list($title, $fuldesc) = explode("&gt;&gt;",$description);