1
0

Filemp3Engine.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. <?php
  2. /* $Id: Filemp3Engine.php 2833 2007-04-08 11:58:47Z b4rt $ */
  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.02 - Oct 18, 06. fix to parsing thx kalep
  23. v 1.01 - Sep 22, 06. Added Stats and Fixed filenames
  24. v 1.00 - Sep 22, 06.
  25. */
  26. class SearchEngine extends SearchEngineBase
  27. {
  28. function SearchEngine($cfg)
  29. {
  30. $this->mainURL = "Filemp3.org";
  31. $this->altURL = "www.Filemp3.org";
  32. $this->mainTitle = "Filemp3";
  33. $this->engineName = "Filemp3";
  34. $this->author = "kboy";
  35. $this->version = "1.02-tfb";
  36. $this->updateURL = "http://www.torrentflux.com/forum/index.php/topic,1967.0.html";
  37. $this->Initialize($cfg);
  38. }
  39. //----------------------------------------------------------------
  40. // Function to Get Main Categories
  41. function populateMainCategories()
  42. {
  43. $this->mainCatalog["0"] = "(all types)";
  44. $this->mainCatalog["1"] = " Alternative";
  45. $this->mainCatalog["2"] = " Dance";
  46. $this->mainCatalog["3"] = " Hip-Hop";
  47. $this->mainCatalog["4"] = " Metal";
  48. $this->mainCatalog["5"] = " Pop";
  49. $this->mainCatalog["6"] = " Punk";
  50. $this->mainCatalog["7"] = " Rap";
  51. $this->mainCatalog["8"] = " R 'n' B";
  52. $this->mainCatalog["9"] = " Rock";
  53. $this->mainCatalog["10"] = "Trance";
  54. $this->mainCatalog["11"] = "Other";
  55. $this->mainCatalog["12"] = "Music Vids";
  56. $this->mainCatalog["13"] = "Old Music";
  57. $this->mainCatalog["14"] = "Country";
  58. $this->mainCatalog["15"] = "House";
  59. $this->mainCatalog["16"] = "Reggae";
  60. $this->mainCatalog["17"] = "Electronic";
  61. $this->mainCatalog["18"] = "Techno";
  62. $this->mainCatalog["19"] = "Drum 'n' Bass";
  63. $this->mainCatalog["20"] = "OST";
  64. $this->mainCatalog["21"] = "Psychedelic";
  65. $this->mainCatalog["22"] = "Hardcore";
  66. $this->mainCatalog["23"] = "Jazz";
  67. $this->mainCatalog["24"] = "Indie";
  68. $this->mainCatalog["25"] = "Funk";
  69. $this->mainCatalog["26"] = "Lo Fi";
  70. $this->mainCatalog["27"] = "Ambient";
  71. $this->mainCatalog["28"] = "Instrumental";
  72. $this->mainCatalog["29"] = "Blues";
  73. }
  74. //----------------------------------------------------------------
  75. // Function to get Latest..
  76. function getLatest()
  77. {
  78. $cat = tfb_getRequestVar('mainGenre');
  79. if (empty($cat)) $cat = tfb_getRequestVar('cat');
  80. $request = "/browse.php";
  81. if(!empty($cat))
  82. {
  83. if(strpos($request,"?"))
  84. {
  85. $request .= "&cat=".$cat;
  86. }
  87. else
  88. {
  89. $request .= "?cat=".$cat;
  90. }
  91. }
  92. if (!empty($this->pg))
  93. {
  94. if(strpos($request,"?"))
  95. {
  96. $request .= "&page=" . $this->pg;
  97. }
  98. else
  99. {
  100. $request .= "?page=" . $this->pg;
  101. }
  102. }
  103. if ($this->makeRequest($request,true))
  104. {
  105. if (strlen($this->htmlPage) > 0 )
  106. {
  107. return $this->parseResponse();
  108. }
  109. else
  110. {
  111. return 'Unable to Browse at this time.';
  112. }
  113. }
  114. else
  115. {
  116. return $this->msg;
  117. }
  118. }
  119. //----------------------------------------------------------------
  120. // Function to perform Search.
  121. function performSearch($searchTerm)
  122. {
  123. // create the request string.
  124. $searchTerm = str_replace(" ", "+", $searchTerm);
  125. $request = "/browse.php?search=".$searchTerm;
  126. if(!empty($cat))
  127. {
  128. $request .= "&cat=".$cat;
  129. }
  130. $incldead = tfb_getRequestVar('incldead');
  131. if (empty($incldead)) $incldead = "0";
  132. $request .= "&incldead=".$incldead;
  133. if (!empty($this->pg))
  134. {
  135. $request .= "&page=" . $this->pg;
  136. }
  137. if ($this->makeRequest($request,true))
  138. {
  139. return $this->parseResponse();
  140. }
  141. else
  142. {
  143. return $this->msg;
  144. }
  145. }
  146. //----------------------------------------------------------------
  147. // Override the base to show custom table header.
  148. // Function to setup the table header
  149. function tableHeader()
  150. {
  151. $tmpStr = $this->htmlPage;
  152. if (strpos($tmpStr,">Wait</") > 0)
  153. {
  154. $needWait = true;
  155. }
  156. else
  157. {
  158. $needWait = false;
  159. }
  160. $output = "<table width=\"100%\" cellpadding=3 cellspacing=0 border=0>";
  161. $output .= "<br>\n";
  162. $output .= "<tr bgcolor=\"".$this->cfg["bgLight"]."\">";
  163. if ($needWait)
  164. {
  165. $output .= " <td colspan=9 align=center>";
  166. }
  167. else
  168. {
  169. $output .= " <td colspan=8 align=center>";
  170. }
  171. $tmpStr = substr($tmpStr,strpos($tmpStr,"userdetails"));
  172. $tmpStr = substr($tmpStr,strpos($tmpStr,"<font"));
  173. $output .= "<font size=5px> Current Stats : ".strip_tags(substr("<td>".$tmpStr,0,strpos($tmpStr,"</td>")))."</font>";
  174. $output .= "</td>";
  175. $output .= "<tr bgcolor=\"".$this->cfg["table_header_bg"]."\">";
  176. $output .= " <td>&nbsp;</td>";
  177. $output .= " <td><strong>Torrent Name</strong> &nbsp;(";
  178. $tmpURI = str_replace(array("?hideSeedless=yes","&hideSeedless=yes","?hideSeedless=no","&hideSeedless=no"),"",$_SERVER["REQUEST_URI"]);
  179. // Check to see if Question mark is there.
  180. if (strpos($tmpURI,'?'))
  181. {
  182. $tmpURI .= "&";
  183. }
  184. else
  185. {
  186. $tmpURI .= "?";
  187. }
  188. if($this->hideSeedless == "yes")
  189. {
  190. $output .= "<a href=\"". $tmpURI . "hideSeedless=no\">Show Seedless</a>";
  191. }
  192. else
  193. {
  194. $output .= "<a href=\"". $tmpURI . "hideSeedless=yes\">Hide Seedless</a>";
  195. }
  196. $output .= ")</td>";
  197. $output .= " <td><strong>Category</strong></td>";
  198. $output .= " <td align=center><strong>&nbsp;&nbsp;Size</strong></td>";
  199. $output .= " <td><strong>Seeds</strong></td>";
  200. $output .= " <td><strong>Peers</strong></td>";
  201. if ($needWait)
  202. {
  203. $output .= " <td><strong>Wait</strong></td>";
  204. }
  205. $output .= " <td><strong>File Life</strong></td>";
  206. $output .= " <td><strong>Snatched</strong></td>";
  207. $output .= "</tr>\n";
  208. return $output;
  209. }
  210. //----------------------------------------------------------------
  211. // Function to parse the response.
  212. function parseResponse($latest = true)
  213. {
  214. $output = $this->tableHeader();
  215. $thing = $this->htmlPage;
  216. if(strpos($thing,"Error:") > 0)
  217. {
  218. $tmpStr = substr($thing,strpos($thing,"Error:")+strlen("Error:"));
  219. $tmpStr = substr($tmpStr,0,strpos($tmpStr,"</p>"));
  220. $this->msg = strip_tags($tmpStr);
  221. return $output . "<center>".$this->msg."</center><br>";
  222. }
  223. // We got a response so display it.
  224. // Chop the front end off.
  225. $thing = substr($thing,strpos($thing,">Hits<"));
  226. $thing = substr($thing,strpos($thing,"</tr>")+strlen("</tr>"));
  227. $tmpList = substr($thing,0,strpos($thing,"</table>"));
  228. // ok so now we have the listing.
  229. $tmpListArr = explode("</tr>",$tmpList);
  230. $bg = $this->cfg["bgLight"];
  231. foreach($tmpListArr as $key =>$value)
  232. {
  233. //echo $value;
  234. $buildLine = true;
  235. if (strpos($value,"id="))
  236. {
  237. $ts = new fileMP3($value, $this->mainURL);
  238. // Determine if we should build this output
  239. if (is_int(array_search($ts->MainId,$this->catFilter)))
  240. {
  241. $buildLine = false;
  242. }
  243. if ($this->hideSeedless == "yes")
  244. {
  245. if($ts->Seeds == "N/A" || $ts->Seeds == "0")
  246. {
  247. $buildLine = false;
  248. }
  249. }
  250. if (!empty($ts->torrentFile) && $buildLine) {
  251. $output .= trim($ts->BuildOutput($bg,$this->searchURL()));
  252. // ok switch colors.
  253. if ($bg == $this->cfg["bgLight"])
  254. {
  255. $bg = $this->cfg["bgDark"];
  256. }
  257. else
  258. {
  259. $bg = $this->cfg["bgLight"];
  260. }
  261. }
  262. }
  263. }
  264. // set thing to end of this table.
  265. $thing = substr($thing,strpos($thing,"</table>"));
  266. $output .= "</table>";
  267. // is there paging at the bottom?
  268. if (strpos($thing, "page=") != false)
  269. {
  270. // Yes, then lets grab it and display it! ;)
  271. $pages = substr($thing,strpos($thing,"<p"));
  272. $pages = substr($pages,strpos($pages,">"));
  273. $pages = substr($pages,0,strpos($pages,"</p>"));
  274. $pages = str_replace("&nbsp; ",'',$pages);
  275. $tmpPageArr = explode("</a>",$pages);
  276. array_pop($tmpPageArr);
  277. $pagesout = '';
  278. foreach($tmpPageArr as $key => $value)
  279. {
  280. $value .= "</a> &nbsp;";
  281. //$tmpVal = substr($value,strpos($value,"browse.php?"));
  282. $tmpVal = substr($value,strpos($value,"browse.php?"),strpos($value,"\">")-2);
  283. $pgNum = substr($tmpVal,strpos($tmpVal,"page=")+strlen("page="));
  284. $pagesout .= str_replace($tmpVal,"XXXURLXXX".$pgNum,$value);
  285. }
  286. $pagesout = str_replace("se.php?page=","",$pagesout);
  287. $cat = tfb_getRequestVar('mainGenre');
  288. if (empty($cat)) $cat = tfb_getRequestVar('cat');
  289. if(strpos($this->curRequest,"LATEST"))
  290. {
  291. if (!empty($cat))
  292. {
  293. $pages = str_replace("XXXURLXXX",$this->searchURL()."&LATEST=1&cat=".$cat."&pg=",$pagesout);
  294. }
  295. else
  296. {
  297. $pages = str_replace("XXXURLXXX",$this->searchURL()."&LATEST=1&pg=",$pagesout);
  298. }
  299. }
  300. else
  301. {
  302. if(!empty($cat))
  303. {
  304. $pages = str_replace("XXXURLXXX",$this->searchURL()."&searchterm=".$_REQUEST["searchterm"]."&cat=".$cat."&pg=",$pagesout);
  305. }
  306. else
  307. {
  308. $pages = str_replace("XXXURLXXX",$this->searchURL()."&searchterm=".$_REQUEST["searchterm"]."&pg=",$pagesout);
  309. }
  310. }
  311. $output .= "<div align=center>".substr($pages,1)."</div>";
  312. }
  313. return $output;
  314. }
  315. }
  316. // This is a worker class that takes in a row in a table and parses it.
  317. class fileMP3
  318. {
  319. var $torrentName = "";
  320. var $torrentDisplayName = "";
  321. var $torrentFile = "";
  322. var $torrentSize = "";
  323. var $torrentStatus = "";
  324. var $MainId = "";
  325. var $MainCategory = "";
  326. var $fileLife = "";
  327. var $Seeds = "";
  328. var $Peers = "";
  329. var $needsWait = false;
  330. var $waitTime = "";
  331. var $Data = "";
  332. var $torrentRating = "";
  333. function fileMP3( $htmlLine, $dwnURL )
  334. {
  335. if (strlen($htmlLine) > 0)
  336. {
  337. $this->Data = $htmlLine;
  338. // Cleanup any bugs in the HTML
  339. $htmlLine = preg_replace("/</td>\n</td>/i",'</td>',$htmlLine);
  340. // Chunck up the row into columns.
  341. $tmpListArr = explode("<td ",$htmlLine);
  342. if(count($tmpListArr) > 9)
  343. {
  344. $tmpStr = substr($tmpListArr["1"],strpos($tmpListArr["1"],"alt=\"")+strlen("alt=\"")); // MainCategory
  345. $this->MainCategory = substr($tmpStr,0,strpos($tmpStr,"\""));
  346. $tmpStr = substr($tmpListArr["1"],strpos($tmpListArr["1"],"cat=")+strlen("cat=")); // Main Id
  347. $this->MainId = trim(substr($tmpStr,0,strpos($tmpStr,"\"")));
  348. $this->torrentName = $this->cleanLine("<td ".$tmpListArr["2"]."</td>"); // TorrentName
  349. $tmpStr = substr($tmpListArr["2"],strpos($tmpListArr["2"],"id=")+strlen("id=")); // File Id
  350. $tmpStr = substr($tmpStr,0,strpos($tmpStr,"&"));
  351. $this->torrentFile = "http://".$dwnURL."/download.php/".$tmpStr."/";
  352. if($this->MainId == "9")
  353. {
  354. $this->torrentFile .= $this->torrentName.".torrent";
  355. }
  356. else
  357. {
  358. $this->torrentFile .= str_replace(" ","_",$this->torrentName).".torrent";
  359. }
  360. $this->needsWait = true;
  361. $this->waitTime = $this->cleanLine("<td ".$tmpListArr["3"]."</td>"); // Wait Time
  362. $this->fileLife = $this->cleanLine("<td ".$tmpListArr["5"]."</td>"); // File Life
  363. $this->fileLife = str_replace("hours","hrs",$this->fileLife);
  364. $this->torrentSize = $this->cleanLine("<td ".$tmpListArr["6"]."</td>"); // Size of File
  365. $this->torrentStatus = $this->cleanLine(str_replace("<br>"," ","<td ".$tmpListArr["7"]."</td>")); // Snatched
  366. $this->Seeds = $this->cleanLine("<td ".$tmpListArr["8"]."</td>"); // Seeds
  367. $this->Peers = $this->cleanLine("<td ".$tmpListArr["9"]."</td>"); // Leech
  368. if ($this->Peers == '')
  369. {
  370. $this->Peers = "N/A";
  371. if (empty($this->Seeds)) $this->Seeds = "N/A";
  372. }
  373. if ($this->Seeds == '') $this->Seeds = "N/A";
  374. } else {
  375. $tmpStr = substr($tmpListArr["1"],strpos($tmpListArr["1"],"alt=\"")+strlen("alt=\"")); // MainCategory
  376. $this->MainCategory = substr($tmpStr,0,strpos($tmpStr,"\""));
  377. $tmpStr = substr($tmpListArr["1"],strpos($tmpListArr["1"],"cat=")+strlen("cat=")); // Main Id
  378. $this->MainId = trim(substr($tmpStr,0,strpos($tmpStr,"\"")));
  379. $this->torrentName = $this->cleanLine("<td ".$tmpListArr["2"]."</td>"); // TorrentName
  380. $tmpStr = substr($tmpListArr["2"],strpos($tmpListArr["2"],"id=")+strlen("id=")); // File Id
  381. $tmpStr = substr($tmpStr,0,strpos($tmpStr,"&"));
  382. $this->torrentFile = "http://".$dwnURL."/download.php/".$tmpStr."/";
  383. if($this->MainId == "9")
  384. {
  385. $this->torrentFile .= $this->torrentName.".torrent";
  386. }
  387. else
  388. {
  389. $this->torrentFile .= str_replace(" ","_",$this->torrentName).".torrent";
  390. }
  391. $this->needsWait = false;
  392. $this->fileLife = $this->cleanLine("<td ".$tmpListArr["4"]."</td>"); // File Life
  393. $this->fileLife = str_replace("hours","hrs",$this->fileLife);
  394. $this->torrentSize = $this->cleanLine("<td ".$tmpListArr["5"]."</td>"); // Size of File
  395. $this->torrentStatus = $this->cleanLine(str_replace("<br>"," ","<td ".$tmpListArr["6"]."</td>")); // Snatched
  396. $this->Seeds = $this->cleanLine("<td ".$tmpListArr["7"]."</td>"); // Seeds
  397. $this->Peers = $this->cleanLine("<td ".$tmpListArr["8"]."</td>"); // Leech
  398. if ($this->Peers == '')
  399. {
  400. $this->Peers = "N/A";
  401. if (empty($this->Seeds)) $this->Seeds = "N/A";
  402. }
  403. if ($this->Seeds == '') $this->Seeds = "N/A";
  404. }
  405. $this->torrentDisplayName = $this->torrentName;
  406. if(strpos($this->torrentName,"\n"))
  407. {
  408. $this->torrentDisplayName = substr($this->torrentName,0,strpos($this->torrentName,"\n"));
  409. $this->torrentName = str_replace("\n"," [",$this->torrentName)."]";
  410. }
  411. if(strlen($this->torrentDisplayName) > 50)
  412. {
  413. $this->torrentDisplayName = substr($this->torrentDisplayName,0,50)."...";
  414. }
  415. }
  416. }
  417. function cleanLine($stringIn,$tags='')
  418. {
  419. if(empty($tags))
  420. return trim(str_replace(array("&nbsp;","&nbsp")," ",strip_tags($stringIn)));
  421. else
  422. return trim(str_replace(array("&nbsp;","&nbsp")," ",strip_tags($stringIn,$tags)));
  423. }
  424. //----------------------------------------------------------------
  425. // Function to build output for the table.
  426. function BuildOutput($bg, $searchURL = '')
  427. {
  428. $output = "<tr>\n";
  429. $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";
  430. $output .= " <td bgcolor=\"".$bg."\"><a href=\"dispatcher.php?action=urlUpload&type=torrent&url=".$this->torrentFile."\" title=\"".$this->torrentName."\">".$this->torrentDisplayName."</a></td>\n";
  431. if (strlen($this->MainCategory) > 1){
  432. $genre = "<a href=\"".$searchURL."&mainGenre=".$this->MainId."\">".$this->MainCategory."</a>";
  433. }else{
  434. $genre = "";
  435. }
  436. $output .= " <td bgcolor=\"".$bg."\">". $genre ."</td>\n";
  437. $output .= " <td bgcolor=\"".$bg."\" align=right>".$this->torrentSize."</td>\n";
  438. $output .= " <td bgcolor=\"".$bg."\" align=center>".$this->Seeds."</td>\n";
  439. $output .= " <td bgcolor=\"".$bg."\" align=center>".$this->Peers."</td>\n";
  440. if ($this->needsWait)
  441. {
  442. $output .= " <td bgcolor=\"".$bg."\" align=center>".$this->waitTime."</td>\n";
  443. }
  444. $output .= " <td bgcolor=\"".$bg."\" align=center>".$this->fileLife."</td>\n";
  445. $output .= " <td bgcolor=\"".$bg."\" align=center>".$this->torrentStatus."</td>\n";
  446. $output .= "</tr>\n";
  447. return $output;
  448. }
  449. }
  450. ?>