/ Published in: Bash
This is modified from the last script which I didn't write. It allows you to upload the contents of a directory of images with the extension .JPG.
You just need to the full path to the directory.
Any comments improvements welcome
Expand |
Embed | Plain Text
#!/bin/bash # Usage $1 path to folder #functions capitalize_ichar () { string0="$@" firstchar=${string0:0:1} string1=${string0:1} FirstChar=`echo "$firstchar" | tr a-z A-Z` echo "$FirstChar$string1" } full_path=$1 album_name=`basename $full_path` ### Your google account and password username= password= cd $full_path auth_key=$( curl -s https://www.google.com/accounts/ClientLogin -d Email="$username"@gmail.com -d Passwd="$password" -d accountType=GOOGLE -d source=Google-cURL-Example -d service=lh2 | awk -F\= '/^Auth=/{print $2}' ) picasa_default_out="picasa_default.tmp" picasa_album_addrs="picasa_album_addrs.tmp" picasa_album_names="picasa_album_names.tmp" picasa_result="picasa_result.tmp" picasa_new_album="picasa_new_album.tmp" picasa_result_upload="picasa_result_upload.tmp" curl -s --header "Authorization: GoogleLogin auth=$auth_key" "http://picasaweb.google.com/data/feed/api/user/default" > "$picasa_default_out" idx=1 cat "$picasa_default_out" | tr '>' '\n' | grep "</gphoto:name" | cut -d'<' -f 1 > "$picasa_album_names" cap_album_name=`capitalize_ichar $album_name` if grep -q $cap_album_name $picasa_album_names then echo "Album already exists" else echo "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gphoto='http://schemas.google.com/photos/2007'>" >> album.xml echo "<category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/photos/2007#album' />" >> album.xml echo "<title type='text'>$album_name</title>" >> album.xml echo "<summary type='text'></summary>" >> album.xml echo "<gphoto:location></gphoto:location>" >> album.xml echo "<gphoto:access>public</gphoto:access>" >> album.xml echo "<gphoto:commentingEnabled>true</gphoto:commentingEnabled>" >> album.xml echo "</entry>" >> album.xml curl --silent --request POST --data "@album.xml" --header "Content-Type: application/atom+xml" --header "Authorization: GoogleLogin auth=$auth_key" "http://picasaweb.google.com/data/feed/api/user/$username" > "$picasa_result" cat "$picasa_result" | tr '>' '\n' | grep "</gphoto:id" | cut -d'<' -f 1 > "$picasa_new_album" album_addr=$( head -1 "$picasa_new_album" ) echo "---------------------------" echo "Album $album_name added" echo "---------------------------" num_images=0 for f in *.JPG do echo "Processing $f file..." mime_type=$( file -ib "$f" ) curl -s --request POST --data-binary "@$f" --header "Slug: $f" --header "Content-Type: $mime_type" --header "Authorization: GoogleLogin auth=$auth_key" "http://picasaweb.google.com/data/feed/api/user/$username/albumid/$album_addr" >> "$picasa_result_upload" echo "Uploaded $f file..." num_images=`expr $num_images + 1`; done echo "---------------------------" echo "Uploaded $num_images file/s" echo "---------------------------" fi #tidy up files=$(ls $full_path/*.tm 2> /dev/null | wc -l) if [ $files ] then rm *.tmp fi if [ -f album.xml ] then rm album.xml fi
Comments
Subscribe to comments
You need to login to post a comment.

It also checks against existing 'albums'!
In line 72 you forgot to change matpolster to $username.
@hansgf - thanks edited but not tested