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.

50 lines
1.3 KiB

  1. <?php
  2. // Loading Artist
  3. // A bit tricky, but not too bad
  4. // Start by navigating to the latest comic
  5. $html = file_get_contents('https://loadingartist.com/latest');
  6. preg_match('@/uploads/([0-9]+/[0-9]+)/([0-9a-zA-Z-]+\\.[a-z]{3,4})@', $html, $matches);
  7. if (empty($matches[2])) {
  8. echo "No comic found on starting page! :(\n";
  9. return;
  10. }
  11. if (!is_dir('loadingartist')) {
  12. mkdir('loadingartist');
  13. }
  14. // Download current page's comic, load previous comic webpage, repeat
  15. while (true) {
  16. if (is_file('loadingartist/' . $matches[2])) {
  17. return;
  18. }
  19. echo "Downloading {$matches[2]}\n";
  20. $url = "https://loadingartist.com/wp-content/uploads/{$matches[1]}/{$matches[2]}";
  21. $data = @file_get_contents($url);
  22. if ($data) {
  23. file_put_contents("loadingartist/{$matches[2]}", $data);
  24. }
  25. // Find previous page link
  26. $regex = '@class="normal highlight prev comic-thumb" href="(https://loadingartist.com/comic/[0-9a-zA-Z-]+/?)"@';
  27. preg_match($regex, $html, $prevMatch);
  28. if (empty($prevMatch[1])) {
  29. echo "No previous URL found!\n";
  30. return;
  31. }
  32. $html = @file_get_contents($prevMatch[1]);
  33. if (!$html) {
  34. echo "Failed to load previous page!\n";
  35. return;
  36. }
  37. preg_match('@/uploads/([0-9]+/[0-9]+)/([0-9a-zA-Z-]+\\.[a-z]{3,4})@', $html, $matches);
  38. usleep(5e5);
  39. }