Now, before I get to the script itself, note that this is not a tutorial on how to write your own script. My programming skills leave a lot to be desired, I know, and I wouldn't dare instruct anyone on how to write any kind of script other than maybe a simple hello world script. So in case someone downloads this script and wants to comment about how much my coding skills suck, I'll save you the time. I already know that, so go away.
A few notes about the script itself. First, this script is absolutely NOT INTENDED FOR USE ON A PUBLIC SERVER! Hopefully I've made that clear enough. If you put this script on a public server and something bad happens as a result, then you suck, not me, because I've warned you. Feel free to run this on your own personal linux box on a home network, however, or better yet get the VMWare Player and run it on a virtual machine so as not to expose anything vital. I suppose it's possible to run this script on a Windows machine running apache, php, and with wget installed, but I haven't attempted it myself and don't intend to.
Specifics about what this script does: You enter a search term in the box. Then you tell the script how many results you want it to return (max 1000). Then, because Bing will only allow you to retrieve 50 results at a time, you tell it how many results per page you want to return. This is just to tell Bing how many results you want to process at one time. The script will continue to run until it reaches the total number of results you have indicated and then display them all on a single page.
You can set the adult content (Safe Search) filter level just like you can on the Bing website. There are three filtering options, none, moderate, and strict. You can also tell the script what size images to download (all, small, medium, large). The sizes are determined by Bing, not me, so don't complain if you select large and you get a bunch of tiny images, but for the most part it's pretty accurate.
Now for the important part. Display/downloading options. You have three choices:
- Full Size: This will display each search result at its full size in your browser, one above the other. It's fine for a small number of search results, but can use a ton of memory if you're trying to display a thousand large images all at once. This option does not save the images to your hard drive, however, so if you want to save any of them you have to right-click to save.
- Thumbnails: I put the most effort into this option, because it's what I prefer. It will display thumbnails of each search result, along with the dimensions and file size of the actual image, and the type of image (ie. jpg, gif, png). Clicking on the thumbnail will load the full size image in your browser. You can also check the box beneath each image that you want to download, then click the button at the bottom of the page to save the checked images to your hard drive. How fast that happens depends on your internet connection. The images are downloaded into the same directory where you placed the script.
- Display None/Direct Download (not recommended): This option doesn't display any images, but will print out the url of each image it is downloading. Images are downloaded to the directory where the script resides. This option is semi-dependent on how your permissions are set, because it first writes all of the urls to a text file, then executes wget to actually download the images from that text file. Not the ideal way to do it, but I never went back and changed it when I realized how stupid it was to do it that way. A final note on this option: Be very careful, because you can accidentally download scripts instead of just images this way. Some servers that disable hotlinking will replace the image with a script that can then be executed on your machine and wget seems to not know the difference.
That's pretty much it. Here are some screenshots so you can see what it looks like:
The first one is the initial search page:

This one is the thumbnail results page:
UPDATE: I removed this image because I realized that I left some debugging code in that shows my app id. I'll replace it with a different image tomorrow.
And that's pretty much the gist of it. You can download the full script from http://www.mediafire.com/?qwvd3damnwg. Have fun.
No comments:
Post a Comment