Oppaitime'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.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?
  2. require(SERVER_ROOT.'/sections/torrents/functions.php');
  3. $TorrentID = (int)$_GET['id'];
  4. $TorrentHash = (string)$_GET['hash'];
  5. if ($TorrentID && $TorrentHash) {
  6. json_die("failure", "bad parameters");
  7. }
  8. if ($TorrentHash) {
  9. if (!is_valid_torrenthash($TorrentHash)) {
  10. json_die("failure", "bad hash parameter");
  11. } else {
  12. $TorrentID = (int)torrenthash_to_torrentid($TorrentHash);
  13. if (!$TorrentID) {
  14. json_die("failure", "bad hash parameter");
  15. }
  16. }
  17. }
  18. if ($TorrentID <= 0) {
  19. json_die("failure", "bad id parameter");
  20. }
  21. $TorrentCache = get_torrent_info($TorrentID, true, 0, true, true);
  22. if (!$TorrentCache) {
  23. json_die("failure", "bad id parameter");
  24. }
  25. list($TorrentDetails, $TorrentList) = $TorrentCache;
  26. if (!isset($TorrentList[$TorrentID])) {
  27. json_die("failure", "bad id parameter");
  28. }
  29. $GroupID = $TorrentDetails['ID'];
  30. $Artists = pullmediainfo(Artists::get_artist($GroupID));
  31. if ($TorrentDetails['CategoryID'] == 0) {
  32. $CategoryName = "Unknown";
  33. } else {
  34. $CategoryName = $Categories[$TorrentDetails['CategoryID'] - 1];
  35. }
  36. $TagList = explode('|', $TorrentDetails['GROUP_CONCAT(DISTINCT tags.Name SEPARATOR \'|\')']);
  37. $JsonTorrentDetails = [
  38. 'wikiBody' => Text::full_format($TorrentDetails['WikiBody']),
  39. 'wikiImage' => $TorrentDetails['WikiImage'],
  40. 'id' => (int)$TorrentDetails['ID'],
  41. 'name' => $TorrentDetails['Name'],
  42. 'namejp' => $TorrentDetails['NameJP'],
  43. 'artists' => $Artists,
  44. 'year' => (int)$TorrentDetails['Year'],
  45. 'catalogueNumber' => $TorrentDetails['CatalogueNumber'],
  46. 'pages' => (int)$TorrentDetails['Pages'],
  47. 'categoryId' => (int)$TorrentDetails['CategoryID'],
  48. 'categoryName' => $CategoryName,
  49. 'dlsiteId' => $TorrentDetails['DLSiteID'],
  50. 'time' => $TorrentDetails['Time'],
  51. 'isBookmarked' => Bookmarks::has_bookmarked('torrent', $GroupID),
  52. 'tags' => $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. 'media' => $Torrent['Media'],
  69. 'container' => $Torrent['Container'],
  70. 'codec' => $Torrent['Codec'],
  71. 'resolution' => $Torrent['Resolution'],
  72. 'audioFormat' => $Torrent['AudioFormat'],
  73. 'subbing' => $Torrent['Subbing'],
  74. 'subber' => $Torrent['Subber'],
  75. 'language' => $Torrent['Language'],
  76. 'censored' => (bool)$Torrent['Censored'],
  77. 'archive' => $Torrent['Archive'],
  78. 'fileCount' => (int)$Torrent['FileCount'],
  79. 'size' => (int)$Torrent['Size'],
  80. 'seeders' => (int)$Torrent['Seeders'],
  81. 'leechers' => (int)$Torrent['Leechers'],
  82. 'snatched' => (int)$Torrent['Snatched'],
  83. 'freeTorrent' => ($Torrent['FreeTorrent'] == 1),
  84. 'reported' => (bool)$Torrent['Reported'],
  85. 'time' => $Torrent['Time'],
  86. 'description' => $Torrent['Description'],
  87. 'mediaInfo' => $Torrent['MediaInfo'],
  88. 'fileList' => $FileList,
  89. 'filePath' => $Torrent['FilePath'],
  90. 'userId' => (int)($Torrent['Anonymous'] ? 0 : $Torrent['UserID']),
  91. 'username' => ($Torrent['Anonymous'] ? 'Anonymous' : $Userinfo['Username'])
  92. ];
  93. json_die("success", ['group' => $JsonTorrentDetails, 'torrent' => array_pop($JsonTorrentList)]);