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.5 KiB

  1. <?php
  2. // Kiwi Blitz
  3. // Mary Cagle's finished comic, hosted on her main personal domain.
  4. // We'll start from the last actual strip, but you should *TOTALLY* buy the
  5. // book as long as it's still available, it's great!
  6. // https://hivemill.com/products/lets-speak-english
  7. $html = file_get_contents('https://www.marycagle.com/letsspeakenglish/134-slow-motion');
  8. preg_match('@/comics/([0-9a-zA-Z_-]+\\.(jpg|png|gif))@', $html, $matches);
  9. if (empty($matches[1])) {
  10. echo "No comic found on home page! :(\n";
  11. return;
  12. }
  13. if (!is_dir('letsspeakenglish')) {
  14. mkdir('letsspeakenglish');
  15. }
  16. // Download current page's comic, load previous comic webpage, repeat
  17. while (true) {
  18. if (is_file('letsspeakenglish/' . $matches[1])) {
  19. return;
  20. }
  21. echo "Downloading {$matches[1]}\n";
  22. $url = "https://www.marycagle.com/comics/{$matches[1]}";
  23. $data = @file_get_contents($url);
  24. if ($data) {
  25. file_put_contents("letsspeakenglish/{$matches[1]}", $data);
  26. }
  27. // Find previous page link
  28. $regex = '@rel="prev" href="(https://www.marycagle.com/letsspeakenglish/[0-9a-zA-Z-]+)"@';
  29. preg_match($regex, $html, $prevMatch);
  30. if (empty($prevMatch[1])) {
  31. echo "No previous URL found!\n";
  32. return;
  33. }
  34. $html = @file_get_contents($prevMatch[1]);
  35. if (!$html) {
  36. echo "Failed to load previous page!\n";
  37. return;
  38. }
  39. preg_match('@/comics/([0-9a-zA-Z_-]+\\.(jpg|png|gif))@', $html, $matches);
  40. if (empty($matches[1])) {
  41. echo "No image found on page!\n";
  42. return;
  43. }
  44. usleep(5e5);
  45. }