diff options
| author | lolcat <will@lolcat.ca> | 2025-05-27 20:03:40 -0400 |
|---|---|---|
| committer | lolcat <will@lolcat.ca> | 2025-05-27 20:03:40 -0400 |
| commit | 8d50667b0d9c9f5d2e1603fa2cb3d7bfb89feb8b (patch) | |
| tree | 5ff6e786ad4f6a82884175abcf1b5058f25aea9c /scraper/imgur.php | |
| parent | a0545b60063c72db4322da78cf8529640346dcf1 (diff) | |
handle imgur ip block
Diffstat (limited to 'scraper/imgur.php')
| -rw-r--r-- | scraper/imgur.php | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/scraper/imgur.php b/scraper/imgur.php index 23efe00..e41f4c2 100644 --- a/scraper/imgur.php +++ b/scraper/imgur.php @@ -182,6 +182,23 @@ class imgur{ throw new Exception("Failed to fetch HTML"); } + $json = json_decode($html, true); + + if($json){ + + // {"data":{"error":"Imgur is temporarily over capacity. Please try again later."},"success":false,"status":403} + + if(isset($json["data"]["error"])){ + + if(stripos($json["data"]["error"], "capacity")){ + + throw new Exception("Imgur IP blocked this 4get instance or request proxy. Try again"); + } + } + + throw new Exception("Imgur returned an unknown error (IP ban?)"); + } + $this->fuckhtml->load($html); $posts = @@ -197,7 +214,14 @@ class imgur{ $image = $this->fuckhtml - ->getElementsByTagName("img")[0]; + ->getElementsByTagName("img"); + + if(count($image) === 0){ + + continue; + } + + $image = $image[0]; $image_url = "https:" . substr($this->fuckhtml->getTextContent($image["attributes"]["src"]), 0, -5); |
