Posted By

matpolster on 07/23/09


Tagged

Bash picasa


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

ashloren


picasa upload directory of images


 / 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

  1. #!/bin/bash
  2. # Usage $1 path to folder
  3.  
  4. #functions
  5.  
  6. capitalize_ichar ()
  7. {
  8.  
  9. string0="$@"
  10. firstchar=${string0:0:1}
  11. string1=${string0:1}
  12. FirstChar=`echo "$firstchar" | tr a-z A-Z`
  13.  
  14. echo "$FirstChar$string1"
  15.  
  16. }
  17.  
  18. full_path=$1
  19. album_name=`basename $full_path`
  20.  
  21. ### Your google account and password
  22. username=
  23. password=
  24.  
  25.  
  26. cd $full_path
  27.  
  28.  
  29. 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}' )
  30.  
  31. picasa_default_out="picasa_default.tmp"
  32. picasa_album_addrs="picasa_album_addrs.tmp"
  33. picasa_album_names="picasa_album_names.tmp"
  34. picasa_result="picasa_result.tmp"
  35. picasa_new_album="picasa_new_album.tmp"
  36. picasa_result_upload="picasa_result_upload.tmp"
  37.  
  38.  
  39. curl -s --header "Authorization: GoogleLogin auth=$auth_key" "http://picasaweb.google.com/data/feed/api/user/default" > "$picasa_default_out"
  40.  
  41. idx=1
  42. cat "$picasa_default_out" | tr '>' '\n' | grep "</gphoto:name" | cut -d'<' -f 1 > "$picasa_album_names"
  43.  
  44.  
  45. cap_album_name=`capitalize_ichar $album_name`
  46.  
  47. if grep -q $cap_album_name $picasa_album_names
  48. then
  49. echo "Album already exists"
  50. else
  51. echo "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gphoto='http://schemas.google.com/photos/2007'>" >> album.xml
  52. echo "<category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/photos/2007#album' />" >> album.xml
  53. echo "<title type='text'>$album_name</title>" >> album.xml
  54. echo "<summary type='text'></summary>" >> album.xml
  55. echo "<gphoto:location></gphoto:location>" >> album.xml
  56. echo "<gphoto:access>public</gphoto:access>" >> album.xml
  57. echo "<gphoto:commentingEnabled>true</gphoto:commentingEnabled>" >> album.xml
  58. echo "</entry>" >> album.xml
  59. 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"
  60. cat "$picasa_result" | tr '>' '\n' | grep "</gphoto:id" | cut -d'<' -f 1 > "$picasa_new_album"
  61. album_addr=$( head -1 "$picasa_new_album" )
  62. echo "---------------------------"
  63. echo "Album $album_name added"
  64. echo "---------------------------"
  65. num_images=0
  66. for f in *.JPG
  67. do
  68. echo "Processing $f file..."
  69.  
  70. mime_type=$( file -ib "$f" )
  71.  
  72. 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"
  73. echo "Uploaded $f file..."
  74. num_images=`expr $num_images + 1`;
  75. done
  76. echo "---------------------------"
  77. echo "Uploaded $num_images file/s"
  78. echo "---------------------------"
  79.  
  80. fi
  81.  
  82. #tidy up
  83. files=$(ls $full_path/*.tm 2> /dev/null | wc -l)
  84. if [ $files ]
  85. then
  86. rm *.tmp
  87. fi
  88. if [ -f album.xml ]
  89. then
  90. rm album.xml
  91. fi

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: matpolster on July 23, 2009

It also checks against existing 'albums'!

Posted By: hansgf on September 11, 2009

In line 72 you forgot to change matpolster to $username.

Posted By: matpolster on March 7, 2010

@hansgf - thanks edited but not tested

Posted By: mesmariusz on June 30, 2014

Hello. This script stopped working for me a few days ago. I used it for daily new date-folder creation in Picasa. From a few days I'm getting as a resuls:

/home/pi/scripts/uploadtopicasa.sh: linia 55: echo: błąd zapisu: Brak miejsca na urządzeniu /home/pi/scripts/uploadtopicasa.sh: linia 56: echo: błąd zapisu: Brak miejsca na urządzeniu /home/pi/scripts/uploadtopicasa.sh: linia 57: echo: błąd zapisu: Brak miejsca na urządzeniu /home/pi/scripts/uploadtopicasa.sh: linia 58: echo: błąd zapisu: Brak miejsca na urządzeniu /home/pi/scripts/uploadtopicasa.sh: linia 59: echo: błąd zapisu: Brak miejsca na urządzeniu /home/pi/scripts/uploadtopicasa.sh: linia 60: echo: błąd zapisu: Brak miejsca na urządzeniu /home/pi/scripts/uploadtopicasa.sh: linia 61: echo: błąd zapisu: Brak miejsca na urządzeniu /home/pi/scripts/uploadtopicasa.sh: linia 62: echo: błąd zapisu: Brak miejsca na urządzeniu

(23) Failed writing body

Album 2014.06.30 added

Processing *.JPG file... (23) Failed writing body

Uploaded *.JPG file...

Uploaded 1 file/s

PS. It is written: Album 2014.06.30 added

But no "2014.06.30" folder exists on picasaweb.

Could someone please help me?

Thank you very much.

You need to login to post a comment.