T411Bridge.php 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. class T411Bridge extends BridgeAbstract {
  3. public function loadMetadatas() {
  4. $this->maintainer = 'ORelio';
  5. $this->name = 'T411 Bridge';
  6. $this->uri = 'https://t411.ch/';
  7. $this->description = 'Returns the 10 newest torrents with specified search terms <br /> Use url part after "?" mark when using their search engine.';
  8. $this->parameters[] = array(
  9. 'search'=>array(
  10. 'name'=>'Search criteria',
  11. 'required'=>true
  12. )
  13. );
  14. }
  15. public function collectData(array $param) {
  16. //Utility function for retrieving text based on start and end delimiters
  17. function ExtractFromDelimiters($string, $start, $end) {
  18. if (strpos($string, $start) !== false) {
  19. $section_retrieved = substr($string, strpos($string, $start) + strlen($start));
  20. $section_retrieved = substr($section_retrieved, 0, strpos($section_retrieved, $end));
  21. return $section_retrieved;
  22. } return false;
  23. }
  24. //Ensure proper parameters have been provided
  25. if (empty($param['search'])) {
  26. $this->returnClientError('You must specify a search criteria');
  27. }
  28. //Retrieve torrent listing from search results, which does not contain torrent description
  29. $url = $this->uri.'torrents/search/?'.$param['search'].'&order=added&type=desc';
  30. $html = $this->getSimpleHTMLDOM($url) or $this->returnServerError('Could not request t411: '.$url);
  31. $results = $html->find('table.results', 0);
  32. if (is_null($results))
  33. $this->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 && !is_object($element->find('th', 0))) {
  39. //Requests are rate-limited
  40. usleep(500000); //So we need to wait (500ms)
  41. //Retrieve data from RSS entry
  42. $item_uri = $this->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. if ($item_html = $this->getSimpleHTMLDOM($item_uri)) {
  47. //Retrieve data from page contents
  48. $item_desc = $item_html->find('div.description', 0);
  49. $item_author = $item_html->find('a.profile', 0)->innertext;
  50. //Cleanup advertisments
  51. $divs = explode('<div class="align-center">', $item_desc->innertext);
  52. $item_desc = '';
  53. foreach ($divs as $text)
  54. if (strpos($text, 'adprovider.adlure.net') === false)
  55. $item_desc = $item_desc.'<div class="align-center">'.$text;
  56. $item_desc = preg_replace('/<h2 class="align-center">LIENS DE T..?L..?CHARGEMENT<\/h2>/i', '', $item_desc);
  57. //Build and add final item
  58. $item = array();
  59. $item['uri'] = $item_uri;
  60. $item['title'] = $item_title;
  61. $item['author'] = $item_author;
  62. $item['timestamp'] = $item_date;
  63. $item['content'] = $item_desc;
  64. $this->items[] = $item;
  65. $limit++;
  66. }
  67. }
  68. }
  69. }
  70. }