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.

jav.php 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <?php
  2. #declare(strict_types=1);
  3. # Headers, cache, etc.
  4. $debug = false;
  5. if (empty($_GET['cn'])) {
  6. json_die();
  7. }
  8. $cn = strtoupper($_GET['cn']);
  9. if (!strpos($cn, '-')) {
  10. preg_match('/\d/', $cn, $m, PREG_OFFSET_CAPTURE);
  11. if ($m) { $cn = substr_replace($cn, '-', $m[0][1], 0); }
  12. }
  13. if (!$debug && $Cache->get_value('jav_fill_json_'.$cn)) {
  14. json_die('success', $Cache->get_value('jav_fill_json_'.$cn));
  15. } else {
  16. # Query the API
  17. # todo: Validate to change $db
  18. /* todo
  19. * switch $category:
  20. * case 'DNA' || 'RNA':
  21. * if $number = refseq_regex:
  22. * $db = 'refseq';
  23. * break;
  24. * case 'Protein':
  25. * if $number = uniprot_regex:
  26. * $db = 'uniprot';
  27. * break;
  28. * default:
  29. * error 'invalid number';
  30. * break;
  31. */
  32. $id = 'NM_001183340.1';
  33. # Assemble the esearch URL
  34. $base = 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/';
  35. $url = $base . "esummary.fcgi?db=$db&id=$id&version=2.0";
  36. # Post the esearch URL
  37. $output = file_get_contents($url);
  38. # Parse WebEnv and QueryKey
  39. #$web = $1 if ($output =~ /<WebEnv>(\S+)<\/WebEnv>/);
  40. #$key = $1 if ($output =~ /<QueryKey>(\d+)<\/QueryKey>/);
  41. ### Include this code for ESearch-ESummary
  42. # Assemble the esummary URL
  43. $url = $base . "esummary.fcgi?db=$db&query_key=$key&WebEnv=$web";
  44. # Post the esummary URL
  45. $docsums = file_get_contents($url);
  46. echo "$docsums";
  47. ### Include this code for ESearch-EFetch
  48. # Assemble the efetch URL
  49. $url = $base . "efetch.fcgi?db=$db&query_key=$key&WebEnv=$web";
  50. $url .= "&rettype=abstract&retmode=text";
  51. # Post the efetch URL
  52. $data = file_get_contents($url);
  53. echo "$data";
  54. /*
  55. $jlib_jp_url = ('http://www.javlibrary.com/ja/vl_searchbyid.php?keyword='.$cn);
  56. $jlib_en_url = ('http://www.javlibrary.com/en/vl_searchbyid.php?keyword='.$cn);
  57. $jdb_url = ('http://javdatabase.com/movies/'.$cn.'/');
  58. $jlib_page_jp = file_get_contents($jlib_jp_url);
  59. $jlib_page_en = file_get_contents($jlib_en_url);
  60. $jdb_page = file_get_contents($jdb_url);
  61. if ($jlib_page_en) {
  62. $jlib_dom_en = new DOMDocument();
  63. $jlib_dom_en->loadHTML($jlib_page_en);
  64. $jlib_en = new DOMXPath($jlib_dom_en);
  65. // Check if we're still on the search page and fix it if so
  66. if($jlib_en->query("//a[starts-with(@title, \"$cn\")]")->item(0)) {
  67. $href = substr($jlib_en->query("//a[starts-with(@title, \"$cn\")]")->item(0)->getAttribute('href'),1);
  68. $jlib_page_en = file_get_contents('http://www.javlibrary.com/en/'.$href);
  69. $jlib_page_jp = file_get_contents('http://www.javlibrary.com/ja/'.$href);
  70. $jlib_dom_en->loadHTML($jlib_page_en);
  71. $jlib_en = new DOMXPath($jlib_dom_en);
  72. // If the provided CN was so bad that search provided a different match, die
  73. if(strtoupper($jlib_en->query('//*[@id="video_id"]/table/tr/td[2]')->item(0)->nodeValue) != $cn) {
  74. json_die('failure', 'Movie not found');
  75. }
  76. }
  77. }
  78. if ($jlib_page_jp) {
  79. $jlib_dom_jp = new DOMDocument();
  80. $jlib_dom_jp->loadHTML($jlib_page_jp);
  81. $jlib_jp = new DOMXPath($jlib_dom_jp);
  82. }
  83. if ($jdb_page) {
  84. $jdb_dom = new DOMDocument();
  85. $jdb_dom->loadHTML($jdb_page);
  86. $jdb = new DOMXPath($jdb_dom);
  87. }
  88. list($idols, $genres, $screens, $title, $title_jp, $year, $studio, $label, $desc, $image) = array([],[],[],'','','','','','','');
  89. if (!$jdb_page && !$jlib_page_jp && !$jlib_page_en) {
  90. json_die('failure', 'Movie not found');
  91. }
  92. $degraded = false;
  93. if ($jlib_page_jp && $jlib_jp->query('//*[@id="video_title"]')['length']) {
  94. $title_jp = $jlib_jp->query('//*[@id="video_title"]/h3/a')->item(0)->nodeValue;
  95. $title_jp = substr($title_jp, strlen($cn) + 1);
  96. } else {
  97. $degraded = true;
  98. }
  99. if ($jlib_page_en && $jlib_en->query('//*[@id="video_title"]')['length']) {
  100. $title = $jlib_en->query('//*[@id="video_title"]/h3/a')->item(0)->nodeValue;
  101. $title = substr($title, strlen($cn) + 1);
  102. $idols = [];
  103. foreach ($jlib_en->query('//*[starts-with(@id, "cast")]/span[1]/a') as $idol) {
  104. $idols[] = $idol->nodeValue;
  105. }
  106. $year = $jlib_en->query('//*[@id="video_date"]/table/tr/td[2]')->item(0)->nodeValue;
  107. $year = explode('-', $year)[0];
  108. $studio = $jlib_en->query('//*[starts-with(@id, "maker")]/a')->item(0)->nodeValue;
  109. $label = $jlib_en->query('//*[starts-with(@id, "label")]/a')->item(0)->nodeValue;
  110. $image = $jlib_en->query('//*[@id="video_jacket_img"]')->item(0)->getAttribute('src');
  111. $comments = "";
  112. foreach ($jlib_en->query('//*[@class="comment"]//*[@class="t"]//textarea') as $comment) {
  113. $comments .= ($comment->nodeValue).' ';
  114. }
  115. preg_match_all("/\[img\b[^\]]*\]([^\[]*?)\[\/img\](?!\[\/url)/is", $comments, $screens_t);
  116. if (isset($screens_t[1])) {
  117. $screens = $screens_t[1];
  118. function f($s) { return !(preg_match('/(rapidgator)|(uploaded)|(javsecret)|(\.gif)|(google)|(thumb)|(imgur)|(fileboom)|(openload)/', $s)); }
  119. $screens = array_values(array_filter($screens, f));
  120. }
  121. if (preg_match('/http:\/\/imagetwist.com\/\S*jpg.html/', $comments, $twist)) {
  122. $twist_t = file_get_contents($twist[0]);
  123. $twist = new DOMDocument();
  124. $twist->loadHTML($twist_t);
  125. $twist = new DOMXPath($twist);
  126. if ($twist->query('//img[@class="pic"]')->item(0)) {
  127. $screens[] = $twist->query('//img[@class="pic"]')->item(0)->getAttribute('src');
  128. }
  129. }
  130. $desc = '';
  131. $genres = [];
  132. foreach ($jlib_en->query('//*[starts-with(@id, "genre")]/a') as $genre) {
  133. $genres[] = str_replace(' ', '.', strtolower($genre->nodeValue));
  134. }
  135. } else {
  136. $degraded = true;
  137. }
  138. if ($jdb_page) {
  139. if (!$title) {
  140. $title = trim(substr($jdb->query("//h1[contains(@class, 'entry-title')]")[0]->nodeValue, strlen($cn) + 3));
  141. }
  142. if (!$studio) {
  143. $studio = $jdb->query("//b[contains(., 'Studio:')]")[0]->nextSibling->nodeValue;
  144. }
  145. if (!$label) {
  146. $label = $jdb->query("//b[contains(., 'Label:')]")[0]->nextSibling->nodeValue;
  147. }
  148. if (!$idols) {
  149. $idols_raw = $jdb->query("//b[contains(., 'Idol(s): ')]")[0]->nextSibling;
  150. for ($i = 0; $i < 10; $i++) {
  151. if ($idols_raw->tagName == "a") {
  152. $idol_name = $idols_raw->nodeValue;
  153. $idol_lower = strtolower(str_replace(' ', '-', $idol_name));
  154. // ensure it's actually an idol name
  155. if (strpos($idols_raw->attributes->item(0)->nodeValue, '.com/idols/' . $idol_lower) !== false) {
  156. $idols[] = $idols_raw->nodeValue;
  157. }
  158. }
  159. $idols_raw = $idols_raw->nextSibling;
  160. }
  161. }
  162. if (!$year) {
  163. $year = substr($jdb->query("//b[contains(., 'Release Date:')]")[0]->nextSibling->nodeValue, 1, 4);
  164. }
  165. if (!$image) {
  166. $image = $jdb->query("//img[contains(@alt, ' download or stream.')]")->item(0)->getAttribute('src');
  167. }
  168. if (substr($image, 0, 2) == '//') {
  169. $image = 'https:'.$image;
  170. }
  171. if (!$desc) {
  172. // Shit neither of the sites have descriptions
  173. $desc = '';
  174. }
  175. }
  176. if (!($title || $idols || $year || $studio || $label || $genres)) {
  177. json_die('failure', 'Movie not found');
  178. }
  179. // Only show "genres" we have tags for
  180. if (!$Cache->get_value('genre_tags')) {
  181. $DB->query('
  182. SELECT Name
  183. FROM tags
  184. WHERE TagType = \'genre\'
  185. ORDER BY Name');
  186. $Cache->cache_value('genre_tags', $DB->collect('Name'), 3600 * 6);
  187. }
  188. $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']))));
  189. $json = array(
  190. 'cn' => $cn,
  191. 'title' => ($title ? $title : ''),
  192. 'title_jp' => ($title_jp ? $title_jp : ''),
  193. 'idols' => ($idols ? $idols : []),
  194. 'year' => ($year ? $year : ''),
  195. 'studio' => ($studio ? $studio : ''),
  196. 'label' => ($label ? $label : ''),
  197. 'image' => ($image ? $image : ''),
  198. 'description' => ($desc ? $desc : ''),
  199. 'tags' => ($genres ? $genres : []),
  200. 'screens' => ($screens ? $screens : []),
  201. 'degraded' => $degraded
  202. );
  203. $Cache->cache_value('jav_fill_json_'.$cn, $json, 86400);
  204. json_die('success', $json);
  205. */
  206. }