Torrent9Bridge.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. class Torrent9Bridge extends BridgeAbstract {
  3. const MAINTAINER = 'lagaisse';
  4. const NAME = 'Torrent9 Bridge';
  5. const URI = 'http://www.torrent9.biz';
  6. const CACHE_TIMEOUT = 86400; // 24h = 86400s
  7. const DESCRIPTION = 'Returns latest torrents';
  8. const PAGE_SERIES = 'torrents_series';
  9. const PAGE_SERIES_VOSTFR = 'torrents_series_vostfr';
  10. const PAGE_SERIES_FR = 'torrents_series_french';
  11. const PARAMETERS = array(
  12. 'From search' => array(
  13. 'q' => array(
  14. 'name' => 'Search',
  15. 'required' => true,
  16. 'title' => 'Type your search'
  17. )
  18. ),
  19. 'By page' => array(
  20. 'page' => array(
  21. 'name' => 'Page',
  22. 'type' => 'list',
  23. 'required' => false,
  24. 'values' => array(
  25. 'Series' => self::PAGE_SERIES,
  26. 'Series VOST' => self::PAGE_SERIES_VOSTFR,
  27. 'Series FR' => self::PAGE_SERIES_FR,
  28. ),
  29. 'defaultValue' => self::PAGE_SERIES
  30. )
  31. )
  32. );
  33. public function collectData(){
  34. if($this->queriedContext === 'From search') {
  35. $request = str_replace(' ', '-', trim($this->getInput('q')));
  36. $page = self::URI . '/search_torrent/' . urlencode($request) . '.html';
  37. } else {
  38. $request = $this->getInput('page');
  39. $page = self::URI . '/' . $request . '.html';
  40. }
  41. $html = getSimpleHTMLDOM($page)
  42. or returnServerError('No results for this query.');
  43. foreach($html->find('table', 0)->find('tr') as $episode) {
  44. if($episode->parent->tag == 'tbody') {
  45. $urlepisode = self::URI . $episode->find('a', 0)->getAttribute('href');
  46. //30 years = forever
  47. $htmlepisode = getSimpleHTMLDOMCached($urlepisode, 86400 * 366 * 30);
  48. $item = array();
  49. $item['author'] = $episode->find('a', 0)->text();
  50. $item['title'] = $episode->find('a', 0)->text();
  51. $item['id'] = $episode->find('a', 0)->getAttribute('href');
  52. $item['pubdate'] = $this->getCachedDate($urlepisode);
  53. $textefiche = $htmlepisode->find('.movie-information', 0)->find('p', 1);
  54. if(isset($textefiche)) {
  55. $item['content'] = $textefiche->text();
  56. } else {
  57. $p = $htmlepisode->find('.movie-information', 0)->find('p');
  58. if(!empty($p)) {
  59. $item['content'] = $htmlepisode->find('.movie-information', 0)->find('p', 0)->text();
  60. }
  61. }
  62. $item['id'] = $episode->find('a', 0)->getAttribute('href');
  63. $item['uri'] = self::URI . $htmlepisode->find('.download', 0)->getAttribute('href');
  64. $this->items[] = $item;
  65. }
  66. }
  67. }
  68. public function getName(){
  69. if(!is_null($this->getInput('q'))) {
  70. return $this->getInput('q') . ' : ' . self::NAME;
  71. }
  72. return parent::getName();
  73. }
  74. private function getCachedDate($url){
  75. debugMessage('getting pubdate from url ' . $url . '');
  76. // Initialize cache
  77. $cache = Cache::create('FileCache');
  78. $cache->setPath(CACHE_DIR . '/pages');
  79. $params = [$url];
  80. $cache->setParameters($params);
  81. // Get cachefile timestamp
  82. $time = $cache->getTime();
  83. return ($time !== false ? $time : time());
  84. }
  85. }