more error handling for yep
This commit is contained in:
		
							parent
							
								
									92d0102738
								
							
						
					
					
						commit
						2007907972
					
				| @ -350,21 +350,7 @@ class yep{ | ||||
| 			throw new Exception("Failed to fetch JSON"); | ||||
| 		} | ||||
| 		 | ||||
| 		// detect cloudflare page
 | ||||
| 		$this->fuckhtml->load($json); | ||||
| 		 | ||||
| 		if( | ||||
| 			count( | ||||
| 				$this->fuckhtml | ||||
| 				->getElementsByClassName( | ||||
| 					"cf-wrapper", | ||||
| 					"div" | ||||
| 				) | ||||
| 			) !== 0 | ||||
| 		){ | ||||
| 			 | ||||
| 			throw new Exception("Blocked by Cloudflare"); | ||||
| 		} | ||||
| 		$this->detect_cf($json); | ||||
| 		 | ||||
| 		$json = json_decode($json, true); | ||||
| 		//$json = json_decode(file_get_contents("scraper/yep.json"), true);
 | ||||
| @ -539,7 +525,6 @@ class yep{ | ||||
| 		try{ | ||||
| 			 | ||||
| 			$json = | ||||
| 				json_decode( | ||||
| 				$this->get( | ||||
| 					$this->backend->get_ip(), // no nextpage!
 | ||||
| 					"https://api.yep.com/fs/2/search", | ||||
| @ -551,14 +536,16 @@ class yep{ | ||||
| 						"safeSearch" => $nsfw, | ||||
| 						"type" => "images" | ||||
| 					] | ||||
| 					), | ||||
| 					true | ||||
| 				); | ||||
| 		}catch(Exception $error){ | ||||
| 			 | ||||
| 			throw new Exception("Failed to fetch JSON"); | ||||
| 		} | ||||
| 		 | ||||
| 		$this->detect_cf($json); | ||||
| 		 | ||||
| 		$json = json_decode($json, true); | ||||
| 		 | ||||
| 		if($json === null){ | ||||
| 			 | ||||
| 			throw new Exception("Failed to decode JSON"); | ||||
| @ -636,7 +623,6 @@ class yep{ | ||||
| 			 | ||||
| 			// https://api.yep.com/fs/2/search?client=web&gl=CA&no_correct=false&q=undefined+variable+javascript&safeSearch=off&type=web
 | ||||
| 			$json = | ||||
| 				json_decode( | ||||
| 				$this->get( | ||||
| 					$this->backend->get_ip(), | ||||
| 					"https://api.yep.com/fs/2/search", | ||||
| @ -649,14 +635,15 @@ class yep{ | ||||
| 						"safeSearch" => $nsfw, | ||||
| 						"type" => "news" | ||||
| 					] | ||||
| 					), | ||||
| 					true | ||||
| 				); | ||||
| 		}catch(Exception $error){ | ||||
| 			 | ||||
| 			throw new Exception("Failed to fetch JSON"); | ||||
| 		} | ||||
| 		 | ||||
| 		$this->detect_cf($json); | ||||
| 		 | ||||
| 		$json = json_decode($json, true); | ||||
| 		//$json = json_decode(file_get_contents("scraper/yep.json"), true);
 | ||||
| 		 | ||||
| 		if($json === null){ | ||||
| @ -698,6 +685,26 @@ class yep{ | ||||
| 	} | ||||
| 	 | ||||
| 	 | ||||
| 	private function detect_cf($payload){ | ||||
| 		 | ||||
| 		// detect cloudflare page
 | ||||
| 		$this->fuckhtml->load($payload); | ||||
| 		 | ||||
| 		if( | ||||
| 			count( | ||||
| 				$this->fuckhtml | ||||
| 				->getElementsByClassName( | ||||
| 					"cf-wrapper", | ||||
| 					"div" | ||||
| 				) | ||||
| 			) !== 0 | ||||
| 		){ | ||||
| 			 | ||||
| 			throw new Exception("Blocked by Cloudflare"); | ||||
| 		} | ||||
| 	} | ||||
| 	 | ||||
| 	 | ||||
| 	private function titledots($title){ | ||||
| 		 | ||||
| 		$substr = substr($title, -4); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 lolcat
						lolcat