import os,os.path,sys, urllib, urlparse from kodiswift import Plugin, ListItem, storage from kodiswift import xbmc, xbmcgui, xbmcplugin, xbmcvfs, xbmcaddon, CLI_MODE, SortMethod from resources.lib import photostation_api try: import wingdbstub except: pass plugin = Plugin() view_mode = plugin.get_setting("view_mode",str) server = plugin.get_setting("server", str) user = plugin.get_setting("user", str) password = plugin.get_setting("password", str) page_size = plugin.get_setting("page_size", str) page_size = -1 if page_size == "All" else int(page_size) sorting = plugin.get_setting("sorting", str) order = plugin.get_setting("order", str) video_quality = plugin.get_setting("video_quality", str) picture_quality = plugin.get_setting("picture_quality", str) ps = photostation_api.PhotoStationAPI("http://home.blue.lv/photo") try: ps.login(user, password) except Exception as e: print "Error while logging %s/%s"%(user,password) plugin.notify(str(e),"",10000) prefix = "" @plugin.route(".+" ) def main(): # plugin://xxx/ global prefix prefix = "%s://%s/"%(plugin.request.scheme,plugin.request.netloc) data = plugin.request.url.replace(prefix,"") data = urllib.unquote(data) #default_oid = "album_323031372f323031372d30312d313320536c69646f73616e61" default_oid = "" if not data: data = default_oid oid = plugin.request.path[1:] if not oid: oid = default_oid qs = dict(urlparse.parse_qsl(plugin.request.query_string)) if not "page" in qs: page = 1 else: page = int(qs["page"]) if not oid or oid.startswith("album"): plugin.set_content("images") offset = 0 if page_size == -1 else (page - 1) * page_size limit = -1 if page_size == -1 else page_size content = ps.get_album_list(oid, offset=offset, limit=limit, sort_by=sorting, sort_direction=order ) items = [] for f in content["items"]: title = f["info"]["name"] type = f["type"] oid2 = f["id"] #is_playable = True if type in ("video","photo") else False is_folder = False if type in ("video","photo") else True thumb_url = ps.get_thumb_url(f["id"],"small") data2 = prefix+f["id"] #item = ListItem(title, icon=thumb_url, thumbnail=thumb_url, path=data2) #item.is_folder = False if type in ("video","photo") else True if type=="album": label2 = "%s photos, %s videos"%(f["additional"]["item_count"]["photo"],f["additional"]["item_count"]["video"]) item = xbmcgui.ListItem(title, label2, thumb_url, thumb_url, path=data2) item.setInfo( "Image", {"title":f["info"]["title"],"picturepath":f["additional"]["file_location"]} ) elif type == "photo": label2 = f["info"]["takendate"] image_url = ps.get_thumb_url(oid2,"large") data2 = image_url item = xbmcgui.ListItem(title, label2, thumb_url, thumb_url, path=data2) item.setInfo( "pictures", {"title":f["info"]["title"], "picturepath":f["additional"]["file_location"], "exif:resolution": "720,480" ,} ) elif type=="video": label2 = f["info"]["takendate"] item = xbmcgui.ListItem(title, label2, thumb_url, thumb_url, path=data2) item.setInfo( 'video', { "title": title, "plot": f["additional"]["file_location"], } ) item.setProperty("is_folder", "true" if is_folder else "") item.setProperty("url", data2) items.append(item) #xbmcplugin.addDirectoryItem(handle=plugin.handle, url=data2, listitem=item, isFolder=is_folder, #totalItems=len(content["items"])) if page_size <> -1 and len(content["items"]) == page_size: data2 = prefix+oid+"?page=%s" % (page+1) item = xbmcgui.ListItem("Next", "", "", "", data2) item.setInfo("Image", {"title":"Next"}) item.setProperty("is_folder", "false") item.setProperty("url", data2) items.append(item) sort_methods = [SortMethod.FILE, SortMethod.DATE, SortMethod.DATE_TAKEN] view_mode_id = get_view_mode(view_mode) return plugin.finish(items, sort_methods=None, view_mode=view_mode_id, cache_to_disc=True, update_listing=False) #xbmcplugin.endOfDirectory(plugin.handle, succeeded=True, updateListing=False, cacheToDisc=True) elif oid.startswith("photo"): print "play_photo ", oid try: url = ps.get_thumb_url(oid,"large") #thumb_url = ps.get_thumb_url(oid,"smalll") #js = ps.get_photo_info(oid) #title = js["info"]["name"] except Exception,e: plugin.notify(str(e),"",10000) return None print "set_resolved_url", url plugin.set_resolved_url(url) elif oid.startswith("video"): try: streams = ps.get_video_streams(oid) js = ps.get_photo_info(oid) except Exception,e: plugin.notify(str(e),"",10000) return None if streams: return play_video(streams) else: plugin.notify("No streams found!",10000) return None def get_view_mode(vm): modes = { "skin.estuary": { "None": None, "List": 50, "Poster": 51, "IconWall":52 , "Shift": 53, "InfoWall": 54, "WideList": 55, "Wall": 500, "Banner": 501, "FanArt": 502 } } skin = xbmc.getSkinDir() if skin in modes and vm in modes[skin]: view_mode = modes[skin][vm] else: view_mode = 50 return view_mode def play_video(streams): stream = streams[0] subfiles = [] print "play_video ",stream["url"] item = ListItem(label=stream["name"], thumbnail=stream["img"], path=stream["url"]) item.set_info("video",{"plot":stream["desc"]}) item.is_folder = False item.set_is_playable(True) plugin.play_video(item) if __name__ == '__main__': if CLI_MODE: from kodiswift.cli.cli import main as start start() else: plugin.run()