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.

40 lines
1.2 KiB

  1. <?php
  2. // Otaku Dad
  3. // This one has ended, so we can hard-code a few things
  4. // We'll work from start to end, unlike most of the other archives
  5. // We force the file names to be sequential. Makes it much easier to read.
  6. $start = 'http://www.otaku-dad.com/comic/i39m-embarrassed-by-my-otaku-dad';
  7. $end = 'http://www.otaku-dad.com/comic/the-end';
  8. if (!is_dir('otaku-dad')) {
  9. mkdir('otaku-dad');
  10. }
  11. $url = $start;
  12. $i = 0;
  13. while ($url != $end) {
  14. $html = file_get_contents($url);
  15. preg_match('@src="http://www.otaku-dad.com/comics/([0-9a-zA-Z-]+\\.[a-z]{3,4})" id="cc-comic"@', $html, $matches);
  16. if (!empty($matches[1])) {
  17. $name = trim(substr($url, 31), '/');
  18. if (glob("otaku-dad/{$name}*")) {
  19. return;
  20. }
  21. echo "Downloading {$name}\n";
  22. $data = @file_get_contents('http://www.otaku-dad.com/comics/' . $matches[1]);
  23. if ($data) {
  24. $ext = pathinfo(parse_url($matches[1])['path'], PATHINFO_EXTENSION);
  25. file_put_contents("otaku-dad/" . str_pad($i, 2, '0', STR_PAD_LEFT) . "-$name.$ext", $data);
  26. }
  27. }
  28. preg_match('@href="(http://www.otaku-dad.com/comic/[0-9a-zA-Z-]+/?)" class="next"@', $html, $matches);
  29. $url = $matches[1];
  30. $i++;
  31. usleep(5e5);
  32. }