Assembla home | Assembla project page
 

Changeset 1006

Show
Ignore:
Timestamp:
06/28/08 21:26:25 (5 months ago)
Author:
Pernod
Message:

Improved the TVDB parser to alternatively use unzip on linux systems which don't have the PHP zip extenstion installed. Synology systems are also detected and will download non-zipped data.

Fixes #151

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/swisscenter/base/server.php

    r820 r1006  
    2323  function is_unix() 
    2424  { return get_os_type() == "UNIX"; }  
     25   
     26  function is_synology() 
     27  {  
     28    // Have we already done the Sybology test? 
     29    if (! isset($_SESSION["Synology"]) ) 
     30    { 
     31      if ( preg_match('/phpinfo/', ini_get('disable_functions')) == 0) 
     32      { 
     33        // Is phpinfo() available for us to use? 
     34        ob_start(); 
     35        phpinfo(8); 
     36        $info = ob_get_contents(); 
     37        ob_end_clean(); 
     38        $_SESSION["Synology"] = !(stristr($info, 'synology') === false); 
     39      } 
     40      else 
     41      { 
     42        $_SESSION["Synology"] = ($_SERVER["SERVER_NAME"] == "synology"); 
     43      } 
     44    } 
     45    return $_SESSION["Synology"]; 
     46  } 
    2547   
    2648  // ---------------------------------------------------------------------------------- 
  • trunk/swisscenter/ext/parsers/tv/www.TheTVDB.com.php

    r1000 r1006  
    2424   31-Mar-2008: v1.1:     Fixed episode year and now informs user if episode details are not found. 
    2525   23-Apr-2008: v1.2:     Fixed downloading of series 0 (Special) banners. 
     26   25-Jun-2008: v1.3:     Improved zip support on Linux installations. 
    2627 
    2728 *************************************************************************************************/ 
     
    7576      global $tvdb_series, $tvdb_episodes, $tvdb_banners; 
    7677 
    77       $series_url       = $xmlmirror.'/api/FA3F6F720A61DE71/series/'.$series_id.'/all/'.$language.'.zip'; 
     78      $series_zip_url   = $xmlmirror.'/api/FA3F6F720A61DE71/series/'.$series_id.'/all/'.$language.'.zip'; 
     79      $series_xml_url   = $xmlmirror.'/api/FA3F6F720A61DE71/series/'.$series_id.'/all/'.$language.'.xml'; 
     80      $banner_xml_url   = $xmlmirror.'/api/FA3F6F720A61DE71/series/'.$series_id.'/banners.xml'; 
    7881      $series_zip_cache = $cache_dir.'/'.$series_id.'_'.$language.'.zip'; 
    7982      $series_cache     = $cache_dir.'/'.$series_id.'_'.$language.'.xml'; 
     
    8184       
    8285      // Ensure local copy of full series zip is uptodate (cache valid for 6 hours) 
    83       $series_cache_time  = (file_exists($series_zip_cache) ? filemtime($series_zip_cache) : 0); 
     86      $series_cache_time  = (file_exists($series_cache) ? filemtime($series_cache) : 0); 
    8487      if ($series_cache_time < (time() - 21600)) 
    8588      { 
    86         send_to_log(4,'Downloading remote file to the local filesystem',$series_url); 
    87         if (!@copy($series_url, $series_zip_cache)) 
    88           send_to_log(6,'Failed to copy remote file to',$series_zip_cache); 
    89         // Extract zip contents 
    90         $zip = @zip_open($series_zip_cache); 
    91         if (is_resource($zip)) 
    92         { 
    93           while ($zip_entry = zip_read($zip))  
     89        if (is_synology()) 
     90        { 
     91          // Synology has no zip support so download non-zipped data 
     92          send_to_log(4,'Downloading remote file to the local filesystem',$series_xml_url); 
     93          if (!@copy($series_xml_url, $series_cache)) 
     94            send_to_log(6,'Failed to copy remote file to',$series_cache); 
     95          send_to_log(4,'Downloading remote file to the local filesystem',$banner_xml_url); 
     96          if (!@copy($banner_xml_url, $banner_cache)) 
     97            send_to_log(6,'Failed to copy remote file to',$banner_cache); 
     98        } 
     99        else 
     100        { 
     101          send_to_log(4,'Downloading remote file to the local filesystem',$series_url); 
     102          if (!@copy($series_url, $series_zip_cache)) 
     103            send_to_log(6,'Failed to copy remote file to',$series_zip_cache); 
     104          else 
    94105          { 
    95             // Get file contents from zip 
    96             $entry = zip_entry_open($zip,$zip_entry); 
    97             $zfilename = zip_entry_name($zip_entry); 
    98             $zfilesize = zip_entry_filesize($zip_entry); 
    99             $zcontents = zip_entry_read($zip_entry, $zfilesize); 
    100             $fp=@fopen($cache_dir.'/'.$series_id.'_'.$zfilename,"w"); 
    101             @fwrite($fp,$zcontents); 
    102             @fclose($fp); 
    103             zip_entry_close($zip_entry); 
     106            // Extract zip contents 
     107            if ( extension_loaded('zip') && is_resource($zip = @zip_open($series_zip_cache)) ) 
     108            { 
     109              while ($zip_entry = zip_read($zip))  
     110              { 
     111                // Get file contents from zip 
     112                $entry = zip_entry_open($zip,$zip_entry); 
     113                $zfilename = zip_entry_name($zip_entry); 
     114                $zfilesize = zip_entry_filesize($zip_entry); 
     115                $zcontents = zip_entry_read($zip_entry, $zfilesize); 
     116                $fp=@fopen($cache_dir.'/'.$series_id.'_'.$zfilename,"w"); 
     117                @fwrite($fp,$zcontents); 
     118                @fclose($fp); 
     119                zip_entry_close($zip_entry); 
     120              } 
     121              @zip_close($zip); 
     122            } 
     123            elseif (is_unix()) 
     124            { 
     125              // On LINUX machines, we can use the standard "unzip" command to  
     126              // perform the same functions as the zip extension 
     127              exec('unzip '.$series_zip_cache.' -d '.$cache_dir); 
     128            } 
     129            else 
     130            { 
     131              send_to_log(6,"Failed to open series zip from www.thetvdb.com. (zip_open errno=$zip)"); 
     132            } 
    104133          } 
    105134        } 
    106         else 
    107         { 
    108           send_to_log(6,"Failed to open series zip from www.thetvdb.com. (zip_open errno=$zip)"); 
    109         } 
    110         @zip_close($zip); 
    111135      } 
    112136