DemonoidBridge.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 for the keywords (in all categories or
  7. a specific category). You can put several keywords separated by a semicolon
  8. (e.g. "one show;another show"). Searches can by done in a specific category;
  9. category number must be specified. (All=0, Movies=1, Music=2, TV=3, Games=4,
  10. Applications=5, Pictures=8, Anime=9, Comics=10, Books=11 Music Videos=8,
  11. Audio Books=17). User feed takes the Uploader ID number (not uploader name)
  12. as keyword. Uploader ID is found by clicking on uploader, clicking on
  13. "View this user\'s torrents", and copying the number after "uid=". An entire
  14. category feed is accomplished by leaving "keywords" box blank and using the
  15. corresponding category number.';
  16. const PARAMETERS = array( array(
  17. 'q' => array(
  18. 'name' => 'keywords/user ID/category, separated by semicolons',
  19. 'exampleValue' => 'first list;second list;…',
  20. 'required' => true
  21. ),
  22. 'crit' => array(
  23. 'type' => 'list',
  24. 'name' => 'Feed type',
  25. 'values' => array(
  26. 'search' => 'search',
  27. 'category' => 'cat',
  28. 'user' => 'usr'
  29. )
  30. ),
  31. 'catCheck' => array(
  32. 'type' => 'checkbox',
  33. 'name' => 'Specify category for keyword search ?',
  34. ),
  35. 'cat' => array(
  36. 'name' => 'Category number',
  37. ),
  38. ));
  39. public function collectData() {
  40. $catBool = $this->getInput('catCheck');
  41. if($catBool) {
  42. $catNum = $this->getInput('cat');
  43. }
  44. $critList = $this->getInput('crit');
  45. $keywordsList = explode(';', $this->getInput('q'));
  46. foreach($keywordsList as $keywords) {
  47. switch($critList) {
  48. case 'search':
  49. if($catBool == false) {
  50. $html = file_get_contents(
  51. self::URI .
  52. 'files/?category=0&subcategory=All&quality=All&seeded=2&external=2&query=' .
  53. urlencode($keywords) . #not rawurlencode so space -> '+'
  54. '&uid=0&sort='
  55. ) or returnServerError('Could not request Demonoid.');
  56. } else {
  57. $html = file_get_contents(
  58. self::URI .
  59. 'files/?category=' .
  60. rawurlencode($catNum) .
  61. '&subcategory=All&quality=All&seeded=2&external=2&query=' .
  62. urlencode($keywords) . #not rawurlencode so space -> '+'
  63. '&uid=0&sort='
  64. ) or returnServerError('Could not request Demonoid.');
  65. }
  66. break;
  67. case 'usr':
  68. $html = file_get_contents(
  69. self::URI .
  70. 'files/?uid=' .
  71. rawurlencode($keywords) .
  72. '&seeded=2'
  73. ) or returnServerError('Could not request Demonoid.');
  74. break;
  75. case 'cat':
  76. $html = file_get_contents(
  77. self::URI .
  78. 'files/?uid=0&category=' .
  79. rawurlencode($keywords) .
  80. '&subcategory=0&language=0&seeded=2&quality=0&query=&sort='
  81. ) or returnServerError('Could not request Demonoid.');
  82. break;
  83. }
  84. if(preg_match('~No torrents found~', $html)) {
  85. returnServerError('No result for query ' . $keywords);
  86. }
  87. $bigTable = explode('<!-- start torrent list -->', $html)[1];
  88. $last50 = explode('<!-- end torrent list -->', $bigTable)[0];
  89. $dateChunk = explode('added_today', $last50);
  90. $item = array ();
  91. for($block = 1;$block < count($dateChunk);$block++) {
  92. preg_match('~(?<=>Add).*?(?=<)~', $dateChunk[$block], $dateStr);
  93. if(preg_match('~today~', $dateStr[0])) {
  94. date_default_timezone_set('UTC');
  95. $timestamp = mktime(0, 0, 0, gmdate('n'), gmdate('j'), gmdate('Y'));
  96. } else {
  97. preg_match('~(?<=ed on ).*\d+~', $dateStr[0], $fullDateStr);
  98. date_default_timezone_set('UTC');
  99. $dateObj = strptime($fullDateStr[0], '%A, %b %d, %Y');
  100. $timestamp = mktime(0, 0, 0, $dateObj['tm_mon'] + 1, $dateObj['tm_mday'], 1900 + $dateObj['tm_year']);
  101. }
  102. $itemsChunk = explode('<!-- tstart -->', $dateChunk[$block]);
  103. for($items = 1;$items < count($itemsChunk);$items++) {
  104. $item = array();
  105. $cols = explode('<td', $itemsChunk[$items]);
  106. preg_match('~(?<=href=\"/).*?(?=\")~', $cols[1], $matches);
  107. $item['id'] = self::URI . $matches[0];
  108. preg_match('~(?<=href=\").*?(?=\")~', $cols[4], $matches);
  109. $item['uri'] = $matches[0];
  110. $item['timestamp'] = $timestamp;
  111. preg_match('~(?<=href=\"/users/).*?(?=\")~', $cols[3], $matches);
  112. $item['author'] = $matches[0];
  113. preg_match('~(?<=/\">).*?(?=</a>)~', $cols[1], $matches);
  114. $item['title'] = $matches[0];
  115. preg_match('~(?<=green\">)\d+(?=</font>)~', $cols[8], $matches);
  116. $item['seeders'] = $matches[0];
  117. preg_match('~(?<=red\">)\d+(?=</font>)~', $cols[9], $matches);
  118. $item['leechers'] = $matches[0];
  119. preg_match('~(?<=>).*?(?=</td>)~', $cols[5], $matches);
  120. $item['size'] = $matches[0];
  121. $item['content'] = 'Uploaded by ' . $item['author']
  122. . ' , Size ' . $item['size']
  123. . '<br>seeders: '
  124. . $item['seeders']
  125. . ' | leechers: '
  126. . $item['leechers']
  127. . '<br><a href="'
  128. . $item['id']
  129. . '">info page</a>';
  130. if(isset($item['title']))
  131. $this->items[] = $item;
  132. }
  133. }
  134. }
  135. }
  136. }