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.

redownload.php 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. #declare(strict_types=1);
  3. if (!empty($_GET['userid']) && is_number($_GET['userid'])) {
  4. $UserID = $_GET['userid'];
  5. } else {
  6. error(0);
  7. }
  8. if (!check_perms('zip_downloader')) {
  9. error(403);
  10. }
  11. $User = Users::user_info($UserID);
  12. $Perms = Permissions::get_permissions($User['PermissionID']);
  13. $UserClass = $Perms['Class'];
  14. list($UserID, $Username) = array_values($User);
  15. if (empty($_GET['type'])) {
  16. error(0);
  17. } else {
  18. switch ($_GET['type']) {
  19. case 'uploads':
  20. if (!check_paranoia('uploads', $User['Paranoia'], $UserClass, $UserID)) {
  21. error(403);
  22. }
  23. $SQL = "WHERE t.UserID = '$UserID'";
  24. $Month = "t.Time";
  25. break;
  26. case 'snatches':
  27. if (!check_paranoia('snatched', $User['Paranoia'], $UserClass, $UserID)) {
  28. error(403);
  29. }
  30. $SQL = "
  31. JOIN xbt_snatched AS x ON t.ID = x.fid
  32. WHERE x.uid = '$UserID'";
  33. $Month = "FROM_UNIXTIME(x.tstamp)";
  34. break;
  35. case 'seeding':
  36. if (!check_paranoia('seeding', $User['Paranoia'], $UserClass, $UserID)) {
  37. error(403);
  38. }
  39. $SQL = "
  40. JOIN xbt_files_users AS xfu ON t.ID = xfu.fid
  41. WHERE xfu.uid = '$UserID'
  42. AND xfu.remaining = 0";
  43. $Month = "FROM_UNIXTIME(xfu.mtime)";
  44. break;
  45. default:
  46. error(0);
  47. }
  48. }
  49. $DownloadsQ = $DB->query("
  50. SELECT
  51. t.ID AS TorrentID,
  52. DATE_FORMAT($Month, '%Y - %m') AS Month,
  53. t.GroupID,
  54. t.Media,
  55. t.Container,
  56. t.Codec,
  57. t.Resolution,
  58. t.Version,
  59. tg.Year,
  60. tg.Name,
  61. t.Size
  62. FROM torrents AS t
  63. JOIN torrents_group AS tg ON t.GroupID = tg.ID
  64. $SQL
  65. GROUP BY TorrentID");
  66. $Collector = new TorrentsDL($DownloadsQ, "$Username's ".ucfirst($_GET['type']));
  67. while (list($Downloads, $GroupIDs) = $Collector->get_downloads('TorrentID')) {
  68. $Artists = Artists::get_artists($GroupIDs);
  69. $TorrentIDs = array_keys($GroupIDs);
  70. foreach ($TorrentIDs as $TorrentID) {
  71. $TorrentFile = file_get_contents(TORRENT_STORE.$TorrentID.'.torrent');
  72. $Download =& $Downloads[$TorrentID];
  73. // unzip(1) corrupts files if an emdash is present. Replace them.
  74. $Download['Artist'] = str_replace('&ndash;', '-', Artists::display_artists($Artists[$Download['GroupID']], false, true, false));
  75. $Collector->add_file($TorrentFile, $Download, $Download['Month']);
  76. unset($Download);
  77. }
  78. }
  79. $Collector->finalize(false);