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.

62 lines
1.6 KiB

  1. <?php
  2. // Least I Could Do
  3. // A bit tricky, but not too bad
  4. // Start with home page and navigate to latest comic
  5. $home = file_get_contents('http://www.leasticoulddo.com/');
  6. $regex = '@href="(http://www.leasticoulddo.com/comic/[0-9]+/?)" id="feature-comic"@';
  7. preg_match($regex, $home, $homeMatch);
  8. if (!empty($homeMatch[1])) {
  9. $html = file_get_contents($homeMatch[1]);
  10. preg_match('@/uploads/([0-9]+/[0-9]+)/([0-9]+\\.[a-z]{3,4})@', $html, $matches);
  11. } else {
  12. echo "Unable to find link to latest comic! :(\n";
  13. return;
  14. }
  15. if (empty($matches[2])) {
  16. echo "No comic found on home page! :(\n";
  17. return;
  18. }
  19. if (!is_dir('licd')) {
  20. mkdir('licd');
  21. }
  22. // Download current page's comic, load previous comic webpage, repeat
  23. while (true) {
  24. if (is_file('licd/' . $matches[1])) {
  25. return;
  26. }
  27. echo "Downloading {$matches[2]}\n";
  28. $url = "http://www.leasticoulddo.com/wp-content/uploads/{$matches[1]}/{$matches[2]}";
  29. $data = @file_get_contents($url);
  30. if ($data) {
  31. file_put_contents("licd/{$matches[2]}", $data);
  32. }
  33. // Find previous page link
  34. $regex = '@href="(http://www.leasticoulddo.com/comic/[0-9]+/?)" id="nav-large-prev"@';
  35. preg_match($regex, $html, $prevMatch);
  36. if (empty($prevMatch[1])) {
  37. echo "No previous URL found!\n";
  38. return;
  39. }
  40. $html = @file_get_contents($prevMatch[1]);
  41. if (!$html) {
  42. echo "Failed to load previous page!\n";
  43. return;
  44. }
  45. preg_match('@/uploads/([0-9]+/[0-9]+)/([0-9]+\\.[a-z]{3,4})@', $html, $matches);
  46. if (empty($matches[1])) {
  47. echo "No image found on page!\n";
  48. return;
  49. }
  50. usleep(5e5);
  51. }