View previous topic :: View next topic |
Author |
Message |
Magic Banana Veteran
Joined: 13 Dec 2005 Posts: 1912 Location: Belo Horizonte, Minas Gerais, Brasil
|
Posted: Sat Jan 12, 2008 9:08 pm Post subject: [SCRIPT] Quickly download entire PicasaWeb albums |
|
|
[mylife]
I finally succeeded in making my mother understand that there exists cleaner ways to share her Christmas pictures than filling up her contacts' mail boxes. Thus, she has got a PicasaWeb "gallery" she feeds via F-Spot. She had such a success with her "novel" approach that the rest of the family now does the same. Now, she wants to download a whole album without having to visualize the pictures one by one.
[/mylife]
Google restricts the download of entire albums to users of its proprietary (and Windows only) software Picasa. Searching solutions on the Web, I discovered an incorrect Bash script having in dependency a XML parser and a C# program which was reported to work with Mono. All in all, nothing to please me. Furthermore, both take in argument the RSS feed address (instead of the URL of the album you receive in the invitation mail) and cannot download at once all the public albums of a given user.
Hence, I looked at the source code of PicasaWeb pages and quickly understood it will be easy to achieve my goals in a few lines of Bash and without any dependency (the most complicated commands I use are wget and grep!). Here is the result:
/usr/bin/picasaweb-download: | #!/bin/bash
# Distributed under the terms of the GNU General Public License v3 or later
# AUTHOR: Loïc Cerf
# e-mail: magicbanana@gmail.com
WGET_OPT="-q -T 180 -t 3 -c"
EX_USAGE=64
EX_NOHOST=68
if [ -z "$1" -o "$1" = "--help" -o "$1" = "-h" ]
then
echo "Usage: $0 url [destination]"
exit
fi
page=${1#*picasaweb.google.*/}
if [ "$page" = "$1" ]
then
echo "\"$1\" is not the URL of a PicasaWeb album or gallery" 1>&2
exit $EX_USAGE
fi
temp=`mktemp`
if wget $WGET_OPT -O $temp "$1"
then
finalPage=${page#*/}
if [ -z "$finalPage" -o "$finalPage" = "$page" ]
then
# $temp is a gallery
if [ -z "$2" ]
then
destination=`grep -m 1 "^var _user" $temp`
destination=${destination##*nickname:\"}
set "$1" "${destination%%\"*}"
fi
mkdir -p "$2"
cd "$2"
grep -E -o "$1"[/]?[[:alnum:]:.%~_-]+ $temp | sort | uniq |
while read album
do
"$0" $album &
done
else
# $temp is an album
if [ -z "$2" ]
then
destination=`grep -m 1 "^var _album" $temp`
destination=${destination##*title:\"}
set "$1" "${destination%%\"*}"
fi
grep -E -o {id:\"[0-9]+\",s:\"[[:alnum:]:\\.%~_-]+ $temp |
while read picture
do
picture=${picture##*\"}
picture=${picture/\x2Fs144/}
wget $WGET_OPT -P "$2" ${picture//\x2F//} &
done
fi
else
exit $EX_NOHOST
fi
rm $temp
|
Using this script is very easy: picasaweb-download URL [destination]
The URL may either point to an album (public or private with the authentication key terminating the URL) or a whole gallery. For example, the following command will download the album titled "GPLv3-2006 Conference" from the PicasaWeb gallery of "Ramprasad B":
Download an album: | $ picasaweb-download http://picasaweb.google.com/ramprasad.i82/GPLv32006Conference/ |
To download all his public albums:
Download a gallery: | $ picasaweb-download http://picasaweb.google.com/ramprasad.i82/ |
The destination is optional. If present, it is the directory (if it does not exist, it will be created) where the pictures will be downloaded. If absent, the album (respectively the gallery) will be downloaded in a directory having its title (respectively the author's nickname). In the case of a gallery, every album will be downloaded in a separate sub-directory bearing its name.
To be able to download galleries, this script must be saved in a directory of the PATH variable (typically /usr/bin).
Obtain the root permissions:
Obtain the root permissions: | $ su |
Open your favourite text editor (here gedit) on a new file in a directory of the PATH variable (here /usr/bin):
Edit /usr/bin/picasaweb-download: | # gedit /usr/bin/picasaweb-download |
Copy-paste the script in your text editor. Close it and, finally, make the script executable:
Make /usr/bin/picasaweb-download executable: | # chmod 755 /usr/bin/picasaweb-download |
Any feedback (even positive ) would be appreciated. |
|
Back to top |
|
|
Magic Banana Veteran
Joined: 13 Dec 2005 Posts: 1912 Location: Belo Horizonte, Minas Gerais, Brasil
|
Posted: Wed Jan 16, 2008 9:48 pm Post subject: |
|
|
Free Software is Good! A user, named Peter Woulfenberg, has just mailed me to suggest a very simple and clever improvement to my code. His proposal fits in one character: '&'. Placed at the end of the line downloading a picture, it makes this job run in the background. In this way, the script continues and starts downloading the rest of the pictures. Following the same idea, I made an analogous modification to grab several albums in parallel. This script is now amazingly fast. Thank Peter for these performances. Thank Free Software too. Indeed, if this software was proprietary, you would still be stuck with poor performances.
Just try it! I directly made the modifications on the first post of this thread.
I am not sure about it but I think this script now presents a limit bound to the maximum number of processes per user (there may be running as many wget processes as there are pictures to download). Any information about such an issue would be appreciated. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|