aboutsummaryrefslogtreecommitdiffstats
path: root/scraper/imgur.php
diff options
context:
space:
mode:
authorlolcat <will@lolcat.ca>2025-05-27 20:03:40 -0400
committerlolcat <will@lolcat.ca>2025-05-27 20:03:40 -0400
commit8d50667b0d9c9f5d2e1603fa2cb3d7bfb89feb8b (patch)
tree5ff6e786ad4f6a82884175abcf1b5058f25aea9c /scraper/imgur.php
parenta0545b60063c72db4322da78cf8529640346dcf1 (diff)
handle imgur ip block
Diffstat (limited to 'scraper/imgur.php')
-rw-r--r--scraper/imgur.php26
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);
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage