DemonoidBridge.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. class DemonoidBridge extends BridgeAbstract {
  3. const MAINTAINER = 'metaMMA';
  4. const NAME = 'Demonoid';
  5. const URI = 'https://www.demonoid.pw/';
  6. const DESCRIPTION = 'Returns results from search';
  7. const PARAMETERS = array(array(
  8. 'q' => array(
  9. 'name' => 'keywords',
  10. 'exampleValue' => 'keyword1 keyword2…',
  11. 'required' => true,
  12. ),
  13. 'category' => array(
  14. 'name' => 'Category',
  15. 'type' => 'list',
  16. 'values' => array(
  17. 'All' => 0,
  18. 'Movies' => 1,
  19. 'Music' => 2,
  20. 'TV' => 3,
  21. 'Games' => 4,
  22. 'Applications' => 5,
  23. 'Pictures' => 8,
  24. 'Anime' => 9,
  25. 'Comics' => 10,
  26. 'Books' => 11,
  27. 'Audiobooks' => 17
  28. )
  29. )
  30. ), array(
  31. 'catOnly' => array(
  32. 'name' => 'Category',
  33. 'type' => 'list',
  34. 'values' => array(
  35. 'All' => 0,
  36. 'Movies' => 1,
  37. 'Music' => 2,
  38. 'TV' => 3,
  39. 'Games' => 4,
  40. 'Applications' => 5,
  41. 'Pictures' => 8,
  42. 'Anime' => 9,
  43. 'Comics' => 10,
  44. 'Books' => 11,
  45. 'Audiobooks' => 17
  46. )
  47. )
  48. ), array(
  49. 'userid' => array(
  50. 'name' => 'user id',
  51. 'exampleValue' => '00000',
  52. 'required' => true,
  53. 'type' => 'number'
  54. ),
  55. 'category' => array(
  56. 'name' => 'Category',
  57. 'type' => 'list',
  58. 'values' => array(
  59. 'All' => 0,
  60. 'Movies' => 1,
  61. 'Music' => 2,
  62. 'TV' => 3,
  63. 'Games' => 4,
  64. 'Applications' => 5,
  65. 'Pictures' => 8,
  66. 'Anime' => 9,
  67. 'Comics' => 10,
  68. 'Books' => 11,
  69. 'Audiobooks' => 17
  70. )
  71. )
  72. )
  73. );
  74. public function collectData() {
  75. if(!empty($this->getInput('q'))) {
  76. $html = getSimpleHTMLDOM(
  77. self::URI .
  78. 'files/?category=' .
  79. rawurlencode($this->getInput('category')) .
  80. '&subcategory=All&quality=All&seeded=2&external=2&query=' .
  81. urlencode($this->getInput('q')) .
  82. '&uid=0&sort='
  83. ) or returnServerError('Could not request Demonoid.');
  84. } elseif(!empty($this->getInput('catOnly'))) {
  85. $html = getSimpleHTMLDOM(
  86. self::URI .
  87. 'files/?uid=0&category=' .
  88. rawurlencode($this->getInput('catOnly')) .
  89. '&subcategory=0&language=0&seeded=2&quality=0&query=&sort='
  90. ) or returnServerError('Could not request Demonoid.');
  91. } elseif(!empty($this->getInput('userid'))) {
  92. $html = getSimpleHTMLDOM(
  93. self::URI .
  94. 'files/?uid=' .
  95. rawurlencode($this->getInput('userid')) .
  96. '&seeded=2'
  97. ) or returnServerError('Could not request Demonoid.');
  98. } else {
  99. returnServerError('Invalid parameters !');
  100. }
  101. if(preg_match('~No torrents found~', $html)) {
  102. return;
  103. }
  104. $table = $html->find('td[class=ctable_content_no_pad]', 0);
  105. $cursorCount = 4;
  106. $elementCount = 0;
  107. while($elementCount != 40) {
  108. $elementCount++;
  109. $currentElement = $table->find('tr', $cursorCount);
  110. if(preg_match('~items total~', $currentElement)) {
  111. break;
  112. }
  113. $item = array();
  114. //Do we have a date ?
  115. if(preg_match('~Added.*?(.*)~', $currentElement->plaintext, $dateStr)) {
  116. if(preg_match('~today~', $dateStr[0])) {
  117. date_default_timezone_set('UTC');
  118. $timestamp = mktime(0, 0, 0, gmdate('n'), gmdate('j'), gmdate('Y'));
  119. } else {
  120. preg_match('~(?<=ed on ).*\d+~', $currentElement->plaintext, $fullDateStr);
  121. date_default_timezone_set('UTC');
  122. $dateObj = strptime($fullDateStr[0], '%A, %b %d, %Y');
  123. $timestamp = mktime(0, 0, 0, $dateObj['tm_mon'] + 1, $dateObj['tm_mday'], 1900 + $dateObj['tm_year']);
  124. }
  125. $cursorCount++;
  126. }
  127. $content = $table->find('tr', $cursorCount)->find('a', 1);
  128. $cursorCount++;
  129. $torrentInfo = $table->find('tr', $cursorCount);
  130. $item['timestamp'] = $timestamp;
  131. $item['title'] = $content->plaintext;
  132. $item['id'] = self::URI . $content->href;
  133. $item['uri'] = self::URI . $content->href;
  134. $item['author'] = $torrentInfo->find('a[class=user]', 0)->plaintext;
  135. $item['seeders'] = $torrentInfo->find('font[class=green]', 0)->plaintext;
  136. $item['leechers'] = $torrentInfo->find('font[class=red]', 0)->plaintext;
  137. $item['size'] = $torrentInfo->find('td', 3)->plaintext;
  138. $item['content'] = 'Uploaded by ' . $item['author']
  139. . ' , Size ' . $item['size']
  140. . '<br>seeders: '
  141. . $item['seeders']
  142. . ' | leechers: '
  143. . $item['leechers']
  144. . '<br><a href="'
  145. . $item['id']
  146. . '">info page</a>';
  147. $this->items[] = $item;
  148. $cursorCount++;
  149. }
  150. }
  151. }