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.

group.php 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. #declare(strict_types=1);
  3. $ENV = ENV::go();
  4. require_once "$ENV->SERVER_ROOT/sections/torrents/functions.php";
  5. # Either id or hash
  6. $GroupID = (int) $_GET['id'];
  7. $TorrentHash = (string) $_GET['hash'];
  8. # Error if both supplied
  9. if ($GroupID && $TorrentHash) {
  10. json_die('failure', 'bad parameters');
  11. }
  12. # Get id from hash
  13. if ($TorrentHash) {
  14. if (!is_valid_torrenthash($TorrentHash)) {
  15. json_die('failure', 'bad hash parameter');
  16. } else {
  17. $GroupID = (int) torrenthash_to_groupid($TorrentHash);
  18. if (!$GroupID) {
  19. json_die('failure', 'bad hash parameter');
  20. }
  21. }
  22. }
  23. # Error if bad id
  24. if ($GroupID <= 0) {
  25. json_die('failure', 'bad id parameter');
  26. }
  27. $TorrentCache = get_group_info($GroupID, true, 0, true, true);
  28. if (!$TorrentCache) {
  29. json_die('failure', 'bad id parameter');
  30. }
  31. # Get torrent details (group, torrents, artists)
  32. list($TorrentDetails, $TorrentList) = $TorrentCache;
  33. $Artists = Artists::get_artist($GroupID);
  34. # Get category name if possible
  35. if ($TorrentDetails['category_id'] === 0) {
  36. $CategoryName = 'Unknown';
  37. } else {
  38. $CategoryName = $Categories[$TorrentDetails['category_id'] - 1];
  39. }
  40. # Get tag list (name and id)
  41. $TagIDs = explode('|', $TorrentDetails["GROUP_CONCAT(DISTINCT tags.`ID` SEPARATOR '|')"]);
  42. $TagNames= explode('|', $TorrentDetails["GROUP_CONCAT(DISTINCT tags.`Name` SEPARATOR '|')"]);
  43. $TagList = [];
  44. foreach ($TagIDs as $Key => $ID) {
  45. array_push(
  46. $TagList,
  47. [
  48. 'id' => $ID,
  49. 'name' => $TagNames[$Key],
  50. ]
  51. );
  52. }
  53. # Get citation list (doi and id)
  54. # todo: Update DB schema
  55. $Citations = [];
  56. foreach ($TorrentDetails['Screenshots'] as $Citation) {
  57. array_push(
  58. $Citations,
  59. [
  60. 'id' => $Citation['ID'],
  61. 'doi' => $Citation['URI'],
  62. #'timestamp' => $Citation['Time'],
  63. ]
  64. );
  65. }
  66. # Torrent group response
  67. # todo: Add seeding, leeching, snatched
  68. $JsonTorrentDetails = [
  69. 'id' => (int) $TorrentDetails['id'],
  70. 'identifier' => $TorrentDetails['identifier'],
  71. 'categoryId' => (int) $TorrentDetails['category_id'],
  72. 'categoryName' => $CategoryName,
  73. 'title' => $TorrentDetails['title'],
  74. 'subject' => $TorrentDetails['subject'],
  75. 'object' => $TorrentDetails['object'],
  76. 'authors' => $Artists,
  77. 'year' => (int) $TorrentDetails['year'],
  78. 'workgroup' => $TorrentDetails['workgroup'],
  79. 'location' => $TorrentDetails['location'],
  80. 'citations' => $Citations,
  81. 'mirrors' => ($TorrentDetails['Mirrors']) ?: false,
  82. 'description' => $TorrentDetails['description'],
  83. #'description' => Text::full_format($TorrentDetails['description']),
  84. 'picture' => $TorrentDetails['picture'],
  85. 'tagList' => $TagList,
  86. 'bookmarked' => Bookmarks::has_bookmarked('torrent', $GroupID),
  87. 'timestamp' => $TorrentDetails['timestamp'],
  88. ];
  89. # Torrents in group
  90. $JsonTorrentList = [];
  91. foreach ($TorrentList as $Torrent) {
  92. # Convert file list back to the old format
  93. $FileList = explode("\n", $Torrent['FileList']);
  94. foreach ($FileList as &$File) {
  95. $File = Torrents::filelist_old_format($File);
  96. }
  97. # todo: Make a nested object
  98. # todo: Limit to 100 files
  99. unset($File);
  100. $FileList = implode('|||', $FileList);
  101. $Userinfo = Users::user_info($Torrent['UserID']);
  102. $Reports = Torrents::get_reports($Torrent['ID']);
  103. $Torrent['Reported'] = count($Reports) > 0;
  104. # Torrent details response
  105. # todo: Update DB schema
  106. $JsonTorrentList[] = [
  107. 'id' => (int) $Torrent['ID'],
  108. 'infoHash' => $Torrent['InfoHash'],
  109. 'description' => $Torrent['Description'],
  110. 'platform' => $Torrent['Media'],
  111. 'format' => $Torrent['Container'],
  112. 'scope' => $Torrent['Resolution'],
  113. 'annotated' => (bool) $Torrent['Censored'],
  114. 'license' => $Torrent['Codec'],
  115. 'size' => (int) $Torrent['Size'],
  116. 'archive' => $Torrent['Archive'],
  117. 'fileCount' => (int) $Torrent['FileCount'],
  118. 'filePath' => $Torrent['FilePath'],
  119. 'fileList' => $FileList,
  120. 'seeders' => (int) $Torrent['Seeders'],
  121. 'leechers' => (int) $Torrent['Leechers'],
  122. 'snatched' => (int) $Torrent['Snatched'],
  123. 'freeTorrent' => ($Torrent['FreeTorrent'] === 1),
  124. 'reported' => (bool) $Torrent['Reported'],
  125. 'time' => $Torrent['Time'],
  126. 'userId' => (int) ($Torrent['Anonymous'] ? 0 : $Torrent['UserID']),
  127. 'username' => ($Torrent['Anonymous'] ? 'Anonymous' : $Userinfo['Username']),
  128. ];
  129. }
  130. # Print response
  131. json_die(
  132. 'success',
  133. [
  134. 'group' => $JsonTorrentDetails,
  135. 'torrents' => $JsonTorrentList,
  136. ]
  137. );