This is a really quick and dirty script I banged out in about a half-hour to download all the wallpapers at
Space.com. I like reading the articles at
Space.com from time to time and I found the wallpapers there are pretty cool. I wanted to grab them all and use them for my Mac OS X screensaver. Of course, downloading them individually (click, click, click, right-click, save as, etc... - ad infinitum), is a pain in the ass. So, the
Space.com Wallpaper Download (sdcwd) script was born!
The script recursively downloads all the images of the specified size, creating folders for each collection. Just start it and let it run!
I used the following software and versions, you'll need
'-o' support in
grep for sure and have
curl and
wget installed. Of course, if the urls change at
Space.com, this script will be broken. Your mileage may vary.
Software Versions:
curl - curl 7.13.1
grep - grep (GNU grep) 2.5.1
wget - GNU Wget 1.8.2
#!/bin/bash
# Space.com Wallpaper Download (sdcwd)
image_size="1280" # Set this to 640, 800, 1024, or 1280 depending on the image size you want
collections=(`curl -s http://www.space.com/php/multimedia/downloads/wallpapers/collection.php?collection=adrian_lark | \
grep -o 'option value="collection.php?collection=\(.*\)"' | \
sed 's,option value="collection.php?collection=\(.*\)",\1,'`)
collection_url="http://www.space.com/php/multimedia/downloads/wallpapers/collection.php?collection="
image_url="http://a52.g.akamaitech.net/f/52/827/1d/www.space.com/entertainment/downloads/spaceart/images/"
logFile="sdcwd.log"
topDir="Space.com_Wallpapers"
getImages()
{
this_collection="$1"
collurl="${collection_url}${this_collection}"
if [ ! -d "$this_collection" ]; then
mkdir "$this_collection"
cd "$this_collection"
# Log
echo "----------------------------" >> "../$logFile"
echo "$this_collection" >> "../$logFile"
echo "----------------------------" >> "../$logFile"
curl -s "$collurl" | grep "/php/multimedia/imagedisplay/wallpaper_display.php?pic=.*_$image_size\.jpg" | \
grep -o "pic=\(.*.jpg\)" | \
sed "s,pic=,$image_url," | \
tee -a "../$logFile" | \
xargs wget -q
# Log
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" >> "../$logFile"
echo >> "../$logFile"
cd ../
# If we didn't download any pics for this directory (maybe the requested size wasn't available)
# remove the empty directory.
find "$this_collection" -type d -empty | xargs rmdir
fi
}
old_dir="`pwd`"
mkdir "$topDir"
cd "$topDir"
for this_collection in ${collections[@]}
do
getImages "$this_collection"
done
cd "$old_dir"