Menu

PicasaUploader

Anonymous

Introduction

Script for upload images to Picasaweb

Additional software:

code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#! /bin/bash

AUTHFILE=${XDG_CACHE_HOME:-$HOME/.cache}/google.auth
YAD="yad --window-icon=web-browser --name=${0##*/}"

# remove temporary files
function atexit () {
    rm -f /tmp/res /tmp/google.xsl
}

# create stylesheet
cat > /tmp/google.xsl <<EOF
<?xml version='1.0' encoding='utf-8'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                              xmlns:atom="http://www.w3.org/2005/Atom"
                              xmlns:gphoto='http://schemas.google.com/photos/2007'>
<xsl:output method="text" omit-xml-declaration="yes" encoding="utf-8"/>
<xsl:template match="//atom:feed">
  GOOGLE_USER="<xsl:value-of select="atom:title"/>"
  ALBUMS=(<xsl:for-each select="//atom:entry">
            "<xsl:value-of select="gphoto:id"/>"
            "<xsl:value-of select="atom:title"/>"
          </xsl:for-each>)
</xsl:template>
</xsl:stylesheet>
EOF

# cleanup on exit
trap atexit EXIT

# login
if [[ -e $AUTHFILE ]]; then
    source $AUTHFILE
else
    eval $($YAD --image=gtk-dialog-authentication --title="Picasa login" \
    --text="<b>Login to google account</b>" --form \
    --field="Login:" --field="Password::H" | awk -F'|' '{printf "EMAIL=%s\nPASS=%s\n", $1, $2}')
    [[ -z $EMAIL || -z $PASS ]] && exit 1

    eval $(curl https://www.google.com/accounts/ClientLogin -sS --insecure \
    --data-urlencode Email="$EMAIL" --data-urlencode Passwd="$PASS" \
    -d accountType=GOOGLE -d source="$0" -d service=lh2)

    if [[ -z $Auth ]]; then
    $YAD --title="Login error" --image=dialog-error --button=gtk-close --text="Login failed: $Error"
    exit 1
    fi

    mkdir -p ${XDG_CACHE_HOME:-$HOME/.cache}
    echo "Auth=$Auth" > $AUTHFILE
fi

# get albums list
eval $(curl --silent --header "Authorization: GoogleLogin auth=$Auth" \
    "http://picasaweb.google.com/data/feed/api/user/default" | xsltproc /tmp/google.xsl -)
for ((i=1; i<${#ALBUMS[@]}; i+=2)); do
    alb="$alb!${ALBUMS[$i]}"
done

# select album and file
eval $($YAD --title="Upload to picasa" --text="Upload to Picasa" \
    --form --field="Album::CB" --field="Title:" --field="File::FL" \
    "$alb" "" "$1" | awk -F'|' '{printf "ALBUM=\"%s\"\nTITLE=\"%s\"\nFILENAME=\"%s\"\n", $1, $2, $3}')
[[ -z $ALBUM || -z $FILENAME ]] && exit 1

for ((i=1; i<${#ALBUMS[@]}; i+=2)); do
    if [[ $ALBUM == ${ALBUMS[$i]} ]]; then
    URI=http://picasaweb.google.com/data/feed/api/user/$GOOGLE_USER/albumid/${ALBUMS[(($i-1))]}
    break
    fi
done
TYPE=$(file -b --mime-type $FILENAME)

# upload file
curl --request POST --data-binary "@$FILENAME" --header "Slug: $TITLE" \
    --header "Content-Type: $TYPE" --header "Authorization: GoogleLogin auth=$Auth" \
    "$URI" 2>&1 > /tmp/res | $YAD --button=gtk-cancel:1 --title="Upload to Picasa" \
    --text="Upload '$FILENAME' to '$ALBUM'" --progress --auto-close --auto-kill

if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
    $YAD --title="Upload error" --image=dialog-error --button=gtk-close --text="Upload failed: $(< /tmp/res)"
fi

exit 0