Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Placing images in subfolder based on Tumblr name. #1

Merged
merged 9 commits into from

2 participants

@parkr

Make for a more organized pull from multiple Tumblrs.

@nixterrimus
Owner

Thanks, Parker! One problem with this is that if an image is reblogged across several tumblrs then it will be repeated in each folder. Do you think this is a big deal? Is it ok to have 3 copies of cute_kitten.jpg if it's reblogged twice?

@parkr

That's true! I see no issue with this in the way I use tumbld.sh (essentially to backup/archive a tumblr), as I would like to have every image from the blog anyway, whether it was reblogged by site B or not.

@nixterrimus
Owner

Good point, interesting to hear how you're using it too! Can you make the script accept an argument to save to folders? Maybe something like ./tumbld -f?

@parkr

That would be good, yeah. I'll have to rework the way tumbld.sh works with arguments.

@parkr

Was just looking through my open pull requests and decided I'd do this.

At first, I wanted to use getopts which is kinda neat, but not suitable for the needs of this script. I just tried it and it all works fine.

@parkr

Let me know if you'd like me to make any further changes.

@nixterrimus nixterrimus merged commit 859f8fb into from
@parkr parkr deleted the branch
@parkr

Oh, hey! Forgot about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 64 additions and 14 deletions.
  1. +2 −0  readme.md
  2. +62 −14 tumbld.sh
View
2  readme.md
@@ -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
76 tumbld.sh
@@ -2,6 +2,16 @@
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 \
@@ -9,26 +19,64 @@ download_site()
# 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
Something went wrong with that request. Please try again.