1
0

TokyoToshoEngine.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <?php
  2. /* $Id: TokyoToshoEngine.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. class SearchEngine extends SearchEngineBase
  22. {
  23. function SearchEngine($cfg)
  24. {
  25. $this->mainURL = "tokyotosho.com";
  26. $this->altURL = "tokyotosho.info";
  27. $this->mainTitle = "TokyoTosho";
  28. $this->engineName = "TokyoTosho";
  29. $this->author = "nls";
  30. $this->version = "1.00-tfb";
  31. $this->updateURL = "http://www.torrentflux.com/forum/index.php/topic,1581.0.html";
  32. $this->Initialize($cfg);
  33. }
  34. function populateMainCategories()
  35. {
  36. $this->mainCatalog["0"] = "(all types)";
  37. $this->mainCatalog["1"] = "Anime";
  38. $this->mainCatalog["10"] = "Non-English Sub";
  39. $this->mainCatalog["8"] = "Drama";
  40. $this->mainCatalog["3"] = "Manga";
  41. $this->mainCatalog["2"] = "Music";
  42. $this->mainCatalog["9"] = "Music-Video";
  43. $this->mainCatalog["7"] = "Raw";
  44. $this->mainCatalog["4"] = "Hentai";
  45. $this->mainCatalog["5"] = "Other";
  46. }
  47. //----------------------------------------------------------------
  48. // Function to Make the Request (overriding base)
  49. function makeRequest($request)
  50. {
  51. return parent::makeRequest($request, false);
  52. }
  53. //----------------------------------------------------------------
  54. // Function to get Latest
  55. function getLatest()
  56. {
  57. return $this->performSearch("");
  58. }
  59. //----------------------------------------------------------------
  60. // Function to perform Search.
  61. function performSearch($searchTerm)
  62. {
  63. if ($searchTerm == "") {
  64. $request = "/";
  65. } else {
  66. $searchTerm = str_replace(" ", "+", $searchTerm);
  67. $request = "/search.php?terms=" . $searchTerm;
  68. }
  69. $cat = tfb_getRequestVar("cat");
  70. if(empty($cat)) $cat = tfb_getRequestVar("mainGenre");
  71. if(!empty($cat))
  72. {
  73. if(strpos($request, "?")) {
  74. $request .= "&cat=" . $cat;
  75. } else {
  76. $request .= "?cat=" . $cat;
  77. }
  78. }
  79. if (!empty($this->pg))
  80. {
  81. if(strpos($request, "?")) {
  82. $request .= "&page=" . $this->pg;
  83. } else {
  84. $request .= "?page=" . $this->pg;
  85. }
  86. }
  87. if ($this->makeRequest($request)) {
  88. return $this->parseResponse();
  89. } else {
  90. return $this->msg;
  91. }
  92. }
  93. //----------------------------------------------------------------
  94. // Function to parse the response.
  95. function parseResponse()
  96. {
  97. $output = $this->tableHeader();
  98. $s = $this->htmlPage;
  99. $bg = $this->cfg["bgLight"];
  100. $s = substr($s, strpos($s, "<table class=\"listing\">"));
  101. if ($s === false) {
  102. return "<table width=\"100%\" cellpadding=3 cellspacing=0 border=0><tr><td align=\"center\"><strong><br/>Nothing to display.<br/></strong></td></tr></table>";
  103. }
  104. $s = substr($s, strpos($s, "<tr"), strpos($s, "</table>") - strpos($s, "<tr"));
  105. $tmpListArr = explode("<td rowspan=\"2\">", $s);
  106. foreach($tmpListArr as $line)
  107. {
  108. $buildLine = true;
  109. if (strpos($line, "cat=") !== false) {
  110. $ts = new ToTo($line);
  111. // we always have category description, but when searching,
  112. // there is no category id, so we try to find it...
  113. if (!is_int($ts->catId))
  114. $ts->catId = array_search($ts->catName, $this->mainCatalog);
  115. if (is_int(array_search($ts->catId, $this->catFilter))) {
  116. $buildLine = false;
  117. }
  118. if (!empty($ts->torrentFile) && $buildLine) {
  119. $output .= trim($ts->BuildOutput($bg));
  120. if ($bg == $this->cfg["bgLight"]) {
  121. $bg = $this->cfg["bgDark"];
  122. } else {
  123. $bg = $this->cfg["bgLight"];
  124. }
  125. }
  126. }
  127. }
  128. $output .= "</table>";
  129. // http://tokyotosho.com/?cat=4&page=2
  130. // is there paging?
  131. $s = $this->htmlPage;
  132. if (strpos($s, "<td class=\"nav\"") !== false) {
  133. $s = substr($s, strpos($s, "<td class=\"nav\""), 500);
  134. $cat = 0;
  135. $output .= "<table width=\"100%\" cellpadding=3 cellspacing=0 border=0><tr><td align=\"center\">";
  136. if (preg_match("@.*page=([0-9]*)&amp;cat=([0-9]*)\">.*Previous 50.*@U", $s, $parts)) {
  137. $output .= "<a href=\"" . $this->searchURL() . "&pg=" . $parts[1] . "&cat=" . $parts[2] . "\">&lt;&lt; Previous 50</a> :: ";
  138. }
  139. $output .= "<a href=\"" . $this->searchURL() . "\">50 Most Recent</a>";
  140. if (preg_match("@.*page=([0-9]*)&amp;cat=([0-9]*)\">Next 50 .*@U", $s, $parts)) {
  141. $output .= " :: <a href=\"" . $this->searchURL() . "&pg=" . $parts[1] . "&cat=" . $parts[2] . "\">Next 50 &gt;&gt;</a>";
  142. }
  143. $output .= "</td></tr></table>";
  144. }
  145. return $output;
  146. }
  147. // Function to setup the table header - overridden for toto (no seeds, no peers)
  148. function tableHeader()
  149. {
  150. $output = "<table width=\"100%\" cellpadding=3 cellspacing=0 border=0>";
  151. $output .= "<br>\n";
  152. $output .= "<tr bgcolor=\"".$this->cfg["table_header_bg"]."\">";
  153. $output .= " <td>&nbsp;</td>";
  154. $output .= " <td><strong>Torrent Name</strong></td>";
  155. $output .= " <td><strong>Category</strong></td>";
  156. // $output .= " <td align=center><strong>Date</strong></td>";
  157. $output .= " <td align=right><strong>&nbsp;&nbsp;Size</strong></td>";
  158. $output .= "</tr>\n";
  159. return $output;
  160. }
  161. }
  162. // This is a worker class that takes in a row in a table and parses it.
  163. class ToTo
  164. {
  165. var $catId = "";
  166. var $catName = "";
  167. var $torrentFile = "";
  168. var $torrentName = "";
  169. var $torrentDisplayName = "";
  170. var $torrentSize = "";
  171. var $dateAdded = "";
  172. var $comment = "";
  173. function ToTo($line) {
  174. if (strlen($line) > 0) {
  175. if (0 == preg_match(
  176. "@.*<a href=\"\?cat=([^\"]*)\"><img class=\"icon\" alt=\"([^\"]*)\"" .
  177. ".*<td class=\"desc-top\"><a rel=\"nofollow\" href=\"([^\"]*)\">([^\"]*)</a></td>" .
  178. ".*Size: ([^ ]*) \| Date: ([^\|<]*).*@", $line, $parts))
  179. {
  180. // search results
  181. preg_match(
  182. "@.*<a rel=\"nofollow\" href=\".*?cat=([^\"]*)\"><img alt=\"([^\"]*)\"" .
  183. ".*<td class=\"desc-top\"><a href=\"([^\"]*)\">([^\"]*)</a></td>" .
  184. ".*Size: ([^ ]*) \| Date: ([^\|<]*).*@", $line, $parts);
  185. }
  186. $this->catId = trim($parts[1]);
  187. $this->catName = trim($parts[2]);
  188. $this->torrentFile = $parts[3];
  189. $this->torrentName = $parts[4];
  190. $this->torrentSize = trim($parts[5]);
  191. $this->dateAdded = trim($parts[6]);
  192. $this->torrentDisplayName = $this->torrentName;
  193. if(strlen($this->torrentDisplayName) > 103) {
  194. $this->torrentDisplayName = substr($this->torrentDisplayName, 0, 100) . "...";
  195. }
  196. if (preg_match("@.*Comment: (.*)</td>@U", $line, $parts)) $this->comment = trim($parts[1]);
  197. }
  198. }
  199. function BuildOutput($bg) {
  200. $output = "<tr>\n";
  201. $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";
  202. $output .= " <td bgcolor=\"".$bg."\"><a href=\"dispatcher.php?action=urlUpload&type=torrent&url=".$this->torrentFile."\" title=\"".$this->torrentName."\">".$this->torrentDisplayName."</a></td>\n";
  203. $output .= " <td bgcolor=\"" . $bg . "\">" . $this->catName . "&nbsp;</td>\n";
  204. // $output .= " <td bgcolor=\"" . $bg . "\" align=center>" . $this->dateAdded . "</td>\n";
  205. $output .= " <td bgcolor=\"" . $bg . "\" align=right>" . $this->torrentSize . "</td>\n";
  206. $output .= "</tr>\n";
  207. return $output;
  208. }
  209. }
  210. ?>