Permalink
Browse files

Merge pull request #1 from parkr/subfolders

Placing images in subfolder based on Tumblr name.
  • Loading branch information...
2 parents ba1b228 + 86fcf35 commit 859f8fbfaed7d2c8189d3211ec1e66fb82f8a3a0 @nixterrimus committed Mar 6, 2013
Showing with 64 additions and 14 deletions.
  1. +2 −0 readme.md
  2. +62 −14 tumbld.sh
View
@@ -18,6 +18,8 @@ The file should contain a list of tumblr blog name with one on each line. For e
architectureblog
drawingarchitecture
+
+If desired, pass in `-s` as the first argument and the photos from these blogs will be placed into subfolders.
# Common Problems
View
@@ -2,33 +2,81 @@
download_site()
{
+ if [ "$USE_SUBFOLDERS" == "1" ]
+ then
+ # Go to subfolder for organized downloading
+ if [ ! -d "$site" ]
+ then
+ mkdir $site
+ fi
+ cd $site
+ fi
+
# Download the images using wget
wget --quiet -H -Dmedia.tumblr.com,$site.tumblr.com -r -R "*avatar*" -A "[0-9]" \
-A "*index*" -A jpeg,jpg,bmp,gif,png --level=10 -nd -nc -erobots=off \
http://$site.tumblr.com/
# Clean up pages needed to find images
rm -f 1 2 3 4 5 6 7 8 9 index.html
+
+ if [ "$USE_SUBFOLDERS" == "1" ]
+ then
+ cd ../
+ fi
}
+usage()
+{
+ cat << EOF
+ usage: $0 [options] file_or_site_name
+
+ download images from tumblr
-if [ $# -ne 1 ]
+ OPTIONS:
+ -h Show this message
+ -s Put downloaded images in subfolders
+EOF
+}
+
+# Ensure that there are args
+if [ $# -lt 1 ]
then
- echo "download images from tumblr"
- echo "Usage: `basename $0` file"
+ usage
exit $E_BADARGS
fi
-if [ -e $1 ]
+USE_SUBFOLDERS=0
+Sites=()
+
+# Parse args
+for var in "$@"
+do
+ if [ "$var" == "-s" ]; then
+ USE_SUBFOLDERS=1
+ else
+ Sites=("${Sites[@]}" "$var")
+ fi
+done
+
+# Ensure that a site or file of sites has been set
+if [ ${#Sites[@]} -lt 1 ]
+then
+ usage
+ exit $E_BADARGS
+fi
+
+# Act accordingly
+if [ -f ${Sites[0]} ]
then
- # Download a site of tumblrs using a file as source
- cat $1 | while read site; do
- if [[ $site != \#* ]]; then
- download_site $site
- fi
- done
+ # Download a site of tumblrs using a file as source
+ cat ${Sites[0]} | while read site; do
+ if [[ $site != \#* ]]; then
+ download_site $site
+ fi
+ done
else
- # download a single tumblr
- site=$1
- download_site $site
-fi
+ # download a single tumblr
+ site=${Sites[0]}
+ download_site $site
+fi

0 comments on commit 859f8fb

Please sign in to comment.