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.

56 lines
1.3 KiB

  1. <?php
  2. // Dumbing of Age
  3. // A bit tricky, but not too bad
  4. // We start with the current day, then click the Previous link until we find
  5. // an image we've already saved before.
  6. $html = file_get_contents('https://www.dumbingofage.com/');
  7. preg_match('@/comics/(.+\\.png)@', $html, $matches);
  8. if (empty($matches[1])) {
  9. echo "No comic found on home page! :(\n";
  10. return;
  11. }
  12. if (!is_dir('doa')) {
  13. mkdir('doa');
  14. }
  15. // Download current page's comic, load previous comic webpage, repeat
  16. while (true) {
  17. if (is_file('doa/' . $matches[1])) {
  18. return;
  19. }
  20. echo "Downloading {$matches[1]}\n";
  21. $url = "https://www.dumbingofage.com/comics/{$matches[1]}";
  22. $data = @file_get_contents($url);
  23. if ($data) {
  24. file_put_contents("doa/{$matches[1]}", $data);
  25. }
  26. // Find previous page link
  27. $regex = '@href="(https://www.dumbingofage.com/[0-9a-zA-Z/-]+)" class="navi navi-prev"@';
  28. preg_match($regex, $html, $prevMatch);
  29. if (empty($prevMatch[1])) {
  30. echo "No previous URL found!\n";
  31. return;
  32. }
  33. $html = @file_get_contents($prevMatch[1]);
  34. if (!$html) {
  35. echo "Failed to load previous page!\n";
  36. return;
  37. }
  38. preg_match('@/comics/(.+\\.png)@', $html, $matches);
  39. if (empty($matches[1])) {
  40. echo "No image found on page!\n";
  41. return;
  42. }
  43. usleep(5e5);
  44. }