From f2b22777b3c9d1f4cd51db6ed3a4cf78d39add0f Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 18 Apr 2016 10:25:43 -0400 Subject: Blacklisted an image server known to return bad images --- difference.cpp | 127 ++++++++++++++++++++++++--------------------------------- 1 file changed, 53 insertions(+), 74 deletions(-) diff --git a/difference.cpp b/difference.cpp index 6444efd..3d3bb18 100644 --- a/difference.cpp +++ b/difference.cpp @@ -36,6 +36,53 @@ std::string capitalize(std::string input) return result; } +bool downloadImage(std::string url, curl::curl_header headers, Magick::Blob& img, Magick::Image& pic) +{ + // willyfogg.com is a thumbnail generator known to return 200 even if the target image no longer exists + if (url.find("willyfogg.com/thumb.php") != std::string::npos) + { + return false; + } + + std::ostringstream imgbuf; + curl::curl_ios imgios(imgbuf); + curl::curl_easy imghandle(imgios); + + imghandle.add(headers.get()); + imghandle.add(url.c_str()); + imghandle.add(30); + + try { + imghandle.perform(); + } catch (curl::curl_easy_exception error) { + error.print_traceback(); + + return false; + } + + if (imghandle.get_info().get() != 200) + { + return false; + } + + if (std::string(imghandle.get_info().get()).substr(0, 6) != "image/") + { + return false; + } + + std::string imgstr = imgbuf.str(); + img = Magick::Blob(imgstr.c_str(), imgstr.length()); + pic.read(img); + if (pic.rows() == 0) + { + return false; + } + + std::cout << url << std::endl; + + return true; +} + int main(int argc, char** argv) { srand(time(NULL)); @@ -154,45 +201,11 @@ int main(int argc, char** argv) int curind = 0; for (; curind < lstvec.size(); curind++) { - std::ostringstream img1buf; - curl::curl_ios img1ios(img1buf); - curl::curl_easy img1handle(img1ios); - std::string img1url = lstvec[curind]; - - img1handle.add(headers.get()); - img1handle.add(img1url.c_str()); - img1handle.add(30); - - try { - img1handle.perform(); - } catch (curl::curl_easy_exception error) { - error.print_traceback(); - - continue; - } - - if (img1handle.get_info().get() != 200) + if (downloadImage(lstvec[curind], headers, img1, pic1)) { - continue; + success = true; + break; } - - if (std::string(img1handle.get_info().get()).substr(0, 6) != "image/") - { - continue; - } - - std::string img1str = img1buf.str(); - img1 = Magick::Blob(img1str.c_str(), img1str.length()); - pic1.read(img1); - if (pic1.rows() == 0) - { - continue; - } - - std::cout << img1url << std::endl; - success = true; - - break; } if (!success) @@ -205,45 +218,11 @@ int main(int argc, char** argv) Magick::Image pic2; for (curind++; curind < lstvec.size(); curind++) { - std::ostringstream img2buf; - curl::curl_ios img2ios(img2buf); - curl::curl_easy img2handle(img2ios); - std::string img2url = lstvec[curind]; - - img2handle.add(headers.get()); - img2handle.add(img2url.c_str()); - img2handle.add(30); - - try { - img2handle.perform(); - } catch (curl::curl_easy_exception error) { - error.print_traceback(); - - continue; - } - - if (img2handle.get_info().get() != 200) - { - continue; - } - - if (std::string(img2handle.get_info().get()).substr(0, 6) != "image/") - { - continue; - } - - std::string img2str = img2buf.str(); - img2 = Magick::Blob(img2str.c_str(), img2str.length()); - pic2.read(img2); - if (pic2.rows() == 0) + if (downloadImage(lstvec[curind], headers, img2, pic2)) { - continue; + success = true; + break; } - - std::cout << img2url << std::endl; - success = true; - - break; } if (!success) -- cgit 1.4.1