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.

javfill.php 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?
  2. $debug = false;
  3. if (empty($_GET['cn'])) {
  4. json_die();
  5. }
  6. $cn = strtoupper($_GET['cn']);
  7. if (!strpos($cn, '-')) {
  8. preg_match('/\d/', $cn, $m, PREG_OFFSET_CAPTURE);
  9. if ($m) { $cn = substr_replace($cn, '-', $m[0][1], 0); }
  10. }
  11. if (!$debug && $Cache->get_value('jav_json_'.$cn)) {
  12. json_die('success', $Cache->get_value('jav_json_'.$cn));
  13. } else {
  14. $jlib_jp_url = ('http://www.javlibrary.com/ja/vl_searchbyid.php?keyword='.$cn);
  15. $jlib_en_url = ('http://www.javlibrary.com/en/vl_searchbyid.php?keyword='.$cn);
  16. $jdb_url = ('http://javdatabase.com/movies/'.$cn.'/');
  17. $jlib_page_jp = file_get_contents($jlib_jp_url);
  18. $jlib_page_en = file_get_contents($jlib_en_url);
  19. $jdb_page = file_get_contents($jdb_url);
  20. if ($jlib_page_en) {
  21. $jlib_dom_en = new DOMDocument();
  22. $jlib_dom_en->loadHTML($jlib_page_en);
  23. $jlib_en = new DOMXPath($jlib_dom_en);
  24. // Check if we're still on the search page and fix it if so
  25. if($jlib_en->query("//a[starts-with(@title, \"$cn\")]")->item(0)) {
  26. $href = substr($jlib_en->query("//a[starts-with(@title, \"$cn\")]")->item(0)->getAttribute('href'),1);
  27. $jlib_page_en = file_get_contents('http://www.javlibrary.com/en/'.$href);
  28. $jlib_page_jp = file_get_contents('http://www.javlibrary.com/ja/'.$href);
  29. $jlib_dom_en->loadHTML($jlib_page_en);
  30. $jlib_en = new DOMXPath($jlib_dom_en);
  31. // If the provided CN was so bad that search provided a different match, die
  32. if(strtoupper($jlib_en->query('//*[@id="video_id"]/table/tr/td[2]')->item(0)->nodeValue) != $cn) {
  33. json_die('failure', 'Movie not found');
  34. }
  35. }
  36. }
  37. if ($jlib_page_jp) {
  38. $jlib_dom_jp = new DOMDocument();
  39. $jlib_dom_jp->loadHTML($jlib_page_jp);
  40. $jlib_jp = new DOMXPath($jlib_dom_jp);
  41. }
  42. if ($jdb_page) {
  43. $jdb_dom = new DOMDocument();
  44. $jdb_dom->loadHTML($jdb_page);
  45. $jdb = new DOMXPath($jdb_dom);
  46. }
  47. list($idols, $genres, $screens, $title, $title_jp, $year, $studio, $label, $desc, $image) = array([],[],[],'','','','','','','');
  48. if (!$jdb_page && !$jlib_page_jp && !$jlib_page_en) {
  49. json_die('failure', 'Movie not found');
  50. }
  51. $degraded = false;
  52. if ($jlib_page_jp && $jlib_jp->query('//*[@id="video_title"]')['length']) {
  53. $title_jp = $jlib_jp->query('//*[@id="video_title"]/h3/a')->item(0)->nodeValue;
  54. $title_jp = substr($title_jp, strlen($cn) + 1);
  55. } else {
  56. $degraded = true;
  57. }
  58. if ($jlib_page_en && $jlib_en->query('//*[@id="video_title"]')['length']) {
  59. $title = $jlib_en->query('//*[@id="video_title"]/h3/a')->item(0)->nodeValue;
  60. $title = substr($title, strlen($cn) + 1);
  61. $idols = array();
  62. foreach ($jlib_en->query('//*[starts-with(@id, "cast")]/span[1]/a') as $idol) {
  63. $idols[] = $idol->nodeValue;
  64. }
  65. $year = $jlib_en->query('//*[@id="video_date"]/table/tr/td[2]')->item(0)->nodeValue;
  66. $year = explode('-', $year)[0];
  67. $studio = $jlib_en->query('//*[starts-with(@id, "maker")]/a')->item(0)->nodeValue;
  68. $label = $jlib_en->query('//*[starts-with(@id, "label")]/a')->item(0)->nodeValue;
  69. $image = $jlib_en->query('//*[@id="video_jacket_img"]')->item(0)->getAttribute('src');
  70. $comments = "";
  71. foreach ($jlib_en->query('//*[@class="comment"]//*[@class="t"]//textarea') as $comment) {
  72. $comments .= ($comment->nodeValue).' ';
  73. }
  74. preg_match_all("/\[img\b[^\]]*\]([^\[]*?)\[\/img\](?!\[\/url)/is", $comments, $screens_t);
  75. if (isset($screens_t[1])) {
  76. $screens = $screens_t[1];
  77. function f($s) { return !(preg_match('/(rapidgator)|(uploaded)|(javsecret)|(\.gif)|(google)|(thumb)|(imgur)|(fileboom)/', $s)); }
  78. $screens = array_values(array_filter($screens, f));
  79. }
  80. if (preg_match('/http:\/\/imagetwist.com\/\S*jpg.html/', $comments, $twist)) {
  81. $twist_t = file_get_contents($twist[0]);
  82. $twist = new DOMDocument();
  83. $twist->loadHTML($twist_t);
  84. $twist = new DOMXPath($twist);
  85. if ($twist->query('//img[@class="pic"]')->item(0))
  86. $screens[] = $twist->query('//img[@class="pic"]')->item(0)->getAttribute('src');
  87. }
  88. $desc = '';
  89. $genres = array();
  90. foreach ($jlib_en->query('//*[starts-with(@id, "genre")]/a') as $genre) {
  91. $genres[] = str_replace(' ', '.', strtolower($genre->nodeValue));
  92. }
  93. } else {
  94. $degraded = true;
  95. }
  96. if ($jdb_page) {
  97. if (!$title) {
  98. $title = substr($jdb->query('//h3')[0]->nodeValue, strlen($cn)+1);
  99. }
  100. if (!idols) {
  101. $idols_raw = $jdb->query("//div[@class='movieinfo']")[0]->childNodes[2]->childNodes[0]->childNodes;
  102. foreach ($idols_raw as $key => $idol) {
  103. if ($key % 2 != 0) {
  104. $idols[] = $idol->nodeValue;
  105. }
  106. }
  107. }
  108. if (!$year) {
  109. $year = substr($jdb->query("//div[@class='movieinfo']")[0]->childNodes[1]->childNodes[0]->nodeValue, strlen("Release Date: "), 4);
  110. }
  111. if(!$image) {
  112. $image = $jdb->query('//*[@class="cover"]/a/img')->item(0)->getAttribute('src');
  113. }
  114. if (!$desc) {
  115. //Shit neither of the sites have descriptions
  116. $desc = '';
  117. }
  118. }
  119. if (!($title || $idols || $year || $studio || $label || $genres)) {
  120. json_die('failure', 'Movie not found');
  121. }
  122. // Only show "genres" we have tags for
  123. if (!$Cache->get_value('genre_tags')) {
  124. $DB->query('
  125. SELECT Name
  126. FROM tags
  127. WHERE TagType = \'genre\'
  128. ORDER BY Name');
  129. $Cache->cache_value('genre_tags', $DB->collect('Name'), 3600 * 6);
  130. }
  131. $genres = array_values(array_intersect(array_values($Cache->get_value('genre_tags')), str_replace('_','.',array_values(Tags::remove_aliases(array('include' => str_replace('.','_',$genres)))['include']))));
  132. $json = array(
  133. 'cn' => $cn,
  134. 'title' => ($title ? $title : ''),
  135. 'title_jp' => ($title_jp ? $title_jp : ''),
  136. 'idols' => ($idols ? $idols : []),
  137. 'year' => ($year ? $year : ''),
  138. 'studio' => ($studio ? $studio : ''),
  139. 'label' => ($label ? $label : ''),
  140. 'image' => ($image ? $image : ''),
  141. 'description' => ($desc ? $desc : ''),
  142. 'tags' => ($genres ? $genres : []),
  143. 'screens' => ($screens ? $screens : []),
  144. 'degraded' => $degraded
  145. );
  146. $Cache->cache_value('jav_json_'.$cn, $json, 86400);
  147. json_die('success', $json);
  148. }