T411Bridge.php 3.2 KB

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