I had the music backed up, obviously, because that shit's too expensive to lose, and the movies I didn't really care about, so that left me with redownloading all of those stupid images I always think I'm going to post on forums and message boards but never do. Manually going through and finding them would take forever, especially since I'd collected most of them over a number of years, so instead of actually hunting for the pics, I hunted for a way to automate the task, at least a little bit.
Being a little bit of a geek, I knew there had to be a way to run a simple script from the command line (Linux, obviously). I considered writing a simple shell script myself, but regular expressions really don't like me, and I'm not familiar enough with shell scripting that I can just whip something up in just a few minutes. After a couple of hours of searching -- ok, maybe twenty minutes -- I finally found what I was looking for. A script to help me automatically download images from Google Image Search without having to use a single mouse click.
# First you'll have to concat a search term:echo "What terms?"; read terms; terms="${terms// /+}"# Insert in link like:# "http://images.google.com/images?q=${terms}&svnum=30&start=0"# Bash has no concept of "pages", so basically you'll iterate through the "start=$n" part until you're done# or until someone comes up with a less crude way:for n in $(seq 0 150); do links -source \"http://images.google.com/images?q=${terms}&safe=off&start=${n}" \| grep "href=/imgres?imgurl=" | tr "<>" " " | while read l; do for i in $l; do case "${i}" in href=/imgres*) \i="${i//&imgrefurl=/ }"; echo "${i//href=\/imgres?imgurl=/ }"|awk '{print $1}'|grep -i "\.jp";; esac; done; donedone# Now you should have a listing of images on stdout.# Pipe output to a temporary file and wget from that file.
The script, as it is, will output a list of links directly to images all over the web. I typically run it with the following command: ./imageSearch.sh | tee results.txt
The "tee results.txt" just writes the output to a text file, which I then download using wget -i results.txt (I use other options as well) and sit back and wait. When wget is finished downloading all the images, I simply use my favorite thumbnail program to sort out the duplicates and ones I don't want, and I'm done.
Now go have fun.
No comments:
Post a Comment