ecasa: initial checkin of prototype
[enigma2-plugins.git] / ecasa / src / plugin.py
1 from __future__ import print_function
2
3 #from Plugins.Plugin import PluginDescriptor
4
5 #pragma mark - Picasa API
6
7 import gdata.photos.service
8 import gdata.media
9 import gdata.geo
10
11 class PicasaApi:
12         """Wrapper around gdata/picasa API to make our life a little easier."""
13         def __init__(self, email, password):
14                 """Initialize API, login to google servers"""
15                 gd_client = gdata.photos.service.PhotosService()
16                 gd_client.email = email
17                 gd_client.password = password
18                 gd_client.source = 'enigma2-plugin-extensions-ecasa'
19                 gd_client.ProgrammaticLogin()
20
21                 self.gd_client = gd_client
22
23         def getAlbums(self, user='default'):
24                 albums = self.gd_client.GetUserFeed(user=user)
25                 # flatten list to something our gui renderers can handle more easily
26                 return [(album.title.text, album.numphotos.text, user, album.gphoto_id.text, album) for album in albums.entry]
27
28         def getAlbum(self, gphoto_id, user='default'):
29                 photos = self.gd_client.GetFeed('/data/feed/api/user/%s/albumid/%s?kind=photo' % (user, gphoto_id))
30                 return [(photo.title.text, user, photo.gphoto_id.text, photo) for photo in photos.entry]
31
32 #pragma mark - GUI
33
34 #pragma mark - Plugin
35
36 def Plugins(**kwargs):
37         return [
38         ]
39
40 if __name__ == '__main__':
41         import sys
42         if not len(sys.argv) > 2:
43                 print("Not enough parameters, aborting...")
44         else:
45                 api = PicasaApi(sys.argv[1], sys.argv[2])
46                 l = api.getAlbums()
47                 print("List of Albums:", l)
48                 if l:
49                         l = api.getAlbum(l[0][3])
50                         print("Pictures in first album:", l)
51                         print("Thumbnail of first picture could be found under:", l[0][3].media.thumbnail[0].url)
52                         print("Picture should be:", l[0][3].media.content[0].url)