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.

jav.php 9.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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_fill_json_'.$cn)) {
  12. json_die('success', $Cache->get_value('jav_fill_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 = [];
  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)|(openload)/', $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. }
  89. $desc = '';
  90. $genres = [];
  91. foreach ($jlib_en->query('//*[starts-with(@id, "genre")]/a') as $genre) {
  92. $genres[] = str_replace(' ', '.', strtolower($genre->nodeValue));
  93. }
  94. } else {
  95. $degraded = true;
  96. }
  97. if ($jdb_page) {
  98. if (!$title) {
  99. $title = trim($jdb->query("//b[contains(., 'Translated Title:')]")[0]->nextSibling->nodeValue);
  100. }
  101. if (!$studio) {
  102. $studio = $jdb->query("//b[contains(., 'Studio:')]")[0]->nextSibling->nodeValue;
  103. }
  104. if (!$label) {
  105. $label = $jdb->query("//b[contains(., 'Label:')]")[0]->nextSibling->nodeValue;
  106. }
  107. if (!$idols) {
  108. $idols_raw = $jdb->query("//b[contains(., 'Idol(s): ')]")[0]->nextSibling;
  109. for ($i = 0; $i < 10; $i++) {
  110. if ($idols_raw->tagName == "a") {
  111. $idol_name = $idols_raw->nodeValue;
  112. $idol_lower = strtolower(str_replace(' ', '-', $idol_name));
  113. // ensure it's actually an idol name
  114. if (strpos($idols_raw->attributes->item(0)->nodeValue, '.com/idols/' . $idol_lower) !== false) {
  115. $idols[] = implode(' ', array_reverse(explode(' ', $idols_raw->nodeValue)));
  116. }
  117. }
  118. $idols_raw = $idols_raw->nextSibling;
  119. }
  120. }
  121. if (!$year) {
  122. $year = substr($jdb->query("//b[contains(., 'Release Date:')]")[0]->nextSibling->nodeValue, 1, 4);
  123. }
  124. if (!$image) {
  125. $image = $jdb->query("//img[@alt='" . $cn . "']")->item(0)->getAttribute('src');
  126. }
  127. if (substr($image, 0, 2) == '//') {
  128. $image = 'https:'.$image;
  129. }
  130. if (!$desc) {
  131. //Shit neither of the sites have descriptions
  132. $desc = '';
  133. }
  134. if (!$genres) {
  135. // Mapping of JDB genres that are different to ours.
  136. $jdb_genre_map = [
  137. 'Actress Best Compilation' => 'compilation',
  138. 'Adultery' => 'cheating',
  139. 'Anal Sex' => 'anal',
  140. 'Big Tits' => 'big.breasts:female',
  141. 'Big Tits Lover' => 'big.breasts:female',
  142. 'Big Vibrator' => 'sex.toys',
  143. 'Bunny Girl' => 'bunny.girl',
  144. 'Cat Cosplay' => 'catgirl',
  145. 'Cheating Wife' => 'cheating',
  146. 'Chinese Dress' => 'chinese.dress',
  147. 'Creampie' => 'nakadashi',
  148. 'Cross Dresser' => 'crossdressing',
  149. 'Cum Swallowing' => 'gokkun',
  150. 'Deep Throat' => 'deepthroat',
  151. 'Drunk Girl' => 'drunk',
  152. 'Egg Vibrator' => 'sex.toys',
  153. 'Face Sitting' => 'facesitting',
  154. 'Female Ninja' => 'ninja',
  155. 'Female Teacher' => 'teacher',
  156. 'Gal' => 'gyaru:female',
  157. 'Gay' => 'yaoi:male',
  158. 'Golden Shower' => 'urination',
  159. 'Huge Tits' => 'huge.breasts',
  160. 'Hypnotism' => 'hypnosis',
  161. 'Kiss Kiss' => 'kissing',
  162. 'Leotards' => 'leotard',
  163. 'Lesbian' => 'yuri:female',
  164. 'Lesbian Kissing' => ['yuri:female', 'kissing'],
  165. 'Lotion' => 'oil',
  166. 'Massage Parlor' => 'massage',
  167. 'MILF' => 'milf:female',
  168. 'Muscular' => 'muscle',
  169. 'Naked Apron' => 'apron',
  170. 'Non-nude Erotica' => 'nonnude',
  171. 'Office Lady' => 'office.lady:female',
  172. 'Older Sister' => ['oneesan:female', 'sister:female'],
  173. 'Orgy' => 'group',
  174. 'Pregnant' => 'pregnant:female',
  175. 'Private Tutor' => 'tutor',
  176. 'Race Queen' => 'race.queen',
  177. 'Relatives' => 'incest',
  178. 'Sailor Uniform' => 'schoolgirl.uniform:female',
  179. 'School Swimsuits' => 'school.swimsuit',
  180. 'School Uniform' => 'schoolgirl.uniform:female',
  181. 'Schoolgirl' => 'schoolgirl:female',
  182. 'Sex Toys' => 'sex.toys',
  183. 'Shaved Pussy' => 'shaved:female',
  184. 'Shotacon' => 'shotacon:male',
  185. 'Sister' => 'sister:female',
  186. 'Small Tits' => 'small.breasts:female',
  187. 'Substance Use' => 'drugs',
  188. 'Swimsuits' => 'swimsuit',
  189. 'Tall Girl' => 'tall.girl',
  190. 'Threesome / Foursome' => 'threesome',
  191. 'Titty Fuck' => 'paizuri',
  192. 'Vibrator' => 'sex.toys',
  193. 'Voyeur' => 'voyeurism',
  194. 'Waitress' => 'waiter',
  195. ];
  196. foreach ($jdb->query("//a[@rel='tag' and starts-with(@href, 'https://www.javdatabase.com/genres/')]") as $tag) {
  197. if (array_key_exists($tag->nodeValue, $jdb_genre_map)) {
  198. if (is_array($jdb_genre_map[$tag->nodeValue])) {
  199. $genres = array_merge($genres, $jdb_genre_map[$tag->nodeValue]);
  200. } else {
  201. $genres[] = $jdb_genre_map[$tag->nodeValue];
  202. }
  203. } else {
  204. $genres[] = strtolower($tag->nodeValue);
  205. }
  206. }
  207. }
  208. }
  209. if (!($title || $idols || $year || $studio || $label || $genres)) {
  210. json_die('failure', 'Movie not found');
  211. }
  212. // Only show "genres" we have tags for
  213. if (!$Cache->get_value('genre_tags')) {
  214. $DB->query('
  215. SELECT Name
  216. FROM tags
  217. WHERE TagType = \'genre\'
  218. ORDER BY Name');
  219. $Cache->cache_value('genre_tags', $DB->collect('Name'), 3600 * 6);
  220. }
  221. $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']))));
  222. $json = array(
  223. 'cn' => $cn,
  224. 'title' => ($title ? $title : ''),
  225. 'title_jp' => ($title_jp ? $title_jp : ''),
  226. 'idols' => ($idols ? $idols : []),
  227. 'year' => ($year ? $year : ''),
  228. 'studio' => ($studio ? $studio : ''),
  229. 'label' => ($label ? $label : ''),
  230. 'image' => ($image ? $image : ''),
  231. 'description' => ($desc ? $desc : ''),
  232. 'tags' => ($genres ? $genres : []),
  233. 'screens' => ($screens ? $screens : []),
  234. 'degraded' => $degraded
  235. );
  236. $Cache->cache_value('jav_fill_json_'.$cn, $json, 86400);
  237. json_die('success', $json);
  238. }