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.

browse.php 4.3KB

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