nyaa.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. function get_nyaa_results($query)
  3. {
  4. global $config;
  5. $url = "https://nyaa.si/?q=$query";
  6. $response = request($url);
  7. $xpath = get_xpath($response);
  8. $results = array();
  9. foreach($xpath->query("//tbody/tr") as $result)
  10. {
  11. $name = $xpath->evaluate(".//td[@colspan='2']//a[not(contains(@class, 'comments'))]/@title", $result)[0]->textContent;
  12. $centered = $xpath->evaluate(".//td[@class='text-center']", $result);
  13. $magnet = $xpath->evaluate(".//a[2]/@href", $centered[0])[0]->textContent;
  14. $magnet_without_tracker = explode("&tr=", $magnet)[0];
  15. $magnet = $magnet_without_tracker . $config->bittorent_trackers;
  16. $size = $centered[1]->textContent;
  17. $seeders = $centered[3]->textContent;
  18. $leechers = $centered[4]->textContent;
  19. array_push($results,
  20. array (
  21. "name" => $name,
  22. "seeders" => (int) $seeders,
  23. "leechers" => (int) $leechers,
  24. "magnet" => $magnet,
  25. "size" => $size,
  26. "source" => "nyaa.si"
  27. )
  28. );
  29. }
  30. return $results;
  31. }
  32. ?>