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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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", array(
  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. // $ExtendedArtists = $GroupInfo['ExtendedArtists'];
  36. $ExtendedArtists = $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 = array($TorrentID => $GroupInfo['Torrents'][$TorrentID]);
  52. }
  53. $TagList = explode(' ', str_replace('_', '.', $GroupInfo['TagList']));
  54. $JsonArtists = [];
  55. if (!empty($ExtendedArtists[1]) || !empty($ExtendedArtists[4]) || !empty($ExtendedArtists[5]) || !empty($ExtendedArtists[6])) {
  56. unset($ExtendedArtists[2]);
  57. unset($ExtendedArtists[3]);
  58. $DisplayName = Artists::display_artists($ExtendedArtists, false, false, false);
  59. foreach ($ExtendedArtists[1] as $Artist) {
  60. $JsonArtists[] = array(
  61. 'id' => (int)$Artist['id'],
  62. 'name' => $Artist['name'],
  63. 'aliasid' => (int)$Artist['id']
  64. );
  65. }
  66. } else {
  67. $DisplayName = '';
  68. }
  69. $JsonTorrents = [];
  70. foreach ($Torrents as $TorrentID => $Data) {
  71. // All of the individual torrents in the group
  72. $JsonTorrents[] = array(
  73. 'torrentId' => (int)$TorrentID,
  74. 'artists' => $JsonArtists,
  75. 'media' => $Data['Media'],
  76. 'container' => $Data['Container'],
  77. 'codec' => $Data['Codec'],
  78. 'resolution' => $Data['Resolution'],
  79. 'audio' => $Data['AudioFormat'],
  80. 'lang' => $Data['Language'],
  81. 'subbing' => $Data['Subbing'],
  82. 'subber' => $Data['Subber'],
  83. 'censored' => $Data['Censored'],
  84. 'archive' => $Data['Archive'],
  85. 'fileCount' => (int)$Data['FileCount'],
  86. 'time' => $Data['Time'],
  87. 'size' => (int)$Data['Size'],
  88. 'snatches' => (int)$Data['Snatched'],
  89. 'seeders' => (int)$Data['Seeders'],
  90. 'leechers' => (int)$Data['Leechers'],
  91. 'isFreeleech' => $Data['FreeTorrent'] == '1',
  92. 'isNeutralLeech' => $Data['FreeTorrent'] == '2',
  93. 'isPersonalFreeleech' => $Data['PersonalFL'],
  94. 'canUseToken' => Torrents::can_use_token($Data),
  95. 'hasSnatched' => $Data['IsSnatched']
  96. );
  97. }
  98. $JsonGroups[] = array(
  99. 'groupId' => (int)$GroupID,
  100. 'groupName' => $GroupName,
  101. 'artist' => $DisplayName,
  102. 'cover' => $GroupInfo['WikiImage'],
  103. 'tags' => $TagList,
  104. 'bookmarked' => (in_array($GroupID, $Bookmarks)),
  105. 'groupYear' => (int)$GroupInfo['Year'],
  106. 'groupTime' => (int)$GroupTime,
  107. 'catalogue' => $GroupInfo['CatalogueNumber'],
  108. 'studio' => $GroupInfo['Studio'],
  109. 'series' => $GroupInfo['Series'],
  110. 'dlsite' => $GroupInfo['DLSiteID'],
  111. 'maxSize' => (int)$MaxSize,
  112. 'totalSnatched' => (int)$TotalSnatched,
  113. 'totalSeeders' => (int)$TotalSeeders,
  114. 'totalLeechers' => (int)$TotalLeechers,
  115. 'torrents' => $JsonTorrents
  116. );
  117. }
  118. json_print('success', array(
  119. 'currentPage' => intval($Page),
  120. 'pages' => ceil($NumResults / TORRENTS_PER_PAGE),
  121. 'results' => $JsonGroups));