마루마루 사이트의 PHP 파싱 파일입니다. fmaru 관련 포팅 자료도 있습니다. (마루마루 사이트가 닫혀서 더 이상 작동하지 않습니다.) https://marumaru.hakase.io/
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.

index.php 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. include_once '_function.php';
  3. $marumaru = new Marumaru();
  4. $num = $_GET['num'];
  5. $image = $_GET['image'];
  6. $imgurl = $_GET['imgurl'];
  7. if(isset($imgurl))
  8. {
  9. $a = parse_url($imgurl);
  10. switch($a['host'])
  11. {
  12. case 'www.yuncomics.com':
  13. case 'wasabisyrup.com':
  14. case 'blog.yuncomics.com':
  15. case 'marumaru.in':
  16. case 'www.wasabisyrup.com':
  17. break;
  18. default:
  19. exit;
  20. }
  21. $last_modified = gmdate('D, d M Y H:i:s', time()) . ' GMT';
  22. if (array_key_exists('HTTP_IF_MODIFIED_SINCE', $_SERVER))
  23. {
  24. $if_modified_since = strtotime(preg_replace('/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE']));
  25. if ($if_modified_since >= $last_modified)
  26. {
  27. header($_SERVER['SERVER_PROTOCOL'].' 304 Not Modified');
  28. exit();
  29. }
  30. }
  31. header('Cache-Control: max-age=86400, public');
  32. header('Expires: '. gmdate('D, d M Y H:i:s \G\M\T', time() + 86400));
  33. header('Last-Modified: ' . gmdate('D, d M Y H:i:s',time() + 86400 ) . ' GMT' );
  34. header('Content-Type: image/jpeg');
  35. $ings = parse_url($imgurl);
  36. $head = array('Referer: http://' . $ings['host']);
  37. echo $marumaru->WEBParsing($imgurl, NULL, NULL, NULL, $head);
  38. exit;
  39. }
  40. if(!isset($num))
  41. {
  42. ?>
  43. <!doctype html><html><head><title>wasabisyrup(marumaru.in) Image URL Parser API</title><meta charset="UTF-8">
  44. <style>body img { width: auto; height: auto; max-width: 100%;
  45. }</style>
  46. <link rel="shortcut icon" href="favicon.ico">
  47. </head><body>
  48. <h1>wasabisyrup(marumaru.in) <u>Image URL</u> Parser API</h1>
  49. <p>Using: /api/{wasabisyrup number}/{1 or 0(null)}<br>
  50. Use only application/web/other developers.</p>
  51. <h2>Example</h2>
  52. <p>no json - <a href="/api/93" target="_blank">/api/93 (Himouto Umaru-Chan)</a><br>
  53. json - <a href="/api/93/1" target="_blank">/api/93/1 (Himouto Umaru-Chan)</a><br>
  54. <a href="https://github.com/fmaru/fmaru" rel="noreferrer" target="_blank">fmaru</a> php porting by hakase - <a href="/fmaru" target="_blank">/fmaru</a><br>
  55. image direct view - <a href="/img/93" target="_blank">/img/93 (Himouto Umaru-Chan)</a></p>
  56. <h2>JSON Type</h2>
  57. <p>title : Manga Subject<br>
  58. url : Image URL<br>
  59. explorer : Another same cartoon episode (same episode will be ignored) - id => name (if not data, show null value)<br>
  60. prevnext : Next Episode / Prev Episode (if not data, show null value)<br>
  61. - prev : id => name (or NULL)<br>
  62. - next : id => name (or NULL)</p>
  63. <h2>String Type</h2>
  64. <p>First Line : Manga Subject<br>
  65. Other Line : Image URL</p>
  66. <h2>Error Message</h2>
  67. <p>Number 0 : Connect Error (wasabisyrup 403 or other error)<br>
  68. Number 2 : Cookie Get Error<br>
  69. Number 3 : Password Error (Protected archive) - Retry 10 minutes after view or retry about 3 times)<br>
  70. Number 4 : Not found comics data<br>
  71. Other error : read the message</p>
  72. <p>Output only JSON (Example) {"error":1,"message":"Error Message"}<br>
  73. Only error / message method use</p>
  74. <h2>Etc...</h2>
  75. <p><strong><i><u><a href="https://github.com/hakasenyang/marumaru-php-parser" target="_blank">Open Source</a></u></i></strong></p>
  76. <p>Developed by <a href="https://keybase.io/hakasekr" rel="noreferrer" target="_blank">Hakase</a> (hakase@hakase.io)<br>
  77. 사용은 자유고 제한 없음. 애초에 제한 있으면 API 인증키를 넣겠지만 귀찮아서 안 넣음.
  78. </p>
  79. </body>
  80. </html>
  81. <?php
  82. exit;
  83. }
  84. cookieget:
  85. $dd = $marumaru->FileRead();
  86. if(!$dd || explode(PHP_EOL, $dd)[0] < time() || $tmp > 1 || $tmp2 > 3)
  87. {
  88. $cookie = $marumaru->GetCookie();
  89. if(!$cookie) $marumaru->ErrorEcho(2);
  90. $marumaru->FileWrite($cookie);
  91. }
  92. else
  93. $cookie = explode(PHP_EOL, $dd)[1];
  94. startdata:
  95. $caches++;
  96. $data = $marumaru->WEBParsing('http://wasabisyrup.com/archives/'.$num, $cookie);
  97. /*if(stripos($data, 'HTTP/1.1 301 Moved Permanently') !== false)
  98. {
  99. $num = explode('/', $marumaru->splits($data, 'Location: ', PHP_EOL))[4];
  100. $data = $marumaru->WEBParsing('http://www.yuncomics.com/archives/'.$num, $cookie.$cookie2);
  101. }*/
  102. if(stripos($data, 'HTTP/1.1 404 Not Found') !== false ||
  103. stripos($data, 'HTTP/1.1 301 Moved Permanently') !== false)
  104. $marumaru->ErrorEcho(4);
  105. if(stripos($data, 'HTTP/1.1 200 OK') === false)
  106. $marumaru->ErrorEcho(0);
  107. if(stripos($data, '<h2>Protected</h2>') !== false)
  108. if($caches > 5)
  109. $marumaru->ErrorEcho(3);
  110. else
  111. {
  112. $tmp2++;
  113. goto startdata;
  114. }
  115. /*if(stripos($data, 'You are being redirected...') !== false)
  116. if($caches > 2)
  117. $marumaru->ErrorEcho(1);
  118. else
  119. {
  120. $tmp++;
  121. goto cookieget;
  122. }*/
  123. $jsonon = ($_GET['json'] == 1) ? true : false;
  124. $aaa = explode('data-src="', str_replace('data-src="/storage/', 'data-src="http://wasabisyrup.com/storage/', $data));
  125. $title = $marumaru->splits($aaa[0], '<title>', '</title>');
  126. $title = trim(explode(' | ', $title)[0]);
  127. $data2 = $marumaru->splits($data, '<select class="list-articles select-js-inline select-js-nofocus select-js-inline-right">', '</select>');
  128. $data2 = explode('<option value="', str_replace('selected>', '>', $data2));
  129. $data2 = str_replace(array("\t", PHP_EOL), NULL, $data2);
  130. if ($image)
  131. {
  132. $jsonon = ($_GET['json'] == 1) ? true : false;
  133. for($i=1,$cnt=(count($aaa));$i<$cnt;$i++)
  134. echo '<img src="?imgurl='.urlencode(trim(explode('"', $aaa[$i])[0])).'"><br>';
  135. }
  136. else
  137. {
  138. for($i=1,$cnt=count($data2);$i<$cnt;$i++)
  139. {
  140. if($num == trim(explode('" >', $data2[$i])[0]))
  141. {
  142. if($i != count($data2) - 1)
  143. {
  144. $nextid = trim(explode('" >', $data2[$i+1])[0]);
  145. $nextname = trim(explode('</option>', explode('" >', $data2[$i+1])[1])[0]);
  146. }
  147. if($i != 1)
  148. {
  149. $previd = trim(explode('" >', $data2[$i-1])[0]);
  150. $prevname = trim(explode('</option>', explode('" >', $data2[$i-1])[1])[0]);
  151. }
  152. continue;
  153. }
  154. $aac[] = [trim(explode('" >', $data2[$i])[0]) => trim(explode('</option>', explode('" >', $data2[$i])[1])[0])];
  155. }
  156. if($previd || $nextid)
  157. {
  158. if($previd)
  159. $aad[] = ['prev'=>[$previd=>$prevname]];
  160. else
  161. $aad[] = ['prev'=>null];
  162. if($nextid)
  163. $aad[] = ['next'=>[$nextid=>$nextname]];
  164. else
  165. $aad[] = ['next'=>null];
  166. }
  167. for($i=1,$cnt=(count($aaa));$i<$cnt;$i++)
  168. $aab[] = trim(explode('"', $aaa[$i])[0]);
  169. if($jsonon)
  170. {
  171. $aaaa = array('title'=>$title,
  172. 'url'=>$aab,
  173. 'explorer'=>$aac,
  174. 'prevnext'=>$aad);
  175. echo json_encode($aaaa);
  176. }
  177. else
  178. echo $title.PHP_EOL.implode(PHP_EOL, $aab);
  179. }