From 8d50667b0d9c9f5d2e1603fa2cb3d7bfb89feb8b Mon Sep 17 00:00:00 2001 From: lolcat Date: Tue, 27 May 2025 20:03:40 -0400 Subject: [PATCH] handle imgur ip block --- scraper/imgur.php | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) 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);