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

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