1
0

isoHuntEngine.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. <?php
  2. /* $Id: isoHuntEngine.php 3311 2007-12-23 01:39:01Z munk $ */
  3. /*************************************************************
  4. * TorrentFlux PHP Torrent Manager
  5. * www.torrentflux.com
  6. **************************************************************/
  7. /*
  8. This file is part of TorrentFlux.
  9. TorrentFlux is free software; you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation; either version 2 of the License, or
  12. (at your option) any later version.
  13. TorrentFlux is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. GNU General Public License for more details.
  17. You should have received a copy of the GNU General Public License
  18. along with TorrentFlux; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. /*
  22. v 1.05 - Oct 07, 06 - updated parseing
  23. v 1.04 - Sep 20, 06 - updated by batmark
  24. v 1.03 - Aug 23, 06 - fix ISOHunt fixed search results to display externals.
  25. v 1.02 - Aug 23, 06 - fix ISOHunt changed there site alittle.
  26. v 1.01 - Jun 30, 06 - fix to Search..
  27. */
  28. class SearchEngine extends SearchEngineBase
  29. {
  30. function SearchEngine($cfg)
  31. {
  32. $this->mainURL = "isohunt.com";
  33. $this->altURL = "isohunt.com";
  34. $this->mainTitle = "isoHunt";
  35. $this->engineName = "isoHunt";
  36. $this->author = "kboy";
  37. $this->version = "1.05-tfb";
  38. $this->updateURL = "http://www.torrentflux.com/forum/index.php/topic,878.0.html";
  39. $this->Initialize($cfg);
  40. }
  41. //----------------------------------------------------------------
  42. // Function to Make the Request (overriding base)
  43. function makeRequest($request)
  44. {
  45. return parent::makeRequest($request, true);
  46. }
  47. //----------------------------------------------------------------
  48. // Function to get Latest..
  49. function getLatest()
  50. {
  51. $request = "/latest.php?mode=bt";
  52. if (!empty($this->pg))
  53. {
  54. $request .= "&pg=" . $this->pg;
  55. }
  56. if ($this->makeRequest($request))
  57. {
  58. return $this->parseResponse(true);
  59. }
  60. else
  61. {
  62. return $this->msg;
  63. }
  64. }
  65. //----------------------------------------------------------------
  66. // Function to perform Search.
  67. function performSearch($searchTerm)
  68. {
  69. // This is what isohunt is looking for in a request.
  70. // http://isohunt.com/torrents.php?ihq=test&ext=&op=and
  71. // create the request string.
  72. $searchTerm = str_replace(" ", "+", $searchTerm);
  73. $request = "/torrents?ihq=".$searchTerm;
  74. //$request .= "&ext=&op=and";
  75. if (!empty($this->pg))
  76. {
  77. $request .= "&ihs1=18&iho1=d&iht=-1&ihp=" . $this->pg;
  78. }
  79. // make the request if successful call the parse routine.
  80. if ($this->makeRequest($request))
  81. {
  82. return $this->parseResponse(false);
  83. }
  84. else
  85. {
  86. return $this->msg;
  87. }
  88. }
  89. //----------------------------------------------------------------
  90. // Function to parse the response.
  91. function parseResponse($latest = true)
  92. {
  93. $output = $this->tableHeader();
  94. $thing = $this->htmlPage;
  95. // Strip out those Nasty Iframes.
  96. $thing = preg_replace("/<table[[:space:]]width=[[:punct:]]100%[[:punct:]][[:space:]]cellspacing=[[:punct:]]0[[:punct:]][[:space:]]cellpadding=[[:punct:]]0[[:punct:]][[:space:]]border=[[:punct:]]0[[:punct:]]><tr><td[[:space:]]width=[[:punct:]]10[[:punct:]]></td><td[[:space:]]style=[[:punct:]]border[[:punct:]]3px[[:space:]]solid[[:space:]]#003366[[:punct:]]><iframe[[:space:]]frameborder=[[:punct:]]0[[:punct:]][[:space:]]width=[[:punct:]]100%[[:punct:]][[:space:]]id=[[:punct:]]([a-zA-Z0-9])*[[:punct:]]></iframe></td></tr></table>/i",'',$thing);
  97. // We got a response so display it.
  98. // Chop the front end off.
  99. if ($latest)
  100. {
  101. $start = strpos($thing, "New torrents on isoHunt");
  102. } else {
  103. $start = strpos($thing, "isoHunt Rank");
  104. }
  105. $thing = substr($thing, $start, strlen($thing) - $start);
  106. if ($latest)
  107. {
  108. $end = strrpos($thing, "adclick");
  109. } else {
  110. $end = strrpos($thing, "»");
  111. }
  112. $tmpList = $thing;
  113. //echo $tmpList;
  114. if (strpos($tmpList,"/download/") || strpos($tmpList,"torrent_details"))
  115. {
  116. // ok so now we have the listing.
  117. $tmpListArr = explode("</tr>",$tmpList);
  118. array_pop($tmpListArr);
  119. $bg = $this->cfg["bgLight"];
  120. foreach($tmpListArr as $key =>$value)
  121. {
  122. //echo $value;
  123. $buildLine = true;
  124. if (strpos($value,"/download/") || strpos($value,"torrent_details"))
  125. {
  126. $ts = new isoHunt($value,$latest);
  127. // Determine if we should build this output
  128. if (is_int(array_search($ts->CatName,$this->catFilter)))
  129. {
  130. $buildLine = false;
  131. }
  132. if ($this->hideSeedless == "yes")
  133. {
  134. if($ts->Seeds == "N/A" || $ts->Seeds == "0")
  135. {
  136. $buildLine = false;
  137. }
  138. }
  139. if (!empty($ts->torrentFile) && $buildLine) {
  140. $output .= trim($ts->BuildOutput($bg));
  141. // ok switch colors.
  142. if ($bg == $this->cfg["bgLight"])
  143. {
  144. $bg = $this->cfg["bgDark"];
  145. }
  146. else
  147. {
  148. $bg = $this->cfg["bgLight"];
  149. }
  150. }
  151. }
  152. }
  153. // set thing to end of this table.
  154. $thing = substr($thing,strpos($thing,"</table>"));
  155. if (!is_integer(strpos($thing,"name=ihLogin")))
  156. {
  157. $thing = "";
  158. }
  159. }
  160. $output .= "</table>";
  161. // is there paging at the bottom?
  162. if (strpos($this->htmlPage, "<table class='pager'>") != false)
  163. {
  164. // Yes, then lets grab it and display it! ;)
  165. $thing = substr($this->htmlPage,strpos($this->htmlPage,"<table class='pager'>")+strlen("<table class='pager'>"));
  166. $pages = substr($thing,0,strpos($thing,"</table>"));
  167. $pages = str_replace("&nbsp; ",'',strip_tags($pages,"<a><b>"));
  168. $tmpPageArr = explode("</a>",$pages);
  169. array_pop($tmpPageArr);
  170. $pagesout = '';
  171. foreach($tmpPageArr as $key => $value)
  172. {
  173. $value .= "</a> &nbsp;";
  174. $tmpVal = substr($value,strpos($value,"/torrents/"),strpos($value,"\>")-1);
  175. $pgNum = substr($tmpVal,strpos($tmpVal,"ihp=")+strlen("ihp="));
  176. $pagesout .= str_replace($tmpVal,"XXXURLXXX".$pgNum,$value);
  177. }
  178. if(strpos($this->curRequest,"LATEST"))
  179. {
  180. $pages = str_replace("XXXURLXXX",$this->searchURL()."&LATEST=1&pg=",$pagesout);
  181. }
  182. else
  183. {
  184. $pages = str_replace("XXXURLXXX",$this->searchURL()."&searchterm=".$_REQUEST["searchterm"]."&pg=",$pagesout);
  185. }
  186. $pages = strip_tags($pages,"<a><b>");
  187. $output .= "<div align=center>".$pages."</div>";
  188. }
  189. return $output;
  190. }
  191. }
  192. // This is a worker class that takes in a row in a table and parses it.
  193. class isoHunt
  194. {
  195. var $torrentName = "";
  196. var $torrentDisplayName = "";
  197. var $torrentFile = "";
  198. var $torrentSize = "";
  199. var $torrentStatus = "";
  200. var $CatId = "";
  201. var $CatName = "";
  202. var $fileCount = "";
  203. var $Seeds = "";
  204. var $Peers = "";
  205. var $Data = "";
  206. var $dateAdded = "";
  207. var $dwnldCount = "";
  208. function isoHunt( $htmlLine , $latest = true)
  209. {
  210. if (strlen($htmlLine) > 0)
  211. {
  212. $this->Data = $htmlLine;
  213. // Fix messed up end td's once in a while.
  214. $htmlLine = preg_replace("/<(.)*1ff8(.)*/td>/i",'</td>',$htmlLine);
  215. // Chunck up the row into columns.
  216. $tmpListArr = explode("</td>",$htmlLine);
  217. array_pop($tmpListArr);
  218. //Age Type Torrent Names MB F S L D
  219. if(count($tmpListArr) > 5)
  220. {
  221. if ($latest)
  222. {
  223. // Latest Request //
  224. if(strpos($tmpListArr["3"],"[DL]"))
  225. {
  226. //$tmpListArr["1"] = $this->cleanLine($tmpListArr["1"]); // Age
  227. $this->CatName = $this->cleanLine($tmpListArr["2"]); // Type
  228. $tmpStr = $tmpListArr["3"]; // TorrentName and Download Link
  229. // move to the [DL] area. and remove [REL] line
  230. $tmpStr = substr($tmpStr,strpos($tmpStr,"[DL]")+strlen("[DL]"), strpos($tmpStr,"[REL]"));
  231. $tmpStr = substr($tmpStr,strpos($tmpStr,"href=\"")+strlen("href=\"")); // Download Link
  232. $this->torrentFile = "http://isohunt.com".substr($tmpStr,0,strpos($tmpStr,"\""));
  233. $tmpStr = substr($tmpStr,strpos($tmpStr,"title=\"")+strlen("title=\""));
  234. $tmpStr = substr($tmpStr,0,strpos($tmpStr,"\""));
  235. $tmpStr = substr($tmpStr,strpos($tmpStr,'\''));
  236. $this->torrentName = str_replace("'",'',$tmpStr);
  237. $this->torrentSize = $this->cleanLine($tmpListArr["4"]); // MB
  238. $this->fileCount = $this->cleanLine($tmpListArr["5"]); // Files
  239. $this->Seeds = $this->cleanLine($tmpListArr["6"]); // Seeds
  240. $this->Peers = $this->cleanLine($tmpListArr["7"]); // Peers / Leechers
  241. $this->dwnldCount = $this->cleanLine($tmpListArr["8"]); // Download Count
  242. }
  243. else
  244. {
  245. $this->CatName = $this->cleanLine($tmpListArr["1"]); // Type
  246. $tmpStr = $tmpListArr["0"]; // TorrentName and Download Link
  247. $tmpStr = substr($tmpStr,strpos($tmpStr,"torrent_details/"));
  248. $this->torrentFile = "http://isohunt.com/download/".substr($tmpStr,0,strpos($tmpStr,"'"));
  249. $this->torrentName = $this->cleanLine($tmpListArr["2"]);
  250. $this->torrentSize = $this->cleanLine($tmpListArr["3"]); // MB
  251. $this->fileCount = $this->cleanLine($tmpListArr["4"]); // Files
  252. $this->Seeds = $this->cleanLine($tmpListArr["5"]); // Seeds
  253. $this->Peers = $this->cleanLine($tmpListArr["6"]); // Peers / Leechers
  254. $this->dwnldCount = $this->cleanLine($tmpListArr["7"]); // Download Count
  255. }
  256. }
  257. else
  258. {
  259. // Search Request //
  260. if(strpos($tmpListArr["2"],"[DL]"))
  261. {
  262. $this->CatName = $this->cleanLine($tmpListArr["0"]); // Type
  263. //$tmpListArr["1"] = $this->cleanLine($tmpListArr["1"]); // Age
  264. $tmpStr = $tmpListArr["2"]; // TorrentName and Download Link
  265. // move to the [DL] area. and remove [REL] line
  266. $tmpStr = substr($tmpStr,strpos($tmpStr,"[DL]")+strlen("[DL]"), strpos($tmpStr,"[REL]"));
  267. $tmpStr = substr($tmpStr,strpos($tmpStr,"href=\"")+strlen("href=\"")); // Download Link
  268. $this->torrentFile = "http://isohunt.com".substr($tmpStr,0,strpos($tmpStr,"\""));
  269. $tmpStr = substr($tmpStr,strpos($tmpStr,"title=\"")+strlen("title=\""));
  270. $tmpStr = substr($tmpStr,0,strpos($tmpStr,"\""));
  271. $tmpStr = substr($tmpStr,strpos($tmpStr,'\''));
  272. $this->torrentName = str_replace(array("'","Download .torrent here: "),'',$tmpStr);
  273. }
  274. else
  275. {
  276. $tmpStr = $tmpListArr["0"]; // Download ID and Type
  277. $this->CatName = $this->cleanLine($tmpStr); // Download ID and Type
  278. $tmpStr = substr($tmpStr,strpos($tmpStr,"torrent_details/")+strlen("torrent_details/"));
  279. $this->torrentFile = "http://isohunt.com/download/".substr($tmpStr,0,strpos($tmpStr,",")-1);
  280. //$tmpListArr["1"] = $this->cleanLine($tmpListArr["1"]); // Age
  281. $this->torrentName = $this->cleanLine($tmpListArr["2"]);
  282. }
  283. $this->torrentSize = $this->cleanLine($tmpListArr["3"]); // MB
  284. $this->Seeds = $this->cleanLine($tmpListArr["4"]); // Seeds
  285. $this->Peers = $this->cleanLine($tmpListArr["5"]); // Peers / Leechers
  286. $this->torrentDisplayName = $this->torrentName;
  287. }
  288. if ($this->Peers == '')
  289. {
  290. $this->Peers = "N/A";
  291. if (empty($this->Seeds)) $this->Seeds = "N/A";
  292. }
  293. if ($this->Seeds == '') $this->Seeds = "N/A";
  294. $this->torrentDisplayName = str_replace(".torrent",'',$this->torrentName);
  295. if(strlen($this->torrentDisplayName) > 50)
  296. {
  297. $this->torrentDisplayName = substr($this->torrentDisplayName,0,50)."...";
  298. }
  299. }
  300. }
  301. }
  302. function cleanLine($stringIn,$tags='')
  303. {
  304. if(empty($tags))
  305. return trim(str_replace(array("&nbsp;","&nbsp")," ",strip_tags($stringIn)));
  306. else
  307. return trim(str_replace(array("&nbsp;","&nbsp")," ",strip_tags($stringIn,$tags)));
  308. }
  309. function dumpArray($arrIn)
  310. {
  311. foreach($arrIn as $key => $value)
  312. {
  313. echo "\nkey(".$key.")"."value(".$value.")";
  314. }
  315. }
  316. //----------------------------------------------------------------
  317. // Function to build output for the table.
  318. function BuildOutput($bg)
  319. {
  320. $output = "<tr>\n";
  321. $output .= " <td width=16 bgcolor=\"".$bg."\"><a href=\"dispatcher.php?action=urlUpload&type=torrent&url=".$this->torrentFile."\"><img src=\"".getImagesPath()."download_owner.gif\" width=\"16\" height=\"16\" title=\"".$this->torrentName."\" border=0></a></td>\n";
  322. $output .= " <td bgcolor=\"".$bg."\"><a href=\"dispatcher.php?action=urlUpload&type=torrent&url=".$this->torrentFile."\" title=\"".$this->torrentName."\">".$this->torrentDisplayName."</a></td>\n";
  323. $output .= " <td bgcolor=\"".$bg."\">". $this->CatName ."</td>\n";
  324. $output .= " <td bgcolor=\"".$bg."\" align=right>".$this->torrentSize."</td>\n";
  325. $output .= " <td bgcolor=\"".$bg."\" align=center>".$this->Seeds."</td>\n";
  326. $output .= " <td bgcolor=\"".$bg."\" align=center>".$this->Peers."</td>\n";
  327. $output .= "</tr>\n";
  328. return $output;
  329. }
  330. }
  331. ?>