BioTorrents.de’s version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

download.php 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /*
  3. This page is something of a hack so those
  4. easily scared off by funky solutions, don't
  5. touch it! :P
  6. There is a central problem to this page, it's
  7. impossible to order before grouping in SQL, and
  8. it's slow to run sub queries, so we had to get
  9. creative for this one.
  10. The solution I settled on abuses the way
  11. $DB->to_array() works. What we've done, is
  12. backwards ordering. The results returned by the
  13. query have the best one for each GroupID last,
  14. and while to_array traverses the results, it
  15. overwrites the keys and leaves us with only the
  16. desired result. This does mean however, that
  17. the SQL has to be done in a somewhat backwards
  18. fashion.
  19. Thats all you get for a disclaimer, just
  20. remember, this page isn't for the faint of
  21. heart. -A9
  22. */
  23. if (
  24. !isset($_REQUEST['collageid'])
  25. || !isset($_REQUEST['preference'])
  26. || !is_number($_REQUEST['preference'])
  27. || !is_number($_REQUEST['collageid'])
  28. || $_REQUEST['preference'] > 2
  29. || count($_REQUEST['list']) === 0
  30. ) {
  31. error(0);
  32. }
  33. if (!check_perms('zip_downloader')) {
  34. error(403);
  35. }
  36. $Preferences = array('RemasterTitle DESC', 'Seeders ASC', 'Size ASC');
  37. $CollageID = $_REQUEST['collageid'];
  38. $Preference = $Preferences[$_REQUEST['preference']];
  39. $DB->query("
  40. SELECT Name
  41. FROM collages
  42. WHERE ID = '$CollageID'");
  43. list($CollageName) = $DB->next_record(MYSQLI_NUM, false);
  44. $SQL = "
  45. SELECT
  46. t.`GroupID`,
  47. t.`ID` AS `TorrentID`,
  48. t.`Media`,
  49. t.`Format`,
  50. t.`Encoding`,
  51. IF(
  52. t.`RemasterYear` = 0,
  53. tg.`year`,
  54. t.`RemasterYear`
  55. ) AS `Year`,
  56. tg.`title`,
  57. t.`Size`
  58. FROM
  59. `torrents` AS t
  60. INNER JOIN `collages_torrents` AS c
  61. ON
  62. t.`GroupID` = c.`GroupID` AND c.`CollageID` = '$CollageID'
  63. INNER JOIN `torrents_group` AS tg
  64. ON
  65. tg.`id` = t.`GroupID` AND tg.`category_id` = '1'
  66. ORDER BY
  67. t.`GroupID` ASC,
  68. `Rank` DESC,
  69. t.$Preference
  70. ";
  71. $DownloadsQ = $DB->query($SQL);
  72. $Collector = new TorrentsDL($DownloadsQ, $CollageName);
  73. while (list($Downloads, $GroupIDs) = $Collector->get_downloads('GroupID')) {
  74. $Artists = Artists::get_artists($GroupIDs);
  75. $TorrentIDs = array_keys($GroupIDs);
  76. foreach ($TorrentIDs as $TorrentID) {
  77. file_get_contents(TORRENT_STORE.$TorrentID.'.torrent');
  78. $GroupID = $GroupIDs[$TorrentID];
  79. $Download =& $Downloads[$GroupID];
  80. $Download['Artist'] = Artists::display_artists($Artists[$Download['GroupID']], false, true, false);
  81. if ($Download['Rank'] == 100) {
  82. $Collector->skip_file($Download);
  83. continue;
  84. }
  85. $Collector->add_file($TorrentFile, $Download);
  86. unset($Download);
  87. }
  88. }
  89. $Collector->finalize();
  90. $Settings = array(implode(':', $_REQUEST['list']), $_REQUEST['preference']);
  91. if (!isset($LoggedUser['Collector']) || $LoggedUser['Collector'] != $Settings) {
  92. Users::update_site_options($LoggedUser['ID'], array('Collector' => $Settings));
  93. }