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.

48 lines
1.2 KiB

  1. <?php
  2. // Questionable Content
  3. // Simple to archive, get the current day's number and work in reverse.
  4. // This one can be re-run several times and it'll safely get images missed in
  5. // the last run if it was stopped before completing
  6. $html = file_get_contents('https://www.questionablecontent.net/');
  7. preg_match('@/comics/([0-9]+)\\.png@', $html, $matches);
  8. if (!$matches[1]) {
  9. echo "No comic found on home page! :(\n";
  10. return;
  11. }
  12. if (!is_dir('qc')) {
  13. mkdir('qc');
  14. }
  15. $start = $matches[1];
  16. for ($i = $start; $i > 0; $i--) {
  17. if (is_file("qc/$i.png") || is_file("qc/$i.jpg") || is_file("qc/$i.gif")) {
  18. continue;
  19. }
  20. echo "Downloading #$i\n";
  21. $url = "https://www.questionablecontent.net/comics/$i.png";
  22. $data = @file_get_contents($url);
  23. if ($data) {
  24. file_put_contents("qc/$i.png", $data);
  25. } else {
  26. $url = "https://www.questionablecontent.net/comics/$i.jpg";
  27. $data = @file_get_contents($url);
  28. if ($data) {
  29. file_put_contents("qc/$i.jpg", $data);
  30. } else {
  31. $url = "https://www.questionablecontent.net/comics/$i.gif";
  32. $data = @file_get_contents($url);
  33. if ($data) {
  34. file_put_contents("qc/$i.gif", $data);
  35. }
  36. }
  37. }
  38. usleep(5e5);
  39. }