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

  1. <?php
  2. // Channelate
  3. // A fairly simple WordPress site
  4. // Start by navigating to the latest comic
  5. $html = file_get_contents('https://www.channelate.com/');
  6. preg_match('@img src="https://www.channelate.com/wp-content/uploads/(.+\\.png)@', $html, $matches);
  7. if (empty($matches[1])) {
  8. echo "No comic found on home page! :(\n";
  9. return;
  10. }
  11. if (!is_dir('channelate')) {
  12. mkdir('channelate');
  13. }
  14. // Download current page's comic, load previous comic webpage, repeat
  15. while (true) {
  16. $filename = basename($matches[1]);
  17. if (is_file('channelate/' . $filename)) {
  18. return;
  19. }
  20. echo "Downloading {$filename}\n";
  21. $url = "https://www.channelate.com/wp-content/uploads/{$matches[1]}";
  22. $data = @file_get_contents($url);
  23. if ($data) {
  24. file_put_contents("channelate/{$filename}", $data);
  25. }
  26. // Find previous page link
  27. $regex = '@href="(https://www.channelate.com/comic/[0-9a-zA-Z/-]+)" class="navi comic-nav-previous 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('@img src="https://www.channelate.com/wp-content/uploads/(.+\\.png)@', $html, $matches);
  39. if (empty($matches[1])) {
  40. echo "No image found on page!\n";
  41. return;
  42. }
  43. usleep(5e5);
  44. }