Advertisement
Guest User

Untitled

a guest
Apr 6th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.06 KB | None | 0 0
  1. <?php
  2.  
  3. require('simple_html_dom.php');
  4.  
  5.  
  6. function RUtreker($query){
  7. $ch = curl_init();
  8. curl_setopt($ch, CURLOPT_URL, 'https://rutracker.org/forum/login.php');
  9. curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/32.0.1700.107 Chrome/32.0.1700.107 Safari/537.36');
  10. curl_setopt($ch, CURLOPT_POST, true);
  11. curl_setopt($ch, CURLOPT_POSTFIELDS, "login_username=free32&login_password=zxcvbq251&login=%E2%F5%EE%E4");
  12. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  13. curl_setopt($ch, CURLOPT_COOKIESESSION, true);
  14. curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie-name');  //could be empty, but cause problems on some hosts
  15. curl_setopt($ch, CURLOPT_COOKIEFILE, '/');  //could be empty, but cause problems on some hosts
  16. $answer = curl_exec($ch);
  17. if (curl_error($ch)) {
  18.     echo curl_error($ch);
  19. }
  20.  
  21. //another request preserving the session
  22. $df = urlencode(iconv('UTF-8','CP1251',$query));
  23. curl_setopt($ch, CURLOPT_URL, 'https://rutracker.org/forum/tracker.php?nm='.$df);
  24. curl_setopt($ch, CURLOPT_POST, false);
  25. curl_setopt($ch, CURLOPT_POSTFIELDS, "");
  26. $answer = curl_exec($ch);
  27. $re = '/<tr class="tCenter hl-tr">(.*?)<\/tr>/s';
  28. preg_match_all($re, $answer, $matchesR);
  29.  
  30.  
  31.  
  32. foreach ($matchesR[0] as $key => $rut) {
  33.     $html = str_get_html($rut);
  34.     $Rurl ="";
  35.     $Rtitle ="";
  36.     $Rsize ="";
  37.     $Rseed ="";
  38.     $Rleech ="";
  39.     $Rdate ="";
  40.     foreach($html->find('a.hl-tags') as $e) $Rtitle = $e->innertext;
  41.     foreach($html->find('a.tLink') as $e) $Rurl = $e->href;
  42.     foreach($html->find('a.tr-dl') as $e) $Rsize = $e->innertext;
  43.     foreach($html->find('b.seedmed') as $e) $Rseed =$e->innertext;
  44.     foreach($html->find('td.leechmed') as $e) $Rleech = $e->innertext;
  45.     foreach($html->find('td[style="padding: 1px 3px 2px;"]') as $e) $Rdate = $e->innertext;
  46.  
  47.             $Rdata[] = array(
  48.             "title"=>strip_tags($Rtitle),
  49.             "url"=>strip_tags($Rurl),
  50.             "size"=>strip_tags($Rsize),
  51.             "seed"=>strip_tags($Rseed),
  52.             "leech"=>strip_tags($Rleech),
  53.             "date"=>$Rdate,
  54.             );
  55.            
  56. }
  57.  
  58.  
  59. if (curl_error($ch)) {
  60.     echo curl_error($ch);
  61. }
  62. return $Rdata;
  63. }
  64.  
  65.  
  66. function NNM($query){
  67.     $ch = curl_init();
  68.     $df = urlencode(iconv('UTF-8','CP1251',$query));
  69.     curl_setopt($ch, CURLOPT_URL,"http://nnm-club.me/forum/tracker.php");
  70.     curl_setopt($ch, CURLOPT_POST, 1);
  71.     curl_setopt($ch, CURLOPT_POSTFIELDS,
  72.                 "f=-1&nm=".$df."&search_submit=%C8%F1%EA%E0%F2%FC");
  73.  
  74.     // in real life you should use something like:
  75.     // curl_setopt($ch, CURLOPT_POSTFIELDS,
  76.     //          http_build_query(array('postvar1' => 'value1')));
  77.  
  78.     // receive server response ...
  79.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  80.  
  81.     $server_output = curl_exec ($ch);
  82.  
  83.     curl_close ($ch);
  84.  
  85.  
  86.  
  87.     //$s = file_get_contents("nnm.html");
  88.     $re = '/<tr class="prow(.*?)">(.*?)<\/tr>/s';
  89.     preg_match_all($re, $server_output, $matches);
  90.  
  91.  
  92.     foreach($matches as $key =>$x){
  93.         $t = "";
  94.         $u = "";
  95.         $seed="";
  96.         $leech = "";
  97.         $date ="";
  98.         foreach($x as $y){$sizeRE = $re = '/<\/u> (.*?)<\/td>/m';preg_match_all($sizeRE, $y, $matchesS);
  99.  
  100.             $html = str_get_html($y);
  101.             foreach($html->find('a.topictitle') as $e) $t = $e->innertext;
  102.             foreach($html->find('a.topictitle') as $e) $u = $e->href;
  103.             foreach($html->find('td.seedmed') as $e) $seed = $e->innertext;
  104.             foreach($html->find('td.leechmed') as $e) $leech = $e->innertext;
  105.             foreach($html->find('td.gensmall') as $e) $date = $e->innertext;
  106.  
  107.             $data[] = array(
  108.             "title"=>strip_tags($t),
  109.             "url"=>strip_tags($u),
  110.             "size"=>strip_tags($matchesS[1][0]),
  111.             "seed"=>strip_tags($seed),
  112.             "leech"=>strip_tags($leech),
  113.             "date"=>$date,
  114.             );
  115.            
  116.  
  117.  
  118.         }
  119.     }
  120.     $newClear = array();
  121.  
  122.     foreach ($data as $key => $items) {
  123.         if(strlen($items['title'])>0){
  124.             $newClear[] = $items;
  125.         }
  126.     }
  127.  
  128.     return $newClear;
  129. }
  130.  
  131.  
  132.  
  133. $list = array();
  134. $list['rut'] = RUtreker($_POST['query']);
  135. $list['nnm'] = NNM($_POST['query']);
  136.  
  137. //print_r($list);
  138. ?>
  139.  
  140. <!doctype html>
  141. <html lang="en">
  142.   <head>
  143.     <!-- Required meta tags -->
  144.     <meta charset="utf-8">
  145.     <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  146. <style type="text/css">
  147.     #search{
  148.         background: #fff;
  149.         margin: 50px ;
  150.         float: center;
  151.     }
  152. </style>
  153.     <!-- Bootstrap CSS -->
  154.     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  155.  
  156.     <title>Hello, world!</title>
  157.   </head>
  158.   <body>
  159. <div class="row align-items-center justify-content-center">
  160. <div id="search">
  161.     <center><form class="form-inline" method="POST">
  162.   <div class="form-group mb-2">
  163.     <label for="staticEmail2" class="sr-only">Email</label>
  164.     <input type="text" readonly class="form-control-plaintext" id="staticEmail2" value="Найти торренты файлы!">
  165.   </div>
  166.   <div class="form-group mx-sm-3 mb-2">
  167.     <label for="inputPassword2" id="inputlg" class="sr-only">Password</label>
  168.     <input type="text" class="form-control" name="query" style="width: 500px" id="inputPassword2" placeholder="Текст.. .">
  169.   </div>
  170.   <button type="submit" name="submit" class="btn btn-primary mb-2">Найти торренты</button>
  171. </form></center>
  172. </div>
  173. </div>
  174.    <table class="table">
  175.   <thead>
  176.     <tr>
  177.       <th scope="col">#</th>
  178.       <th scope="col">Имя торрента</th>
  179.       <th scope="col">Источник</th>
  180.       <th scope="col">Размер</th>
  181.       <th scope="col">Seed</th>
  182.       <th scope="col">Leechers</th>
  183.       <th scope="col">Дата</th>
  184.       <th scope="col">Скачать</th>
  185.     </tr>
  186.   </thead>
  187.   <tbody>
  188. <?foreach ($list['rut'] as $key => $r):?>
  189. <tr>
  190.       <th scope="row"><?=$key;?></th>
  191.       <td><?=$r['title'];?></td>
  192.       <td><img src="/favicon.ico" /></td>
  193.       <td><?=$r['size'];?></td>
  194.       <td><?=$r['seed'];?></td>
  195.       <td><?=$r['leech'];?></td>
  196.       <td><?=$r['date'];?></td>
  197.       <td><?=$r['url'];?></td>
  198.           </tr>
  199.   <?php endforeach;?>
  200.   <?foreach ($list['nnm'] as $key => $r):?>
  201. <tr>
  202.       <th scope="row"><?=$key;?></th>
  203.       <td><?=$r['title'];?></td>
  204.       <td><img src="/favicon2.ico" /></td>
  205.       <td><?=$r['size'];?></td>
  206.       <td><?=$r['seed'];?></td>
  207.       <td><?=$r['leech'];?></td>
  208.       <td><?=$r['date'];?></td>
  209.       <td><?=$r['url'];?></td>
  210.           </tr>
  211.   <?php endforeach;?>
  212.   </tbody>
  213. </table>
  214.  
  215.     <!-- Optional JavaScript -->
  216.     <!-- jQuery first, then Popper.js, then Bootstrap JS -->
  217.     <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
  218.     <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
  219.     <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
  220.   </body>
  221. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement