3 # Add tags to photos: --tag="cat,dog,animals"
5 import gdata.photos.service
9 from optparse import OptionParser
12 parser = OptionParser(usage="usage: %prog [options] images...", version="%prog v0.1.0")
13 parser.add_option("-t", "--title", dest="title", default="New Album", help="Set the album title")
14 parser.add_option("-s", "--summary", dest="summary", default="", help="Set the album summary")
16 (options, args) = parser.parse_args()
18 parser.error("Please specify at least one photo.")
21 print 'Please enter your Google Account information'
22 email = raw_input('Email: ')
23 password = getpass.getpass()
26 picasa = gdata.photos.service.PhotosService(email=email,password=password)
30 picasa.ProgrammaticLogin()
31 except gdata.service.CaptchaRequired:
32 sys.exit('Google required a captcha.')
33 except gdata.service.BadAuthentication:
34 sys.exit('Bad Authentication')
35 except gdata_client.Error:
36 sys.exit('Login Error')
40 # Get a list of Albums
42 albums = picasa.GetUserFeed()
43 except gdata.photos.service.GooglePhotosException as gpe:
46 # Find a matching album name
47 for a in albums.entry:
48 if a.title.text == options.title:
49 print 'Found existing album %s with %s photo(s)' % (a.title.text,a.numphotos.text)
53 # Create Album if we didn't find one.
55 print 'Creating Album: %s ' % options.title
57 album = picasa.InsertAlbum(title=options.title, summary=options.summary,access='private')
58 except gdata.photos.service.GooglePhotosException as gpe:
63 album_url = '/data/feed/api/user/default/albumid/%s' % (album.gphoto_id.text)
65 filename = os.path.abspath(a)
66 extension = os.path.splitext(filename)[1].lower()
67 if extension=='.jpg' or extension=='.jpeg':
68 print 'Uploading %s' % filename
69 photo = picasa.InsertPhotoSimple(album_url,'New Photo','',filename,content_type='image/jpeg')
70 elif extension=='.png':
71 print 'Uploading %s' % filename
72 photo = picasa.InsertPhotoSimple(album_url,'New Photo','',filename,content_type='image/png')
73 elif extension=='.bmp':
74 print 'Uploading %s' % filename
75 photo = picasa.InsertPhotoSimple(album_url,'New Photo','',filename,content_type='image/bmp')
76 elif extension=='.gif':
77 print 'Uploading %s' % filename
78 photo = picasa.InsertPhotoSimple(album_url,'New Photo','',filename,content_type='image/gif')
80 print 'Skipping %s' % filename
82 except gdata.photos.service.GooglePhotosException as gpe:
85 if __name__ == "__main__":