Oppaitime'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 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?
  2. //TODO: freeleech in ratio hit calculations, in addition to a warning of whats freeleech in the Summary.txt
  3. /*
  4. This page is something of a hack so those
  5. easily scared off by funky solutions, don't
  6. touch it! :P
  7. There is a central problem to this page, it's
  8. impossible to order before grouping in SQL, and
  9. it's slow to run sub queries, so we had to get
  10. creative for this one.
  11. The solution I settled on abuses the way
  12. $DB->to_array() works. What we've done, is
  13. backwards ordering. The results returned by the
  14. query have the best one for each GroupID last,
  15. and while to_array traverses the results, it
  16. overwrites the keys and leaves us with only the
  17. desired result. This does mean however, that
  18. the SQL has to be done in a somewhat backwards
  19. fashion.
  20. Thats all you get for a disclaimer, just
  21. remember, this page isn't for the faint of
  22. heart. -A9
  23. SQL template:
  24. SELECT
  25. CASE
  26. WHEN t.Format = 'MP3' AND t.Encoding = 'V0 (VBR)'
  27. THEN 1
  28. WHEN t.Format = 'MP3' AND t.Encoding = 'V2 (VBR)'
  29. THEN 2
  30. ELSE 100
  31. END AS Rank,
  32. t.GroupID,
  33. t.Media,
  34. t.Format,
  35. t.Encoding,
  36. IF(t.Year = 0, tg.Year, t.Year),
  37. tg.Name,
  38. a.Name,
  39. t.Size
  40. FROM torrents AS t
  41. INNER JOIN torrents_group AS tg ON tg.ID = t.GroupID AND tg.CategoryID = '1'
  42. INNER JOIN artists_group AS a ON a.ArtistID = tg.ArtistID AND a.ArtistID = '59721'
  43. ORDER BY t.GroupID ASC, Rank DESC, t.Seeders ASC
  44. */
  45. if (
  46. !isset($_REQUEST['artistid'])
  47. || !isset($_REQUEST['preference'])
  48. || !is_number($_REQUEST['preference'])
  49. || !is_number($_REQUEST['artistid'])
  50. || $_REQUEST['preference'] > 2
  51. || count($_REQUEST['list']) === 0
  52. ) {
  53. error(0);
  54. }
  55. if (!check_perms('zip_downloader')) {
  56. error(403);
  57. }
  58. $Preferences = array('RemasterTitle DESC', 'Seeders ASC', 'Size ASC');
  59. $ArtistID = $_REQUEST['artistid'];
  60. $Preference = $Preferences[$_REQUEST['preference']];
  61. $DB->query("
  62. SELECT Name
  63. FROM artists_group
  64. WHERE ArtistID = '$ArtistID'");
  65. list($ArtistName) = $DB->next_record(MYSQLI_NUM, false);
  66. $DB->query("
  67. SELECT GroupID, Importance
  68. FROM torrents_artists
  69. WHERE ArtistID = '$ArtistID'");
  70. if (!$DB->has_results()) {
  71. error(404);
  72. }
  73. $Releases = $DB->to_array('GroupID', MYSQLI_ASSOC, false);
  74. $GroupIDs = array_keys($Releases);
  75. $SQL = 'SELECT CASE ';
  76. foreach ($_REQUEST['list'] as $Priority => $Selection) {
  77. if (!is_number($Priority)) {
  78. continue;
  79. }
  80. $SQL .= 'WHEN ';
  81. switch ($Selection) {
  82. case '00': $SQL .= "t.Format = 'MP3' AND t.Encoding = 'V0 (VBR)'"; break;
  83. case '01': $SQL .= "t.Format = 'MP3' AND t.Encoding = 'APX (VBR)'"; break;
  84. case '02': $SQL .= "t.Format = 'MP3' AND t.Encoding = '256 (VBR)'"; break;
  85. case '03': $SQL .= "t.Format = 'MP3' AND t.Encoding = 'V1 (VBR)'"; break;
  86. case '10': $SQL .= "t.Format = 'MP3' AND t.Encoding = '224 (VBR)'"; break;
  87. case '11': $SQL .= "t.Format = 'MP3' AND t.Encoding = 'V2 (VBR)'"; break;
  88. case '12': $SQL .= "t.Format = 'MP3' AND t.Encoding = 'APS (VBR)'"; break;
  89. case '13': $SQL .= "t.Format = 'MP3' AND t.Encoding = '192 (VBR)'"; break;
  90. case '20': $SQL .= "t.Format = 'MP3' AND t.Encoding = '320'"; break;
  91. case '21': $SQL .= "t.Format = 'MP3' AND t.Encoding = '256'"; break;
  92. case '22': $SQL .= "t.Format = 'MP3' AND t.Encoding = '224'"; break;
  93. case '23': $SQL .= "t.Format = 'MP3' AND t.Encoding = '192'"; break;
  94. case '30': $SQL .= "t.Format = 'FLAC' AND t.Encoding = '24bit Lossless' AND t.Media = 'Vinyl'"; break;
  95. case '31': $SQL .= "t.Format = 'FLAC' AND t.Encoding = '24bit Lossless' AND t.Media = 'DVD'"; break;
  96. case '32': $SQL .= "t.Format = 'FLAC' AND t.Encoding = '24bit Lossless' AND t.Media = 'SACD'"; break;
  97. case '33': $SQL .= "t.Format = 'FLAC' AND t.Encoding = '24bit Lossless' AND t.Media = 'WEB'"; break;
  98. case '34': $SQL .= "t.Format = 'FLAC' AND t.Encoding = 'Lossless' AND HasLog = '1' AND LogScore = '100' AND HasCue = '1'"; break;
  99. case '35': $SQL .= "t.Format = 'FLAC' AND t.Encoding = 'Lossless' AND HasLog = '1' AND LogScore = '100'"; break;
  100. case '36': $SQL .= "t.Format = 'FLAC' AND t.Encoding = 'Lossless' AND HasLog = '1'"; break;
  101. case '37': $SQL .= "t.Format = 'FLAC' AND t.Encoding = 'Lossless'"; break;
  102. case '40': $SQL .= "t.Format = 'DTS'"; break;
  103. case '42': $SQL .= "t.Format = 'AAC' AND t.Encoding = '320'"; break;
  104. case '43': $SQL .= "t.Format = 'AAC' AND t.Encoding = '256'"; break;
  105. case '44': $SQL .= "t.Format = 'AAC' AND t.Encoding = 'q5.5'"; break;
  106. case '45': $SQL .= "t.Format = 'AAC' AND t.Encoding = 'q5'"; break;
  107. case '46': $SQL .= "t.Format = 'AAC' AND t.Encoding = '192'"; break;
  108. default: error(0);
  109. }
  110. $SQL .= " THEN $Priority ";
  111. }
  112. $SQL .= "
  113. ELSE 100
  114. END AS Rank,
  115. t.GroupID,
  116. t.ID AS TorrentID,
  117. t.Media,
  118. t.Format,
  119. t.Encoding,
  120. tg.ReleaseType,
  121. IF(t.RemasterYear = 0, tg.Year, t.RemasterYear) AS Year,
  122. tg.Name,
  123. t.Size
  124. FROM torrents AS t
  125. JOIN torrents_group AS tg ON tg.ID = t.GroupID AND tg.CategoryID = '1' AND tg.ID IN (".implode(',', $GroupIDs).")
  126. ORDER BY t.GroupID ASC, Rank DESC, t.$Preference";
  127. $DownloadsQ = $DB->query($SQL);
  128. $Collector = new TorrentsDL($DownloadsQ, $ArtistName);
  129. while (list($Downloads, $GroupIDs) = $Collector->get_downloads('GroupID')) {
  130. $Artists = Artists::get_artists($GroupIDs);
  131. $TorrentIDs = array_keys($GroupIDs);
  132. foreach ($TorrentIDs as $TorrentID) {
  133. $TorrentFile = file_get_contents(TORRENT_STORE.$TorrentID.'.torrent');
  134. $GroupID = $GroupIDs[$TorrentID];
  135. $Download =& $Downloads[$GroupID];
  136. $Download['Artist'] = Artists::display_artists($Artists[$Download['GroupID']], false, true, false);
  137. if ($Download['Rank'] == 100) {
  138. $Collector->skip_file($Download);
  139. continue;
  140. }
  141. if ($Releases[$GroupID]['Importance'] == 1) {
  142. $ReleaseTypeName = $ReleaseTypes[$Download['ReleaseType']];
  143. } elseif ($Releases[$GroupID]['Importance'] == 2) {
  144. $ReleaseTypeName = 'Guest Appearance';
  145. } elseif ($Releases[$GroupID]['Importance'] == 3) {
  146. $ReleaseTypeName = 'Remixed By';
  147. }
  148. $Collector->add_file($TorrentFile, $Download, $ReleaseTypeName);
  149. unset($Download);
  150. }
  151. }
  152. $Collector->finalize();
  153. $Settings = array(implode(':', $_REQUEST['list']), $_REQUEST['preference']);
  154. if (!isset($LoggedUser['Collector']) || $LoggedUser['Collector'] != $Settings) {
  155. Users::update_site_options($LoggedUser['ID'], array('Collector' => $Settings));
  156. }
  157. define('SKIP_NO_CACHE_HEADERS', 1);
  158. ?>