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.

45 lines
1.2 KiB

  1. <?php
  2. // Nerf NOW!!
  3. // For some reason the image numbers don't match the comic numbers, but we'll
  4. // work around that by renaming the files I guess. I didn't want to do that, but
  5. // we don't have a good alternative.
  6. // This should be safe to re-run multiple times to catch missed images from a
  7. // previous run, though that hasn't actually been thoroughly tested.
  8. $html = file_get_contents('http://www.nerfnow.com/');
  9. preg_match('@/img/([0-9]+)/([0-9]+\\.[a-z]{3,4})@', $html, $matches);
  10. if (!$matches[1]) {
  11. echo "No comic found on home page! :(\n";
  12. return;
  13. }
  14. if (!is_dir('nerfnow')) {
  15. mkdir('nerfnow');
  16. }
  17. $start = $matches[1];
  18. for ($i = $start; $i > 0; $i--) {
  19. if (glob("nerfnow/$i-*")) {
  20. continue;
  21. }
  22. echo "Downloading #$i\n";
  23. $html = file_get_contents('http://www.nerfnow.com/comic/' . $i);
  24. if (!$html) {
  25. echo "Unable to load page, skipping...\n";
  26. continue;
  27. }
  28. preg_match('@/img/([0-9]+)/([0-9]+\\.[a-z]{3,4})@', $html, $matches);
  29. $url = "http://www.nerfnow.com/img/$i/{$matches[2]}";
  30. $data = @file_get_contents($url);
  31. if ($data) {
  32. file_put_contents("nerfnow/$i-{$matches[2]}", $data);
  33. }
  34. usleep(5e5);
  35. }