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 3.4KB

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