def fetch_photos(self,
                  user_id="",
                  album_id="",
                  photo_id="",
                  kind="",
                  access=""):
     # Picasa client
     client = PicasaClient()
     # starting item
     start_index = (self.args.page - 1) * self.settings["perpage"] + 1
     # set access
     if (access == ""):
         access = self.settings["access"]
     # fetch the items
     exec 'feed = client.%s( user_id=user_id, album_id=album_id, photo_id=photo_id, kind=kind, imgmax="d", thumbsize=self.settings[ "thumbsize" ], authkey=self.authkey, access=access, start__index=start_index, max__results=self.settings[ "perpage" ], q=self.args.pq )' % (
         self.args.category, )
     # if there were results
     if (feed):
         # set user icon for user query
         self.user_icon = feed["user_icon"]
         # calculate total pages
         pages = self._get_total_pages(feed["totalResults"])
         # fill media list
         return self._fill_media_list(feed["items"],
                                      self.args.page,
                                      pages,
                                      self.settings["perpage"],
                                      feed["totalResults"],
                                      kind=kind,
                                      access=access)
     #else return failed
     else:
         return False, 0
 def authenticate(self):
     # if this is first run open settings
     self.openSettings()
     # authentication is not permanent, so do this only when first launching plugin
     if (not sys.argv[2]):
         # get the users settings
         password = xbmcplugin.getSetting("user_password")
         # we can only authenticate if both email and password are entered
         if (self.email and password):
             # our client api
             from PicasaAPI.PicasaClient import PicasaClient
             client = PicasaClient()
             # make the authentication call
             authkey = client.authenticate(self.email, password)
             # if authentication succeeded, save it for later
             if (authkey):
                 xbmcplugin.setSetting("authkey", authkey)
 def get_users_contacts(self):
     # get client
     from PicasaAPI.PicasaClient import PicasaClient
     client = PicasaClient()
     # initialize our category tuple
     categories = ()
     # get settings
     user_id = xbmcplugin.getSetting("user_email")
     perpage = (
         10,
         15,
         20,
         25,
         30,
         40,
         50,
         75,
         100,
     )[int(xbmcplugin.getSetting("perpage"))]
     thumbsize = (
         72,
         144,
         160,
         200,
         288,
         320,
         400,
         512,
     )[int(xbmcplugin.getSetting("thumbsize"))]
     access = (
         "all",
         "private",
         "public",
     )[int(xbmcplugin.getSetting("access"))]
     # starting item
     start_index = (self.args.page - 1) * perpage + 1
     # fetch the items
     feed = client.users_contacts(user_id=user_id,
                                  album_id="",
                                  photo_id="",
                                  pq="",
                                  kind="user",
                                  imgmax="d",
                                  thumbsize=thumbsize,
                                  authkey=xbmcplugin.getSetting("authkey"),
                                  access=access,
                                  start__index=start_index,
                                  max__results=perpage,
                                  q="")
     # if there were results
     if (feed):
         #{'items': [{'thumb_url': u'http://lh3.ggpht.com/_NMYCpWBWM8Y/AAAAW8QQU-U/AAAAAAAAAAA/BPOH5yeOD1M/s64-c/gotoidan.jpg', 'nickname': u'Idan', 'user': u'gotoidan'}], 'totalResults': 1}
         # enumerate thru and add user
         for user in feed["items"]:
             # add user to our dictionary
             categories += ((
                 user["nickname"].encode("utf-8"),
                 "users_contacts_photos",
                 "",
                 user["user"].encode("utf-8"),
                 True,
                 0,
                 "photo",
                 access,
                 user["thumb_url"],
                 False,
             ), )
     # return results
     return categories