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.

torrent.php 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. #declare(strict_types=1);
  3. require_once SERVER_ROOT.'/sections/torrents/functions.php';
  4. $TorrentID = (int) $_GET['id'];
  5. $TorrentHash = (string) $_GET['hash'];
  6. if ($TorrentID && $TorrentHash) {
  7. json_die('failure', 'bad parameters');
  8. }
  9. if ($TorrentHash) {
  10. if (!is_valid_torrenthash($TorrentHash)) {
  11. json_die('failure', 'bad hash parameter');
  12. } else {
  13. $TorrentID = (int) torrenthash_to_torrentid($TorrentHash);
  14. if (!$TorrentID) {
  15. json_die('failure', 'bad hash parameter');
  16. }
  17. }
  18. }
  19. if ($TorrentID <= 0) {
  20. json_die('failure', 'bad id parameter');
  21. }
  22. $TorrentCache = get_torrent_info($TorrentID, true, 0, true, true);
  23. if (!$TorrentCache) {
  24. json_die('failure', 'bad id parameter');
  25. }
  26. list($TorrentDetails, $TorrentList) = $TorrentCache;
  27. if (!isset($TorrentList[$TorrentID])) {
  28. json_die('failure', 'bad id parameter');
  29. }
  30. $GroupID = $TorrentDetails['ID'];
  31. $Artists = Artists::get_artist($GroupID);
  32. if ($TorrentDetails['category_id'] === 0) {
  33. $CategoryName = 'Unknown';
  34. } else {
  35. $CategoryName = $Categories[$TorrentDetails['category_id'] - 1];
  36. }
  37. $TagList = explode('|', $TorrentDetails['GROUP_CONCAT(DISTINCT tags.Name SEPARATOR \'|\')']);
  38. $JsonTorrentDetails = [
  39. 'description' => Text::full_format($TorrentDetails['description']),
  40. 'picture' => $TorrentDetails['picture'],
  41. 'id' => (int) $TorrentDetails['id'],
  42. 'title' => $TorrentDetails['title'],
  43. 'subject' => $TorrentDetails['subject'],
  44. 'object' => $TorrentDetails['object'],
  45. 'authors' => $Artists,
  46. 'year' => (int) $TorrentDetails['published'],
  47. 'identifier' => $TorrentDetails['identifier'],
  48. 'categoryId' => (int) $TorrentDetails['category_id'],
  49. 'icategoryName' => $CategoryName,
  50. 'timestamp' => $TorrentDetails['timestamp'],
  51. 'bookmarked' => Bookmarks::has_bookmarked('torrent', $GroupID),
  52. 'tagList' => $TagList
  53. ];
  54. $Torrent = $TorrentList[$TorrentID];
  55. $Reports = Torrents::get_reports($TorrentID);
  56. $Torrent['Reported'] = (count($Reports) > 0);
  57. // Convert file list back to the old format
  58. $FileList = explode("\n", $Torrent['FileList']);
  59. foreach ($FileList as &$File) {
  60. $File = Torrents::filelist_old_format($File);
  61. }
  62. unset($File);
  63. $FileList = implode('|||', $FileList);
  64. $Userinfo = Users::user_info($Torrent['UserID']);
  65. $JsonTorrentList[] = [
  66. 'id' => (int) $Torrent['ID'],
  67. 'infoHash' => $Torrent['InfoHash'],
  68. 'platform' => $Torrent['Media'],
  69. 'format' => $Torrent['Container'],
  70. 'license' => $Torrent['Codec'],
  71. 'scope' => $Torrent['Resolution'],
  72. 'annotated' => (bool) $Torrent['Censored'],
  73. 'archive' => $Torrent['Archive'],
  74. 'fileCount' => (int) $Torrent['FileCount'],
  75. 'size' => (int) $Torrent['Size'],
  76. 'seeders' => (int) $Torrent['Seeders'],
  77. 'leechers' => (int) $Torrent['Leechers'],
  78. 'snatched' => (int) $Torrent['Snatched'],
  79. 'freeTorrent' => ($Torrent['FreeTorrent'] == 1),
  80. 'reported' => (bool) $Torrent['Reported'],
  81. 'time' => $Torrent['Time'],
  82. 'description' => $Torrent['Description'],
  83. 'fileList' => $FileList,
  84. 'filePath' => $Torrent['FilePath'],
  85. 'userId' => (int) ($Torrent['Anonymous'] ? 0 : $Torrent['UserID']),
  86. 'username' => ($Torrent['Anonymous'] ? 'Anonymous' : $Userinfo['Username'])
  87. ];
  88. json_die('success', ['group' => $JsonTorrentDetails, 'torrent' => array_pop($JsonTorrentList)]);