@@ -245,6 +245,11 @@ public function getSerieEpisodes($serieId, $language = null, $format = self::FOR
245245 $ data = $ this ->fetchXml ('series/ ' . $ serieId . '/all/ ' . $ language . '. ' . $ format );
246246 break ;
247247 case self ::FORMAT_ZIP :
248+ if (!in_array ('zip ' , stream_get_wrappers ())) {
249+ throw new \ErrorException ('Your PHP does nort support ZIP stream wrappers ' );
250+ }
251+ $ data = $ this ->fetchZIP ('series/ ' . $ serieId . '/all/ ' . $ language . '. ' . $ format , array (), self ::GET , $ language .".xml " );
252+ break ;
248253 default :
249254 throw new \ErrorException ('Unsupported format ' );
250255 break ;
@@ -351,6 +356,39 @@ protected function fetchXml($function, $params = array(), $method = self::GET)
351356 return $ simpleXml ;
352357 }
353358
359+ /**
360+ * Fetches data via curl and returns result
361+ *
362+ * @access protected
363+ * @param string $function The function used to fetch data in zip
364+ * @param array $params
365+ * @param string $method
366+ * @param string $file The file to extract from the ZIP
367+ * @return string The data
368+ */
369+ protected function fetchZIP ($ function , $ params = array (), $ method = self ::GET , $ file =null )
370+ {
371+ if (strpos ($ function , '.php ' ) > 0 ) { // no need of api key for php calls
372+ $ url = $ this ->getMirror (self ::MIRROR_TYPE_ZIP ) . '/api/ ' . $ function ;
373+ } else {
374+ $ url = $ this ->getMirror (self ::MIRROR_TYPE_ZIP ) . '/api/ ' . $ this ->apiKey . '/ ' . $ function ;
375+ }
376+
377+ $ zipName = tempnam (sys_get_temp_dir (), "tvdb- " );
378+ $ zip = fopen ($ zipName , "w " );
379+ fwrite ($ zip , $ this ->httpClient ->fetch ($ url , $ params , $ method ));
380+ fclose ($ zip );
381+ if (is_null ($ file )) {
382+ $ file = $ this ->getDefaultLanguage ().".xml " ;
383+ }
384+ $ dataPath = "zip:// " .$ zipName ."# " .$ file ;
385+ $ data = file_get_contents ($ dataPath );
386+
387+ $ simpleXml = $ this ->getXml ($ data );
388+
389+ return $ simpleXml ;
390+ }
391+
354392 /**
355393 * Fetch data with curl
356394 *
@@ -391,7 +429,7 @@ protected function getXml($data)
391429 throw new XmlException (implode ("\n" , $ errors ));
392430 }
393431 }
394- throw new XmlException ('Xml file cound not be loaded ' );
432+ throw new XmlException ('Xml file could not be loaded ' );
395433 }
396434
397435 return $ simpleXml ;
0 commit comments