Advertisement
jurassicplayer

Nyaa extsearch Engine

Jul 20th, 2014
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.96 KB | None | 0 0
  1. <?php
  2.  
  3. class NyaaEngine extends commonEngine
  4. {
  5.     public $defaults = array( "public"=>true, "page_size"=>25 );
  6.     public $categories = array( 'All categories'=>'0_0', 'Anime'=>'1_0', 'Anime - Anime Music Video'=>'1_32', 'Anime - English-translated Anime'=>'1_37', 'Anime - Non-English-translated Anime'=>'1_38', 'Anime - Raw Anime'=>'1_11',
  7.         'Audio'=>'3_0', 'Audio - Lossless Audio'=>'3_14', 'Audio - Lossy Audio'=>'3_15',
  8.         'Literature'=>'2_0', 'Literature - English-translated Literature'=>'2_12', 'Literature - Non-English-translated Literature'=>'2_39', 'Literature - Raw Literature'=>'2_13',
  9.         'Live Action'=>'5_0', 'Live Action - English-translated Live Action'=>'5_19', 'Live Action - Live Action Promotional Video'=>'5_22', 'Live Action - Non-English-translated Live Action'=>'5_21', 'Live Action - Raw Live Action'=>'5_20',
  10.         'Pictures'=>'4_0', 'Pictures - Graphics'=>'4_18', 'Pictures - Photos'=>'4_17',
  11.         'Software'=>'6_0', 'Software - Applications'=>'6_23', 'Software - Games'=>'6_24' );
  12.  
  13.     public function action($what,$cat,&$ret,$limit,$useGlobalCats)
  14.     {
  15.         $added = 0;
  16.         $url = 'http://www.nyaa.se';
  17.         if($useGlobalCats)
  18.             $categories = array( 'all'=>'0_0', 'movies'=>'0_0', 'tv'=>'5_0', 'music'=>'3_0', 'games'=>'6_23', 'anime'=>'1_0', 'software'=>'6_0', 'pictures'=>'4_0', 'books'=>'2_0' );
  19.         else
  20.             $categories = &$this->categories;
  21.         if(!array_key_exists($cat,$categories))
  22.             $cat = $categories['All categories'];
  23.         else
  24.             $cat = $categories[$cat];
  25.  
  26.         for($pg = 1; $pg<11; $pg++)
  27.         {
  28.             $cli = $this->fetch( $url.'/?page=search&cats='.$cat.'&filter=0&sort=1&order=1&term='.$what.'&offset='.$pg );
  29.             if( ($cli==false) || (strpos($cli->results, "<b>No torrents found.</b>")!==false) )
  30.                 break;
  31.             $res = preg_match_all('`<td class="tlisticon"><a.* title="(?P<cat>.*)"><img.*</a></td>.*'.
  32.                 '<td class="tlistname"><a href="http://www.nyaa.se/\?page=view&#38;#38;tid=(?P<id>.*)">(?P<name>.*)</a></td>.*'.
  33.                 '<td class=".*">.*</td>'.
  34.                 '<td class="tlistsize">(?P<size>.*)</td>.*'.
  35.                 '(<td class="tlistsn">(?P<seeds>.*)</td><td class="tlistln">(?P<leech>.*)</td>.*|<td class="tlistfailed" colspan="2">Status unknown</td>)'.
  36.                 '<td class=".*">.*</td>.*'.
  37.                 '<td class=".*">.*</td>'.
  38.                 '`siU', $cli->results, $matches);
  39.             if($res)
  40.             {
  41.                 for($i=0; $i<$res; $i++)
  42.                 {
  43.                     $link = $url."/?page=download&tid=".$matches["id"][$i];
  44.                     if(!array_key_exists($link,$ret))
  45.                     {
  46.                         $item = $this->getNewEntry();
  47.                         $item["desc"] = $url."/?page=view&tid=".$matches["id"][$i];
  48.                         $item["name"] = self::removeTags($matches["name"][$i]);
  49.                         $item["cat"] = self::removeTags($matches["cat"][$i]);
  50.                         $item["size"] = self::formatSize($matches["size"][$i]);
  51.                         $item["seeds"] = intval(self::removeTags($matches["seeds"][$i]));
  52.                         $item["peers"] = intval(self::removeTags($matches["leech"][$i]));
  53.                         $ret[$link] = $item;
  54.                         $added++;
  55.                         if($added>=$limit)
  56.                             return;
  57.                     }
  58.                 }
  59.             }
  60.             else
  61.                 break;
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement