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.

58 lines
1.6 KiB

  1. <?php
  2. // Gaia - The fantasy webcomic
  3. // Another ComicPress one, still updating regularly, but ending soon (2019)
  4. // This is hosted on the same domain as Sandra and Woo, in a sub-directory
  5. // Note that you can get official downloads of this comic, including
  6. // high-resolution and draft versions by supporting the creators on Patreon!
  7. // https://www.patreon.com/gaia
  8. $html = file_get_contents('http://www.sandraandwoo.com/gaia/');
  9. preg_match('@/gaia/comics/(.+\\.(jpg|png|gif))@', $html, $matches);
  10. if (empty($matches[1])) {
  11. echo "No comic found on home page! :(\n";
  12. return;
  13. }
  14. if (!is_dir('gaia')) {
  15. mkdir('gaia');
  16. }
  17. // Download current page's comic, load previous comic webpage, repeat
  18. while (true) {
  19. if (is_file('gaia/' . $matches[1])) {
  20. return;
  21. }
  22. echo "Downloading {$matches[1]}\n";
  23. $url = "http://www.sandraandwoo.com/gaia/comics/{$matches[1]}";
  24. $data = @file_get_contents($url);
  25. if ($data) {
  26. file_put_contents("gaia/{$matches[1]}", $data);
  27. }
  28. // Find previous page link
  29. $regex = '@href="(http://www.sandraandwoo.com/gaia/[0-9]{4}/[0-9]+/[0-9]+/[0-9a-zA-Z-]+/?)" rel="prev"@';
  30. preg_match($regex, $html, $prevMatch);
  31. if (empty($prevMatch[1])) {
  32. echo "No previous URL found!\n";
  33. return;
  34. }
  35. $html = @file_get_contents($prevMatch[1]);
  36. if (!$html) {
  37. echo "Failed to load previous page!\n";
  38. return;
  39. }
  40. preg_match('@/gaia/comics/(.+\\.(jpg|png|gif))@', $html, $matches);
  41. if (empty($matches[1])) {
  42. echo "No image found on page!\n";
  43. return;
  44. }
  45. usleep(5e5);
  46. }