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.

browse.php 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. #declare(strict_types=1);
  3. include SERVER_ROOT.'/sections/torrents/functions.php';
  4. if (!empty($_GET['order_way']) && $_GET['order_way'] === 'asc') {
  5. $OrderWay = 'asc';
  6. } else {
  7. $OrderWay = 'desc';
  8. }
  9. if (empty($_GET['order_by']) || !isset(TorrentSearch::$SortOrders[$_GET['order_by']])) {
  10. $OrderBy = 'time';
  11. } else {
  12. $OrderBy = $_GET['order_by'];
  13. }
  14. $GroupResults = !isset($_GET['group_results']) || (int) $_GET['group_results'] !== 0;
  15. $Page = !empty($_GET['page']) ? (int) $_GET['page'] : 1;
  16. $Search = new TorrentSearch($GroupResults, $OrderBy, $OrderWay, $Page, TORRENTS_PER_PAGE);
  17. $Results = $Search->query($_GET);
  18. $Groups = $Search->get_groups();
  19. $NumResults = $Search->record_count();
  20. if ($Results === false) {
  21. json_die('error', 'Search returned an error. Make sure all parameters are valid and of the expected types.');
  22. }
  23. if ($NumResults === 0) {
  24. json_die('success', [
  25. 'results' => []
  26. ]);
  27. }
  28. $Bookmarks = Bookmarks::all_bookmarks('torrent');
  29. $JsonGroups = [];
  30. foreach ($Results as $Key => $GroupID) {
  31. $GroupInfo = $Groups[$GroupID];
  32. if (empty($GroupInfo['Torrents'])) {
  33. continue;
  34. }
  35. $CategoryID = $GroupInfo['CategoryID'];
  36. $Artists = $GroupInfo['Artists'];
  37. $GroupCatalogueNumber = $GroupInfo['CatalogueNumber'];
  38. $GroupName = $GroupInfo['Name'];
  39. if ($GroupResults) {
  40. $Torrents = $GroupInfo['Torrents'];
  41. $GroupTime = $MaxSize = $TotalLeechers = $TotalSeeders = $TotalSnatched = 0;
  42. foreach ($Torrents as $T) {
  43. $GroupTime = max($GroupTime, strtotime($T['Time']));
  44. $MaxSize = max($MaxSize, $T['Size']);
  45. $TotalLeechers += $T['Leechers'];
  46. $TotalSeeders += $T['Seeders'];
  47. $TotalSnatched += $T['Snatched'];
  48. }
  49. } else {
  50. $TorrentID = $Key;
  51. $Torrents = [$TorrentID => $GroupInfo['Torrents'][$TorrentID]];
  52. }
  53. $TagList = explode(' ', str_replace('_', '.', $GroupInfo['TagList']));
  54. $JsonArtists = [];
  55. $DisplayName = '';
  56. if (!empty($Artists)) {
  57. $DisplayName = Artists::display_artists($Artists, false, false, false);
  58. foreach ($Artists as $Artist) {
  59. $JsonArtists[] = [
  60. 'id' => (int) $Artist['id'],
  61. 'name' => $Artist['name']
  62. ];
  63. }
  64. }
  65. $JsonTorrents = [];
  66. foreach ($Torrents as $TorrentID => $Data) {
  67. // All of the individual torrents in the group
  68. $JsonTorrents[] = [
  69. 'torrentId' => (int) $TorrentID,
  70. 'authors' => $JsonArtists,
  71. 'platform' => $Data['Media'],
  72. 'format' => $Data['Container'],
  73. 'license' => $Data['Codec'],
  74. 'scope' => $Data['Resolution'],
  75. 'annotated' => $Data['Censored'],
  76. 'archive' => $Data['Archive'],
  77. 'fileCount' => (int) $Data['FileCount'],
  78. 'time' => $Data['Time'],
  79. 'size' => (int) $Data['Size'],
  80. 'snatches' => (int) $Data['Snatched'],
  81. 'seeders' => (int) $Data['Seeders'],
  82. 'leechers' => (int) $Data['Leechers'],
  83. 'isFreeleech' => (int) $Data['FreeTorrent'] === 1,
  84. 'isNeutralLeech' => (int) $Data['FreeTorrent'] === 2,
  85. 'isPersonalFreeleech' => $Data['PersonalFL'],
  86. 'canUseToken' => Torrents::can_use_token($Data),
  87. 'hasSnatched' => $Data['IsSnatched']
  88. ];
  89. }
  90. $JsonGroups[] = [
  91. 'groupId' => (int) $GroupID,
  92. 'groupName' => $GroupName,
  93. 'author' => $DisplayName,
  94. 'picture' => $GroupInfo['WikiImage'],
  95. 'tags' => $TagList,
  96. 'bookmarked' => (in_array($GroupID, $Bookmarks)),
  97. 'groupYear' => (int) $GroupInfo['Year'],
  98. 'groupTime' => (int) $GroupTime,
  99. 'accession' => $GroupInfo['CatalogueNumber'],
  100. 'lab' => $GroupInfo['Studio'],
  101. 'location' => $GroupInfo['Series'],
  102. 'maxSize' => (int) $MaxSize,
  103. 'totalSnatched' => (int) $TotalSnatched,
  104. 'totalSeeders' => (int) $TotalSeeders,
  105. 'totalLeechers' => (int) $TotalLeechers,
  106. 'torrents' => $JsonTorrents
  107. ];
  108. }
  109. json_print('success', [
  110. 'currentPage' => intval($Page),
  111. 'pages' => ceil($NumResults / TORRENTS_PER_PAGE),
  112. 'results' => $JsonGroups
  113. ]);