Skip to content

Instantly share code, notes, and snippets.

@bugb
Forked from hrpunio/picasa_upld.sh
Created May 7, 2021 08:56
Show Gist options
  • Save bugb/6263f984ed317b4f6ffabd9d0b6b8b57 to your computer and use it in GitHub Desktop.
Save bugb/6263f984ed317b4f6ffabd9d0b6b8b57 to your computer and use it in GitHub Desktop.
Upload pic_file to Google photos/Picasa with curl; returns source image URL
#!/bin/bash
# Upload pic_file to Google photos/Picasa with curl; returns source image URL
#
# Usage: picasa.sh -s SCALE -a ALBUMID -t PIC_NAME -u -r pic_file
# -s SCALE -- scale pic_file to SCALE% (with imagemagic's convert)
# -a ALBUMID -- if not given upload to default album
# -t PIC_NAME -- picture name, if not given the same as pic_file
# -u -- print HTML fragment with URL to pic_file
# -r -- remove scaled pic_file
#
# Note: Images larger than 2048 x 2048 pixels do not count towards Google
# free account limits.
# As the limit is low it is useful to reduce size of photos
# which exceed 2048 x 2048 pixels.
#
# Default album iD:
ALBUM_ID=5814486831826593553
# User ID:
USER_ID=116390720146821374745
#
# Google account and password:
username=????????
password='????????'
while test $# -gt 0; do
case "$1" in
-s) shift; SCALE_R="$1";;
-s*) SCALE_R="`echo :$1 | sed 's/^:-s//'`";;
-a) shift; ALBUM_ID="$1";;
-a*) ALBUM_ID="`echo :$1 | sed 's/^:-a//'`";;
-t) shift; PIC_TITLE="$1";;
-t*) PIC_TITLE="`echo :$1 | sed 's/^:-t//'`";;
-l) URL="Y" ;;
-u) URL="Y" ;;
-r) REMOVE_SCALED="Y" ;;
###############
*) PIC_FILE="$1";;
esac
shift
done
LOGFILE="$ALBUM_ID.log"
# the -z operator checks whether the string is null:
if [ -z "$SCALE_R" ] ; then
my_pic="$PIC_FILE"
else
my_pic_orig="$PIC_FILE"
## basename_s.extension :
## http://www.linuxjournal.com/content/bash-parameter-expansion
my_pic="${PIC_FILE%.*}_s.${PIC_FILE#*.}"
my_scaled_pic="$my_pic"
##
convert $my_pic_orig -resize "${SCALE_R}%" $my_pic
fi
if [ -z "$PIC_TITLE" ] ; then
pic_title=`basename $my_pic`
else
pic_title="$PIC_TITLE"
fi
pic_type=`file -b --mime-type "$my_pic"`
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}' )
album_xml="http://picasaweb.google.com/data/feed/api/user/$USER_ID/albumid/$ALBUM_ID?authkey=$auth_key"
URL=`curl -s --request POST --data-binary "@$my_pic" --header "Slug: $pic_title" --header "Content-Type: $pic_type" --header "Authorization: GoogleLogin auth=$auth_key" "$album_xml" |
sed 's/.*media:content url='"'"'\([^'"'"']*\).*media:thumbnail url='"'"'\([^'"'"']*\).*/\1/'`
PRE_URL=${URL%/*}
PST_URL=${URL##*/}
CSS_STYLE="margin-bottom: 1em; margin-right: .1em;"
if [ -z "$URL" ] ; then
echo $URL
else
echo "<!-- $URL -->"
echo "<span><a href='$PRE_URL/s1600/$PST_URL' style='$CSS_STYLE'><img border='0' height='85' alt='' src='$PRE_URL/s200/$PST_URL'/></a></span>"
echo "<span><a href='$PRE_URL/s1600/$PST_URL' style='$CSS_STYLE'><img border='0' height='85' alt='' src='$PRE_URL/s200/$PST_URL'/></a></span>" >> $LOGFILE
fi
if [ "$REMOVE_SCALED" = "Y" ] ; then
if [ -e "$my_scaled_pic" ] ; then
rm "$my_scaled_pic"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment