Oops! It appears that you have disabled your Javascript. In order for you to see this page as it is meant to appear, we ask that you please re-enable your Javascript!

Download a public photo gallery from Dropbox

Today I’ve received a link to a public Dropbox photo gallery. I wanted to download all the pictures without having to click on them one by one.

Doing a little search I found that someone had already solved this problem with a simple Bash Shell Script. I’ve tested it and it works pretty well.

You can find the script (with the appropriate credits) below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
#
# Call this with the URL of a public dropbox photo gallery as the first
# argument, a destination directory as the second argument, and optionally
# give a size (thumbnail|large|extralarge|original) for the third argument
# (defaults to original)
#
# Initial version written 1st June 2010, by Andrew Scheller
#
# Added quoting (so it works if urls or paths contain spaces) on 10th July 2010
#
# Tweaked to use either wget or curl, 17th January 2011
#

# get binary locations
WGET=$(which wget)
CURL=$(which curl)
if [ -z "$WGET" ] && [ -z "$CURL" ]
then
  echo "Please install either wget or curl" >&2
  exit 1
fi

if [ -z "$1" ]
then
  echo "Required argument (gallery URL) not given"
  exit 1
fi
GALLERY_URL=$1
if [ -z "$2" ]
then
  echo "Required argument (destination dir) not given"
  exit 1
else
  if [ ! -d "$2" ]
  then
    echo "Destination dir '$2' doesn't exist"
    exit 1
  fi
fi
DESTDIR=$2
SIZE=original
if [ ! -z "$3" ]
then
  if [[ "$3" == "thumbnail" || "$3" == "large" || "$3" == "extralarge" || "$3" == "original" ]]
  then
    SIZE=$3
  else
    echo "Size must be one of (thumbnail|large|extralarge|original)"
    exit 1
  fi
fi

TEMP=$(mktemp)
if [ "$WGET" ]
then
  "$WGET" -q "$GALLERY_URL" -O "$TEMP"
elif [ "$CURL" ]
then
  "$CURL" "$GALLERY_URL" -o "$TEMP" -s
fi
if [ $? -ne 0 ]
then
  echo "Something went wrong! Couldn't download the gallery index page"
  rm "$TEMP"
  exit 1
fi
IFS='
'

FILENAMES=( $(grep "'filename': " "$TEMP" | cut -d"'" -f4) )
IMAGE_URLS=( $(grep "'$SIZE': " "$TEMP" | cut -d'"' -f2) )
rm "$TEMP"
TOTAL_FILENAMES=${#FILENAMES[@]}
TOTAL_IMAGES=${#IMAGE_URLS[@]}
if [ $TOTAL_FILENAMES -ne $TOTAL_IMAGES ]
then
  echo "Something went wrong! Got list of $TOTAL_FILENAMES filenames but $TOTAL_IMAGES images"
  exit 1
fi

for ((i=0;i<$TOTAL_IMAGES;i++))
do
  echo "Downloading ${FILENAMES[$i]} ($(($i + 1))/$TOTAL_IMAGES)"
  if [ "$WGET" ]
  then
    "$WGET" -q "${IMAGE_URLS[$i]}" -O "$DESTDIR/${FILENAMES[$i]}"
  elif [ "$CURL" ]
  then
    "$CURL" "${IMAGE_URLS[$i]}" -o "$DESTDIR/${FILENAMES[$i]}" -s
  fi
done
exit 0

Here are some instructions on how to use the script:

  1. Copy the script
  2. Make it executable
  3. Call it with the URL of the gallery and a (pre-existing) destination directory:

    download_dropbox_gallery.sh “http://url_to_the_public_gallery_on_dropbox” output_directory

  4. If you want you can also choose to download the photos in a different size (choose from thumbnail, large, extralarge or original)

    download_dropbox_gallery.sh “http://url_to_the_public_gallery_on_dropbox” output_directory large

You can find more information on the original post

© 2011, fbastian. All rights reserved.

Leave a Reply

%d bloggers like this: