Created
February 12, 2014 22:57
-
-
Save heyalexej/8966271 to your computer and use it in GitHub Desktop.
Dirtiest Download Script in the World!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# check for directories and create if non-existent. | |
for i in lala lulu | |
do | |
if [ -d $i ]; then | |
echo "Cool. Directory $i exists." | |
else | |
echo "Directory $i didn't exist so I knitted one for ya!" | |
mkdir $i | |
fi | |
done | |
# read from input file and download file from every url. move images to a different directory and rename them to their hash! | |
filename="$1" | |
url=$line | |
while read -r line | |
do | |
echo -e "\nRead from file - $url" | |
wget --user-agent="Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; GreenBrowser)" -P lala -e robots=off $line 2>&1 | grep -i "error" | |
for F in lala/*.*; do | |
echo "Downloaded $F" | |
done | |
for F in lala/*.*; do | |
echo "Renamed $F to $(md5sum "$F" | cut -d' ' -f1).${F##*.}"; | |
mv "$F" lulu/"$(md5sum "$F" | cut -d' ' -f1).${F##*.}"; | |
done | |
done < $filename | |
echo "We're done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Prolly the dirtiest Spaghetti script in the world. Worked well downloading several tens of thousands of images and rename them to their hash.
Why would you wanna do this? I had to download images from different resources to one folder. In order to avoid duplicates (IMG_XX.jpg, DSCXXX.jpg etc. are prone to that), I renamed them to their hash immediately after download.