T411Bridge.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. class T411Bridge extends BridgeAbstract {
  3. const MAINTAINER = 'ORelio';
  4. const NAME = 'T411 Bridge';
  5. const URI = 'https://www.t411.li/';
  6. const DESCRIPTION = 'Returns the 10 newest torrents with specified search
  7. terms <br /> Use url part after "?" mark when using their search engine.';
  8. const PARAMETERS = array( array(
  9. 'search' => array(
  10. 'name' => 'Search criteria',
  11. 'required' => true
  12. )
  13. ));
  14. public function collectData(){
  15. //Utility function for retrieving text based on start and end delimiters
  16. function extractFromDelimiters($string, $start, $end){
  17. if(strpos($string, $start) !== false){
  18. $section_retrieved = substr($string, strpos($string, $start) + strlen($start));
  19. $section_retrieved = substr($section_retrieved, 0, strpos($section_retrieved, $end));
  20. return $section_retrieved;
  21. }
  22. return false;
  23. }
  24. //Retrieve torrent listing from search results, which does not contain torrent description
  25. $url = self::URI
  26. . 'torrents/search/?search='
  27. . urlencode($this->getInput('search'))
  28. . '&order=added&type=desc';
  29. $html = getSimpleHTMLDOM($url)
  30. or returnServerError('Could not request t411: ' . $url);
  31. $results = $html->find('table.results', 0);
  32. if (is_null($results))
  33. returnServerError('No results from t411: ' . $url);
  34. $limit = 0;
  35. //Process each item individually
  36. foreach($results->find('tr') as $element){
  37. //Limit total amount of requests and ignore table header
  38. if($limit >= 10){
  39. break;
  40. }
  41. if(is_object($element->find('th', 0))){
  42. continue;
  43. }
  44. //Requests are rate-limited
  45. usleep(500000); //So we need to wait (500ms)
  46. //Retrieve data from RSS entry
  47. $item_uri = self::URI
  48. . 'torrents/details/?id='
  49. . extractFromDelimiters($element->find('a.nfo', 0)->outertext, '?id=', '"');
  50. $item_title = extractFromDelimiters($element->outertext, '" title="', '"');
  51. $item_date = strtotime($element->find('dd', 0)->plaintext);
  52. //Retrieve full description from torrent page
  53. $item_html = getSimpleHTMLDOM($item_uri);
  54. if(!$item_html){
  55. continue;
  56. }
  57. //Retrieve data from page contents
  58. $item_desc = $item_html->find('div.description', 0);
  59. $item_author = $item_html->find('a.profile', 0)->innertext;
  60. //Cleanup advertisments
  61. $divs = explode('<div class="align-center">', $item_desc->innertext);
  62. $item_desc = '';
  63. foreach ($divs as $text)
  64. if (strpos($text, 'adprovider.adlure.net') === false)
  65. $item_desc = $item_desc . '<div class="align-center">' . $text;
  66. $item_desc = preg_replace('/<h2 class="align-center">LIENS DE T..?L..?CHARGEMENT<\/h2>/i', '', $item_desc);
  67. //Build and add final item
  68. $item = array();
  69. $item['uri'] = $item_uri;
  70. $item['title'] = $item_title;
  71. $item['author'] = $item_author;
  72. $item['timestamp'] = $item_date;
  73. $item['content'] = $item_desc;
  74. $this->items[] = $item;
  75. $limit++;
  76. }
  77. }
  78. }