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.

55 lines
1.5 KiB

  1. <?php
  2. // Sleepless Domain
  3. // Another ComicPress one, still updating regularly.
  4. // Mary Cagle is amazing and I have no idea how she maintains her separate
  5. // comics with such a detailed art style. She's sorta Willis-y.
  6. $html = file_get_contents('https://www.sleeplessdomain.com/');
  7. preg_match('@/comics/([0-9a-zA-Z_-]+\\.(jpg|png|gif))@', $html, $matches);
  8. if (empty($matches[1])) {
  9. echo "No comic found on home page! :(\n";
  10. return;
  11. }
  12. if (!is_dir('sleeplessdomain')) {
  13. mkdir('sleeplessdomain');
  14. }
  15. // Download current page's comic, load previous comic webpage, repeat
  16. while (true) {
  17. if (is_file('sleeplessdomain/' . $matches[1])) {
  18. return;
  19. }
  20. echo "Downloading {$matches[1]}\n";
  21. $url = "https://www.sleeplessdomain.com/comics/{$matches[1]}";
  22. $data = @file_get_contents($url);
  23. if ($data) {
  24. file_put_contents("sleeplessdomain/{$matches[1]}", $data);
  25. }
  26. // Find previous page link
  27. $regex = '@rel="prev" href="(https://www.sleeplessdomain.com/comic/[0-9a-zA-Z-]+)"@';
  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/([0-9a-zA-Z_-]+\\.(jpg|png|gif))@', $html, $matches);
  39. if (empty($matches[1])) {
  40. echo "No image found on page!\n";
  41. return;
  42. }
  43. usleep(5e5);
  44. }