PageRenderTime 47ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/library/imdb/imdb_trailers.class.php

https://github.com/hegylako/openTracker
PHP | 195 lines | 145 code | 7 blank | 43 comment | 10 complexity | 45865a3f4ae8a76d73ce9a401c3e3628 MD5 | raw file
Possible License(s): MIT
  1. <?php
  2. #############################################################################
  3. # IMDBPHP (c) Giorgos Giagas & Itzchak Rehberg #
  4. # written by Giorgos Giagas #
  5. # extended & maintained by Itzchak Rehberg <izzysoft AT qumran DOT org> #
  6. # http://www.izzysoft.de/ #
  7. # ------------------------------------------------------------------------- #
  8. # IMDBPHP TRAILERS (c) Ricardo Silva #
  9. # written by Ricardo Silva (banzap) <banzap@gmail.com> #
  10. # http://www.ricardosilva.pt.tl/ #
  11. # rewritten and extended by Itzchak Rehberg <izzysoft AT qumran DOT org> #
  12. # ------------------------------------------------------------------------- #
  13. # This program is free software; you can redistribute and/or modify it #
  14. # under the terms of the GNU General Public License (see doc/LICENSE) #
  15. #############################################################################
  16. # $Id: imdb_trailers.class.php 357 2010-03-16 22:01:11Z izzy $
  17. require_once (dirname(__FILE__)."/imdb.class.php");
  18. #=================================================[ The IMDB Charts class ]===
  19. /** Obtaining the URL of the trailer Flash Movie
  20. * @package openTracker
  21. * @class imdb_trailers
  22. * @author Ricardo Silva (banzap) <banzap@gmail.com>
  23. * @version $Revision: 357 $ $Date: 2010-03-16 23:01:11 +0100 (Di, 16. M채r 2010) $
  24. */
  25. class imdb_trailers {
  26. var $page = "";
  27. var $moviemazeurl = "http://www.moviemaze.de";
  28. var $alltrailersurl = "http://www.alltrailers.net";
  29. var $latemagurl = "http://latemag.com";
  30. var $moviemazeflashplayer = "/media/trailer/flash/player.swf";
  31. var $latemagflashplayer = "/files/mediaplayer.swf";
  32. var $moviemazefilesyntax = "file=";
  33. var $latemagfilesyntax = "file=";
  34. /** Constructor: Nothing (yet)
  35. * @constructor imdb_trailers
  36. */
  37. function imdb_trailers(){
  38. $this->revision = preg_replace('|^.*?(\d+).*$|','$1','$Revision: 357 $');
  39. }
  40. /** Retrieve trailer URLs from moviemaze.de
  41. * @method getFlashCodeMovieMaze
  42. * @param string url trailer url as retrieved with imdb::videosites
  43. * @brief the URL of the trailer in http://www.moviemaze.de, this URL its obtained from the IMDB class, using the trailer function.
  44. * @return array [0..n] of array[url,format] of movie trailers (Flash or Quicktime)
  45. */
  46. function getFlashCodeMovieMaze($url){
  47. $req = new MDB_Request($url);
  48. $req->sendRequest();
  49. $this->page=$req->getResponseBody();
  50. if($this->page=="" || $this->page==false) return false;
  51. preg_match_all('/<a href="([^\"]*)\.(flv|mov)"/iUms',$this->page,$matches);
  52. $mc = count($matches[0]);
  53. for ($i=0;$i<$mc;++$i) {
  54. if ( strpos($matches[1][$i],"http://")===0 ) $list[] = array("url"=>$matches[1][$i].".".$matches[2][$i],"format"=>$matches[2][$i]);
  55. else $list[] = array("url"=>$this->moviemazeurl.$matches[1][$i].".".$matches[2][$i],"format"=>$matches[2][$i]);
  56. }
  57. return $list;
  58. }
  59. /** Retrieve trailers from alltrailers.net
  60. * @method getFlashCodeAllTrailers
  61. * @param string url page url as retrieved with imdb::videosites
  62. * @brief the URL of the trailer in http://www.alltrailers.net, this URL its obtained from the IMDB class, using the trailer function.
  63. * @return array [0..n] of array[url,format] of movie trailers (Flash)
  64. */
  65. function getFlashCodeAllTrailers($url){
  66. if (strpos($url,"http://alltrailers")!==FALSE) $url = str_replace("http://","http://www.",$url);
  67. $req = new MDB_Request($url);
  68. $req->sendRequest();
  69. $pattern = "'";
  70. $this->page=$req->getResponseBody();
  71. if($this->page=="" || $this->page==false) return false;
  72. preg_match_all('|<embed .* src="([^\"]*)"|iUms',$this->page,$matches);
  73. $mc = count($matches[1]);
  74. for ($i=0;$i<$mc;++$i) {
  75. if (strpos($matches[1][$i],"http://")===0) $list[$i] = array("url"=>$matches[1][$i],"format"=>"flv");
  76. else $list[$i] = array("url"=>$this->alltrailersurl.$matches[1][$i],"format"=>"flv");
  77. }
  78. return $list;
  79. }
  80. /** Retrieve trailers from IMDB site
  81. * @method getImdbTrailers
  82. * @param string url page url as retrieved with imdb::videosites
  83. * @return array [0..n] of array[url,format] of movie trailers (Flash)
  84. */
  85. function getImdbTrailers($url) {
  86. $url = str_replace("rg/VIDEO_TITLE/GALLERY/","",$url)."player";
  87. $req = new MDB_Request($url);
  88. $req->sendRequest();
  89. $this->page=$req->getResponseBody();
  90. if($this->page=="" || $this->page==false) return false;
  91. preg_match('|so\.addVariable\("file",\s*"(http.*)"|iUms',$this->page,$match);
  92. $url = urldecode($match[1]);
  93. preg_match('|type\=\.(.{3})|i',$url,$format);
  94. if (!empty($url)) return array( array("url"=>$url,"format"=>$format[1]) );
  95. }
  96. /** Retrieve trailers from movieplayer.it (Italian)
  97. * @method getMoviePlayerTrailers
  98. * @param string url page url as retrieved with imdb::videosites
  99. * @return array [0..n] of array[url,format] of movie trailers (Flash)
  100. */
  101. function getMoviePlayerTrailers($url) {
  102. $req = new MDB_Request($url);
  103. $req->sendRequest();
  104. $this->page=$req->getResponseBody();
  105. if($this->page=="" || $this->page==false) return false;
  106. preg_match('|s1\.addVariable\("file",\s*"(http.*)"|iUms',$this->page,$match);
  107. preg_match('|\.(.{3})$|i',$match[1],$format);
  108. if (!empty($match[1])) return array( array("url"=>$match[1],"format"=>$format[1]) );
  109. }
  110. /** Retrieve trailers from azmovietrailers.com
  111. * @method getAZMovieTrailers
  112. * @param string url page url as retrieved with imdb::videosites
  113. * @return array [0..n] of array[url,format] of movie trailers (Flash)
  114. */
  115. function getAZMovieTrailers($url) {
  116. $req = new MDB_Request($url);
  117. $req->sendRequest();
  118. $this->page=$req->getResponseBody();
  119. if($this->page=="" || $this->page==false) return false;
  120. preg_match('|flashvars\="file\=(http.*)\&|iUms',$this->page,$match);
  121. preg_match('|\.(.{3})$|i',$match[1],$format);
  122. if (!empty($match[1])) return array( array("url"=>$match[1],"format"=>$format[1]) );
  123. }
  124. /** Retrieve trailers from youtube
  125. * @method getYoutubeTrailers
  126. * @param string url
  127. * @return array [0..n] of array[url,format] of movie trailers
  128. */
  129. function getYoutubeTrailers($url) {
  130. $videoid = preg_replace('|.*v=(.*)|','\\1',$url);
  131. parse_str(file_get_contents("http://youtube.com/get_video_info?video_id={$videoid}"),$i);
  132. if($i['status'] == 'fail' && $i['errorcode'] == '150') {
  133. $content = file_get_contents("http://www.youtube.com/watch?v={$videoid}");
  134. preg_match_all ("/(\\{.*?\\})/is", $content, $matches);
  135. $obj = json_decode($matches[0][1]);
  136. $token = $obj->{'t'};
  137. $fmt_url_map = $obj->{'fmt_url_map'};
  138. } elseif ($i['status'] == 'fail' && $i['errorcode'] != '150') {
  139. return false;
  140. } else {
  141. $token = $i['token'];
  142. $fmt_url_map = $i['fmt_url_map'];
  143. }
  144. $url = "http://www.youtube.com/get_video.php?video_id={$videoid}&vq=2&fmt={$fmt}&t={$token}";
  145. $headers = get_headers($url,1);
  146. $video = $headers['Location'];
  147. if(!isset($video)) {
  148. preg_match ("/((?:http|https)(?::\\/{2}[\\w]+)(?:[\\/|\\.]?)(?:[^\\s\"]*))/is", $fmt_url_map, $matches);
  149. $video = explode(',', $matches[0]); $video = $video[0];
  150. }
  151. #some times array?
  152. if (is_array($video)) return array("url"=>$video[0],"format"=>"flv");
  153. else return array("url"=>$video,"format"=>"flv");
  154. }
  155. /** Get all possible trailers
  156. * @method getAllTrailers
  157. * @param string mid IMDB ID
  158. * @return array [0..n] of array[url,format] of movie trailers
  159. */
  160. function getAllTrailers($mid) {
  161. $movie = new imdb($mid);
  162. $arraytrailers = $movie->videosites();
  163. $list = array();
  164. foreach ($arraytrailers as $trail) {
  165. unset($tl);
  166. $tmp = strtolower($trail['url']);
  167. if ( strpos($tmp,"www.moviemaze.de")!==FALSE )
  168. $tl = $this->getFlashCodeMovieMaze($trail['url']);
  169. elseif ( strpos($tmp,"alltrailers.net")!==FALSE)
  170. $tl = $this->getFlashCodeAllTrailers($trail['url']);
  171. elseif ( strpos($url,"imdb.com/rg/VIDEO_TITLE/GALLERY")!==FALSE )
  172. $tl = $this->getImdbTrailers($trail['url']);
  173. elseif ( strpos($tmp,"www.movieplayer.it")!==FALSE )
  174. $tl = $this->getMoviePlayerTrailers($trail['url']);
  175. elseif ( strpos($tmp,"azmovietrailers.com")!==FALSE)
  176. $tl = $this->getAZMovieTrailers($trail['url']);
  177. elseif ( strpos($tmp,"youtube.com")!==FALSE)
  178. $tl = $this->getYoutubeTrailers($trail['url']);
  179. if ( isset($tl) ) $list = array_merge($list,$tl);
  180. }
  181. return $list;
  182. }
  183. } // end class imdb_trailers
  184. ?>