forked from starryalley/public-misc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpicasa_downloader.py
executable file
·76 lines (63 loc) · 2.13 KB
/
picasa_downloader.py
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
#!/usr/bin/python
#
# This interactive script prompts the user for an album to download.
# modified from http://psung.blogspot.tw/2009/12/manipulating-picasa-web-albums.html
#
# NOTE: do not use directly... it downloads everything...
#
# Author: Mark Kuo
# Date: 2012/8/3
#
import gdata.photos.service
import urllib
import getpass
import os, sys
def main():
# authenticating
email = raw_input("Username (e-mail): ")
password = getpass.getpass("Password (optional):")
client = login(email, password)
# get album list for the user
albums = client.GetUserFeed(user = email).entry
album_ids = []
# print and get interested albums
for album in sorted(albums, key=lambda a: a.title.text):
#if not album.title.text.startswith('Day'): continue
album_ids.append((album.title.text, album.gphoto_id.text))
print '%s (%3d photos) id = %s' % \
(album.title.text, int(album.numphotos.text), album.gphoto_id.text)
# download them
download_albums(client, email, album_ids)
def login(email, password):
gd_client = gdata.photos.service.PhotosService()
if password.rstrip() == '':
print "Log in as anonymous"
return gd_client
gd_client.email = email
gd_client.password = password
gd_client.source = 'MyPicasaDownloader'
try:
gd_client.ProgrammaticLogin()
except:
print "Login error.. aborted."
sys.exit(1)
return gd_client
def download_albums(client, email, albums):
prefix="photo"
for name, album_id in albums:
print "Downloading album: %s" % name
photos = client.GetFeed('/data/feed/api/user/%s/albumid/%s?kind=photo&imgmax=d'
% (email, album_id))
path = os.path.join(prefix, name)
try:
os.makedirs(path)
except OSError:
pass
for photo in photos.entry:
download_file(photo.content.src, path)
def download_file(url, path):
basename = url[url.rindex('/') + 1:]
print " Downloading photo:%s" % (basename,)
urllib.urlretrieve(url, os.path.join(path, basename))
if __name__ == '__main__':
main()