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.

torrentgroup.php 3.4KB

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