123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350 |
- # -*- coding: utf-8 -*-
- try:
- import wingdbstub
- except:
- pass
- import os,os.path,sys, urllib, urlparse
- #import xbmc, xbmcgui, xbmcplugin, xbmcvfs, xbmcaddon
- from kodiswift import Plugin, ListItem, storage
- from kodiswift import xbmc, xbmcgui, xbmcplugin, xbmcvfs, xbmcaddon, CLI_MODE, SortMethod
- from resources.lib import photostation_api
-
- plugin = Plugin()
- handle = sys.argv[1]
-
- 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)
- thumbnail_quality = plugin.get_setting("thumbnail_quality", str)
- play_next = plugin.get_setting("play_next", bool)
- start_page = plugin.get_setting("start_page", 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 = "" #start_page
- 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") or oid.startswith("category"):
- plugin.set_content("images")
-
- content = []
- if not oid:
- categories = ps.get_categories()["categories"]
- for cat in categories:
- if cat["hidden"]:
- continue
- data2 = prefix + cat["id"]
- label = cat["name"]
- item = xbmcgui.ListItem(label, "", "", "", data2)
- item.setInfo("Image", {"title":label})
- item.setProperty("is_folder", "true")
- item.setProperty("url", data2)
- #items.append(item)
- xbmcplugin.addDirectoryItem(handle=plugin.handle, url=data2, listitem=item, isFolder=True)
-
- offset = 0 if page_size == -1 else (page - 1) * page_size
- limit = -1 if page_size == -1 else page_size
- if "category" in oid:
- content = ps.get_category_list(oid)
- else:
- content = ps.get_album_list(oid, offset=offset, limit=limit, sort_by=sorting, sort_direction=order )
- items = []
- for f in content["items"]:
- label = f["info"]["title"]
- if not label:
- continue
- label2 = f["additional"]["file_location"] if "file_location" in f["additional"] else ""
- type = f["type"]
- oid2 = f["id"]
- is_playable = "true" if type in ("video","photo") else ""
- is_folder = "" if type in ("video","photo") else "true"
- thumb_quality = thumbnail_quality if thumbnail_quality in f["thumbnail_status"] else "small"
- thumb_url = ps.get_thumb_url(f["id"],thumb_quality)
- #thumb_url = urllib.quote(thumb_url, ":/")
- data2 = prefix+f["id"]
-
- if type=="album":
- nfiles = int(f["additional"]["item_count"]["photo"]) + int(f["additional"]["item_count"]["video"]) if "item_count" in f["additional"] else None
- suf = "\n(%s)" % nfiles if nfiles else ""
- label2 = "%s photos, %s videos"%(f["additional"]["item_count"]["photo"],f["additional"]["item_count"]["video"]) if "item_count" in f["additional"] else ""
- label = label + suf
- li_type = "video" # pictures
- tags = {
- #"title":f["info"]["title"],
- "title": label,
- #"picturepath":f["additional"]["file_location"]
- "label": label,
- "plotline":f["additional"]["file_location"] + "\n" + label2 if "file_location" in f["additional"] else "",
- "plot":f["additional"]["file_location"] + "\n" + label2 if "file_location" in f["additional"] else "",
- "path": f["info"]["sharepath"] if "sharepath" in f["additional"] else "",
- }
-
- elif type == "photo":
- label = label + "\n" + f["info"]["takendate"]
- label2 = f["info"]["takendate"]
- image_url = ps.get_photo_url(oid2) if picture_quality == "original" else ps.get_thumb_url(oid2, picture_quality)
- data2 = image_url
- #print "image_url=", data2
- #data2 = urllib.quote(data2, ":/")
- li_type = "pictures"
- tags = {
- "title": label2, #f["info"]["title"],
- "date": f["info"]["takendate"],
- "picturepath": f["additional"]["file_location"],
- "exif:resolution": "%s,%s" % (f["info"]["resolutionx"], f["info"]["resolutiony"]),
- #"exif:path": f["additional"]["file_location"],
- #"exif:name": f["info"]["name"],
- #"exif:filename": f["additional"]["file_location"],
- #"exif:"
- # TODO pārejie EXIF u.c. dati
- }
-
- elif type=="video":
- label = label + "\n" + f["info"]["takendate"]
- label2 = f["info"]["takendate"]
- li_type = 'video'
- tags = {
- "title": label ,
- "plot": f["additional"]["file_location"],
- #TODO
- }
- if play_next:
- data2 = data2 + "&album=" + oid if "?" in data2 else data2 + "?album=" + oid
- #data2 = urllib.quote(data2, ":/")
- is_playable = ""
- else:
- if video_quality == "original":
- quality_id = ""
- else:
- quality_id = f["additional"]["video_quality"][0]["id"]
- data2 = ps.get_video_url(oid2, quality_id)
- #data2 = urllib.quote(data2, ":/")
-
- item = xbmcgui.ListItem(label=label, label2=label2, path=data2)
- item.setArt({
- "thumb": thumb_url,
- "icon": thumb_url,
- "fanart": thumb_url,
- })
- item.setInfo(li_type, tags)
- item.setProperty("is_folder", is_folder)
- item.setProperty('IsPlayable', is_playable)
- item.setProperty("url", data2)
- #items.append(item)
- xbmcplugin.addDirectoryItem(handle=plugin.handle, url=data2, listitem=item, isFolder=True if is_folder=="true" else False,
- totalItems=len(content["items"]))
-
- if page_size <> -1 and len(content["items"]) == page_size:
- data2 = prefix+oid+"?page=%s" % (page+1)
- #data2 = urllib.quote(data2, ":/")
- item = xbmcgui.ListItem("Next", "", "", "", data2)
- item.setInfo("Image", {"title":"Next"})
- item.setProperty("is_folder", "false")
- item.setProperty("url", data2)
- #items.append(item)
- xbmcplugin.addDirectoryItem(handle=plugin.handle, url=data2, listitem=item, isFolder=True,
- totalItems=len(content["items"]))
-
- view_mode_id = get_view_mode(view_mode)
- xbmc.executebuiltin('Container.SetViewMode(%s)' % view_mode_id)
- #sort_methods = [SortMethod.FILE, SortMethod.DATE, SortMethod.DATE_TAKEN]
- #xbmcplugin.addSortMethod( plugin.handle, sortMethod=xbmcplugin.SORT_METHOD_GENRE )
- xbmcplugin.endOfDirectory(plugin.handle, succeeded=True, updateListing=False, cacheToDisc=True)
- #return plugin.finish(items, sort_methods=None, view_mode=view_mode_id, cache_to_disc=True, update_listing=False)
-
- 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"):
- if play_next and "album" in qs: # play playlist
- print "play_playlist", data, qs
- album_id = qs["album"]
- try:
- items = ps.get_album_list(album_id)
- except Exception,e:
- plugin.notify(str(e),"",10000)
- return None
- if items:
- play_playlist(items["items"], oid)
- return None
- else:
- plugin.notify("No items found!",10000)
- return None
- else: # play one video
- print "play_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:
- play_video(streams)
- return None
- else:
- plugin.notify("No streams found!",10000)
- return None
-
- def get_view_mode(vm):
- modes = {
- #"skin.estuary.isl"
- "skin.estuary": {
- "None": None,
- "List": 50,
- "Poster": 51,
- "IconWall":52 ,
- "Shift": 53,
- "InfoWall": 54,
- "WideList": 55,
- "Wall": 500,
- "Banner": 501,
- "FanArt": 502
- },
- "skin.estuary.isl": {
- "None": None,
- "List": 50,
- "Poster": 51,
- "IconWall":52 ,
- "Shift": 53,
- "InfoWall": 54,
- "WideList": 55,
- "Wall": 500,
- "Banner": 501,
- "FanArt": 502
- },
- "skin.estuary.is": {
- "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 = 500
- return view_mode
-
-
- def play_playlist(items, oid):
- playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
- playlist.clear()
- pos = -1
- i = 0
- for f in items:
- if f["type"] in ("album","photo"):
- continue
-
- label = f["info"]["name"] + "\n" + f["info"]["takendate"]
- label2 = f["additional"]["file_location"]
- type = f["type"]
- oid2 = f["id"]
- if oid == oid2:
- pos = i
- #is_playable = True if type in ("video","photo") else False
- is_folder = False if type in ("video","photo") else True
- thumb_quality = thumbnail_quality if thumbnail_quality in f["thumbnail_status"] else "small"
- thumb_url = ps.get_thumb_url(f["id"],thumb_quality)
- data2 = prefix+f["id"]
- item = xbmcgui.ListItem(label, label2, path=data2)
- item.setArt({
- "thumb": thumb_url,
- "icon": thumb_url,
- "fanart": thumb_url,
- })
- item.setLabel2(label2)
- item.setInfo(
- 'video', {
- "title": label,
- "plot": f["additional"]["file_location"],
- #TODO
- }
- )
- if video_quality == "original":
- quality_id = ""
- else:
- quality_id = f["additional"]["video_quality"][0]["id"]
- data2 = ps.get_video_url(oid2, quality_id)
- #data2 = urllib.quote(data2, ":/")
- item.setProperty("is_folder", "")
- item.setProperty('IsPlayable', 'true')
-
- #item.setPath(data2)
- item.setProperty("url", data2)
- playlist.add(data2, item)
- i += 1
-
- xbmc.Player().play(playlist, startpos=pos)
-
-
- 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)
- item2 = xbmcgui.ListItem("label", "label2", path=stream["url"])
- item2.setProperty('IsPlayable', 'true')
- xbmc.Player().play(item=stream["url"], listitem=item2)
- #xbmcplugin.setResolvedUrl(plugin.handle, True, listitem=item2)
-
-
-
- if __name__ == '__main__':
- if CLI_MODE:
- from kodiswift.cli.cli import main as start
- start()
- else:
- plugin.run()
|