YGGTorrentBridge.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /* This is a mashup of FlickrExploreBridge by sebsauvage and FlickrTagBridge
  3. * by erwang.providing the functionality of both in one.
  4. */
  5. class YGGTorrentBridge extends BridgeAbstract {
  6. const MAINTAINER = 'teromene';
  7. const NAME = 'Yggtorrent Bridge';
  8. const URI = 'https://yggtorrent.is';
  9. const DESCRIPTION = 'Returns torrent search from Yggtorrent';
  10. const PARAMETERS = array(
  11. array(
  12. 'cat' => array(
  13. 'name' => 'category',
  14. 'type' => 'list',
  15. 'values' => array(
  16. 'Toute les catégories' => 'all.all',
  17. 'Film/Vidéo - Toutes les sous-catégories' => '2145.all',
  18. 'Film/Vidéo - Animation' => '2145.2178',
  19. 'Film/Vidéo - Animation Série' => '2145.2179',
  20. 'Film/Vidéo - Concert' => '2145.2180',
  21. 'Film/Vidéo - Documentaire' => '2145.2181',
  22. 'Film/Vidéo - Émission TV' => '2145.2182',
  23. 'Film/Vidéo - Film' => '2145.2183',
  24. 'Film/Vidéo - Série TV' => '2145.2184',
  25. 'Film/Vidéo - Spectacle' => '2145.2185',
  26. 'Film/Vidéo - Sport' => '2145.2186',
  27. 'Film/Vidéo - Vidéo-clips' => '2145.2186',
  28. 'Audio - Toutes les sous-catégories' => '2139.all',
  29. 'Audio - Karaoké' => '2139.2147',
  30. 'Audio - Musique' => '2139.2148',
  31. 'Audio - Podcast Radio' => '2139.2150',
  32. 'Audio - Samples' => '2139.2149',
  33. 'Jeu vidéo - Toutes les sous-catégories' => '2142.all',
  34. 'Jeu vidéo - Autre' => '2142.2167',
  35. 'Jeu vidéo - Linux' => '2142.2159',
  36. 'Jeu vidéo - MacOS' => '2142.2160',
  37. 'Jeu vidéo - Microsoft' => '2142.2162',
  38. 'Jeu vidéo - Nintendo' => '2142.2163',
  39. 'Jeu vidéo - Smartphone' => '2142.2165',
  40. 'Jeu vidéo - Sony' => '2142.2164',
  41. 'Jeu vidéo - Tablette' => '2142.2166',
  42. 'Jeu vidéo - Windows' => '2142.2161',
  43. 'eBook - Toutes les sous-catégories' => '2140.all',
  44. 'eBook - Audio' => '2140.2151',
  45. 'eBook - Bds' => '2140.2152',
  46. 'eBook - Comics' => '2140.2153',
  47. 'eBook - Livres' => '2140.2154',
  48. 'eBook - Mangas' => '2140.2155',
  49. 'eBook - Presse' => '2140.2156',
  50. 'Emulation - Toutes les sous-catégories' => '2141.all',
  51. 'Emulation - Emulateurs' => '2141.2157',
  52. 'Emulation - Roms' => '2141.2158',
  53. 'GPS - Toutes les sous-catégories' => '2141.all',
  54. 'GPS - Applications' => '2141.2168',
  55. 'GPS - Cartes' => '2141.2169',
  56. 'GPS - Divers' => '2141.2170'
  57. )
  58. ),
  59. 'nom' => array(
  60. 'name' => 'Nom',
  61. 'description' => 'Nom du torrent',
  62. 'type' => 'text'
  63. ),
  64. 'description' => array(
  65. 'name' => 'Description',
  66. 'description' => 'Description du torrent',
  67. 'type' => 'text'
  68. ),
  69. 'fichier' => array(
  70. 'name' => 'Fichier',
  71. 'description' => 'Fichier du torrent',
  72. 'type' => 'text'
  73. ),
  74. 'uploader' => array(
  75. 'name' => 'Uploader',
  76. 'description' => 'Uploader du torrent',
  77. 'type' => 'text'
  78. ),
  79. )
  80. );
  81. public function collectData() {
  82. $catInfo = explode('.', $this->getInput('cat'));
  83. $category = $catInfo[0];
  84. $subcategory = $catInfo[1];
  85. $html = getSimpleHTMLDOM(self::URI . '/engine/search?name='
  86. . $this->getInput('nom')
  87. . '&description='
  88. . $this->getInput('description')
  89. . '&fichier='
  90. . $this->getInput('fichier')
  91. . '&file='
  92. . $this->getInput('uploader')
  93. . '&category='
  94. . $category
  95. . '&sub_category='
  96. . $subcategory
  97. . '&do=search&order=desc&sort=publish_date')
  98. or returnServerError('Unable to query Yggtorrent !');
  99. $count = 0;
  100. $results = $html->find('.results', 0);
  101. if(!$results) return;
  102. foreach($results->find('tr') as $row) {
  103. $count++;
  104. if($count == 1) continue;
  105. if($count == 12) break;
  106. $item = array();
  107. $item['timestamp'] = $row->find('.hidden', 1)->plaintext;
  108. $item['title'] = $row->find('a', 1)->plaintext;
  109. $torrentData = $this->collectTorrentData($row->find('a', 1)->href);
  110. $item['author'] = $torrentData['author'];
  111. $item['content'] = $torrentData['content'];
  112. $item['seeders'] = $row->find('td', 7)->plaintext;
  113. $item['leechers'] = $row->find('td', 8)->plaintext;
  114. $item['size'] = $row->find('td', 5)->plaintext;
  115. $this->items[] = $item;
  116. }
  117. }
  118. private function collectTorrentData($url) {
  119. //For weird reason, the link we get can be invalid, we fix it.
  120. $url_full = explode('/', $url);
  121. $url_full[4] = urlencode($url_full[4]);
  122. $url_full[5] = urlencode($url_full[5]);
  123. $url_full[6] = urlencode($url_full[6]);
  124. $url = implode('/', $url_full);
  125. $page = getSimpleHTMLDOM($url) or returnServerError('Unable to query Yggtorrent page !');
  126. $author = $page->find('.informations', 0)->find('a', 4)->plaintext;
  127. $content = $page->find('.default', 1);
  128. return array('author' => $author, 'content' => $content);
  129. }
  130. }