From 06d62d4304e2c41a96f8adda49a0cef315b1c744 Mon Sep 17 00:00:00 2001 From: MatMasIt Date: Mon, 8 Nov 2021 18:29:45 +0100 Subject: [PATCH] Added isbn image fetcher --- isbnImage.php | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 isbnImage.php diff --git a/isbnImage.php b/isbnImage.php new file mode 100644 index 0000000..f27d8c1 --- /dev/null +++ b/isbnImage.php @@ -0,0 +1,39 @@ +time(),"url"=>$url]; + file_put_contents("2/isbnCacheImg.json", json_encode($data)); +} +function isbnImage($isbn){ + $url = cache_get($isbn); + if($url) return $url; + $curlSES=curl_init(); + curl_setopt($curlSES,CURLOPT_URL,"https://www.googleapis.com/books/v1/volumes?q=isbn:".urlencode($isbn)); + curl_setopt($curlSES,CURLOPT_RETURNTRANSFER,true); + curl_setopt($curlSES,CURLOPT_HEADER, false); + $result=curl_exec($curlSES); + curl_close($curlSES); + $data=json_decode($result,true); + if(!$data) return "books.png"; + $images=$data["items"][0]["volumeInfo"]["imageLinks"]; + $lak = array_keys($images); + $le = $lak[count($lak)-1]; + $url = $images[$le]?: "books.png"; + cache_set($isbn,$url); + return $url; +} +?>