2 # dropbox_recursive recursively downloads files from dropbox
3 # and is released under the terms of the GNU GPL version 3, or any
4 # later version, at your option. See the file README and COPYING for
6 # Copyright 2014 by Don Armstrong <don@donarmstrong.com>.
17 dropbox_recursive - recursively downloads files from dropbox
21 dropbox_recursive [options] dropboxurl1 [additional dropbox urls]
24 --debug, -d debugging level (Default 0)
25 --help, -h display this help
26 --man, -m display manual
34 Debug verbosity. (Default 0)
38 Display brief usage information.
48 dropbox_recursive https://www.dropbox.com/sh/foo/bar
55 my %options = (debug => 0,
61 'debug|d+','help|h|?','man|m');
63 pod2usage() if $options{help};
64 pod2usage({verbose=>2}) if $options{man};
66 $DEBUG = $options{debug};
73 push @USAGE_ERRORS,"You must give at least one dropbox url";
76 pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS;
80 my $mech = WWW::Mechanize->new();
90 my @links = $m->find_all_links(class=>"filename-link");
91 print STDERR map {$_->url()."\n"} @links;
92 for my $link (@links) {
93 $m->get($link->url());
94 my ($name) = $m->uri() =~ m{/([^/]+)$};
95 $name = uri_unescape($name);
96 # see if there is a download button
97 my @download_button = $m->find_all_links(id=>'default_content_download_button');
98 # If there's a download button, then we've visted the link for a
100 if (@download_button) {
101 print STDERR "getting file $name\n";
102 $m->get($download_button[0]->url(),':content_file'=>$name);
103 print STDERR "got file $name\n";
105 # there isn't a download button, so we must have visited
106 # the link for a directory
107 mkdir $name unless -d $name;
108 print STDERR "made directory $name\n";
109 chdir $name or die "Unable to chdir to $name";