From 45e4047c321be57459926d0479487f90950c3b97 Mon Sep 17 00:00:00 2001 From: vdbhb59 Date: Thu, 29 May 2025 15:46:56 +0530 Subject: [PATCH] handle imgur ip block https://git.lolcat.ca/lolcat/4get/commit/8d50667b0d9c9f5d2e1603fa2cb3d7bfb89feb8b --- scraper/imgur.php | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/scraper/imgur.php b/scraper/imgur.php index 23efe00..6e99a72 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); @@ -255,4 +279,4 @@ class imgur{ return $out; } -} +} \ No newline at end of file