Пример #1
0
    def _update_properties(self):
        for property in _properties:
            setting = settings.get_setting(property)
            utils.log("{}: {}".format(property, setting))
            if setting is not None:
                utils.set_property(property, setting)
                utils.log("Property {0} set".format(property))
            else:
                utils.clear_property(property)
                utils.log("Property {0} cleared".format(property))

        self._reload_settings()
Пример #2
0
 def do_OPTIONS(s):
     s.send_response(200)
     s.send_header('Content-Length', '0')
     s.send_header('X-Plex-Client-Identifier', settings.get_setting('client_id'))
     s.send_header('Content-Type', 'text/plain')
     s.send_header('Connection', 'close')
     s.send_header('Access-Control-Max-Age', '1209600')
     s.send_header('Access-Control-Allow-Origin', '*')
     s.send_header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, DELETE, PUT, HEAD')
     s.send_header('Access-Control-Allow-Headers', 'x-plex-version, x-plex-platform-version, x-plex-username, x-plex-client-identifier, x-plex-target-client-identifier, x-plex-device-name, x-plex-platform, x-plex-product, accept, x-plex-device')
     s.end_headers()
     s.wfile.close()
Пример #3
0
 def do_OPTIONS(s):
     s.send_response(200)
     s.send_header('Content-Length', '0')
     s.send_header('X-Plex-Client-Identifier',
                   settings.get_setting('client_id'))
     s.send_header('Content-Type', 'text/plain')
     s.send_header('Connection', 'close')
     s.send_header('Access-Control-Max-Age', '1209600')
     s.send_header('Access-Control-Allow-Origin', '*')
     s.send_header('Access-Control-Allow-Methods',
                   'POST, GET, OPTIONS, DELETE, PUT, HEAD')
     s.send_header(
         'Access-Control-Allow-Headers',
         'x-plex-version, x-plex-platform-version, x-plex-username, x-plex-client-identifier, x-plex-target-client-identifier, x-plex-device-name, x-plex-platform, x-plex-product, accept, x-plex-device'
     )
     s.end_headers()
     s.wfile.close()
Пример #4
0
 def answer_request(s, sendData):
     try:
         request_path = s.path[1:]
         request_path = re.sub(r"\?.*", "", request_path)
         url = urlparse(s.path)
         paramarrays = parse_qs(url.query)
         params = {}
         for key in paramarrays:
             params[key] = paramarrays[key][0]
         log_print("request path is: [%s]" % (request_path, ))
         log_print("params are: %s" % params)
         subMgr.updateCommandID(
             s.headers.get('X-Plex-Client-Identifier', s.client_address[0]),
             params.get('commandID', False))
         if request_path == "version":
             s.response(
                 "PleXBMC Helper Remote Redirector: Running\r\nVersion: %s"
                 % GLOBAL_SETUP['__version__'])
         elif request_path == "verify":
             result = jsonrpc("ping")
             s.response("XBMC JSON connection test:\r\n" + result)
         elif "resources" == request_path:
             resp = getXMLHeader()
             resp += "<MediaContainer>"
             resp += "<Player"
             resp += ' title="%s"' % settings.get_setting('devicename')
             resp += ' protocol="plex"'
             resp += ' protocolVersion="1"'
             resp += ' protocolCapabilities="navigation,playback,timeline"'
             resp += ' machineIdentifier="%s"' % settings.get_setting(
                 'client_id')
             resp += ' product="PleXBMC"'
             resp += ' platform="%s"' % get_platform()
             resp += ' platformVersion="%s"' % GLOBAL_SETUP['__version__']
             resp += ' deviceClass="pc"'
             resp += "/>"
             resp += "</MediaContainer>"
             log_print("crafted resources response: %s" % resp)
             s.response(resp, getPlexHeaders())
         elif "/subscribe" in request_path:
             s.response(getOKMsg(), getPlexHeaders())
             protocol = params.get('protocol', False)
             host = s.client_address[0]
             port = params.get('port', False)
             uuid = s.headers.get('X-Plex-Client-Identifier', "")
             commandID = params.get('commandID', 0)
             subMgr.addSubscriber(protocol, host, port, uuid, commandID)
         elif "/poll" in request_path:
             if params.get('wait', False) == '1':
                 xbmc.sleep(950)
             commandID = params.get('commandID', 0)
             s.response(
                 re.sub(r"INSERTCOMMANDID", str(commandID),
                        subMgr.msg(getPlayers())), {
                            'X-Plex-Client-Identifier':
                            settings.get_setting('client_id'),
                            'Access-Control-Expose-Headers':
                            'X-Plex-Client-Identifier',
                            'Access-Control-Allow-Origin':
                            '*',
                            'Content-Type':
                            'text/xml'
                        })
         elif "/unsubscribe" in request_path:
             s.response(getOKMsg(), getPlexHeaders())
             uuid = s.headers.get('X-Plex-Client-Identifier',
                                  False) or s.client_address[0]
             subMgr.removeSubscriber(uuid)
         elif request_path == "player/playback/setParameters":
             s.response(getOKMsg(), getPlexHeaders())
             if 'volume' in params:
                 volume = int(params['volume'])
                 log_print("adjusting the volume to %s%%" % volume)
                 jsonrpc("Application.SetVolume", {"volume": volume})
         elif "/playMedia" in request_path:
             s.response(getOKMsg(), getPlexHeaders())
             resume = params.get('viewOffset', params.get('offset', "0"))
             protocol = params.get('protocol', "http")
             address = params.get('address', s.client_address[0])
             server = getServerByHost(address)
             port = params.get('port', server.get('port', '32400'))
             fullurl = protocol + "://" + address + ":" + port + params[
                 'key']
             log_print("playMedia command -> fullurl: %s" % fullurl)
             jsonrpc("playmedia", [fullurl, resume])
             subMgr.lastkey = params['key']
             subMgr.server = server.get('server', 'localhost')
             subMgr.port = port
             subMgr.protocol = protocol
             subMgr.notify()
         elif request_path == "player/playback/play":
             s.response(getOKMsg(), getPlexHeaders())
             for playerid in getPlayerIds():
                 jsonrpc("Player.PlayPause", {
                     "playerid": playerid,
                     "play": True
                 })
         elif request_path == "player/playback/pause":
             s.response(getOKMsg(), getPlexHeaders())
             for playerid in getPlayerIds():
                 jsonrpc("Player.PlayPause", {
                     "playerid": playerid,
                     "play": False
                 })
         elif request_path == "player/playback/stop":
             s.response(getOKMsg(), getPlexHeaders())
             for playerid in getPlayerIds():
                 jsonrpc("Player.Stop", {"playerid": playerid})
         elif request_path == "player/playback/seekTo":
             s.response(getOKMsg(), getPlexHeaders())
             for playerid in getPlayerIds():
                 jsonrpc(
                     "Player.Seek", {
                         "playerid": playerid,
                         "value": millisToTime(params.get('offset', 0))
                     })
             subMgr.notify()
         elif request_path == "player/playback/stepForward":
             s.response(getOKMsg(), getPlexHeaders())
             for playerid in getPlayerIds():
                 jsonrpc("Player.Seek", {
                     "playerid": playerid,
                     "value": "smallforward"
                 })
             subMgr.notify()
         elif request_path == "player/playback/stepBack":
             s.response(getOKMsg(), getPlexHeaders())
             for playerid in getPlayerIds():
                 jsonrpc("Player.Seek", {
                     "playerid": playerid,
                     "value": "smallbackward"
                 })
             subMgr.notify()
         elif request_path == "player/playback/skipNext":
             s.response(getOKMsg(), getPlexHeaders())
             for playerid in getPlayerIds():
                 jsonrpc("Player.Seek", {
                     "playerid": playerid,
                     "value": "bigforward"
                 })
             subMgr.notify()
         elif request_path == "player/playback/skipPrevious":
             s.response(getOKMsg(), getPlexHeaders())
             for playerid in getPlayerIds():
                 jsonrpc("Player.Seek", {
                     "playerid": playerid,
                     "value": "bigbackward"
                 })
             subMgr.notify()
         elif request_path == "player/navigation/moveUp":
             s.response(getOKMsg(), getPlexHeaders())
             jsonrpc("Input.Up")
         elif request_path == "player/navigation/moveDown":
             s.response(getOKMsg(), getPlexHeaders())
             jsonrpc("Input.Down")
         elif request_path == "player/navigation/moveLeft":
             s.response(getOKMsg(), getPlexHeaders())
             jsonrpc("Input.Left")
         elif request_path == "player/navigation/moveRight":
             s.response(getOKMsg(), getPlexHeaders())
             jsonrpc("Input.Right")
         elif request_path == "player/navigation/select":
             s.response(getOKMsg(), getPlexHeaders())
             jsonrpc("Input.Select")
         elif request_path == "player/navigation/home":
             s.response(getOKMsg(), getPlexHeaders())
             jsonrpc("Input.Home")
         elif request_path == "player/navigation/back":
             s.response(getOKMsg(), getPlexHeaders())
             jsonrpc("Input.Back")
     except:
         traceback.print_exc()
def add_menu_item(
    title="",
    params=None,
    path=None,
    info=None,
    cm=None,
    art=None,
    isFolder=False,
    props=None,
):
    _plugin = sys.argv[0]
    _handle = int(sys.argv[1])

    if params is not None and isinstance(params, dict):
        encode = {k: v for k, v in params.items() if k not in _exclude_params}

        _plugin += "?{}".format(urlencode(encode))

        for param in _exclude_params:
            _plugin += "&{}={}".format(param, params.get(param, ""))
    elif path is not None and isinstance(path, six.text_type):
        _plugin = path

    if isinstance(title, int):
        title = utils.get_string(title)

    item = xbmcgui.ListItem(title)

    if info is not None and isinstance(info, dict):
        def_info = {}
        mediatype = info.get("type", "unknown")
        info_type = info_types.get(mediatype, "video")

        for key, value in info.items():
            new_value = None
            if isinstance(value, list):
                if key in ["cast", "castandrole"]:
                    item.setCast(value)
                else:
                    new_value = [six.text_type(i) for i in value]
            elif isinstance(value, dict):
                if key == "resume":
                    pos = value.get("position", 0)
                    total = value.get("total", 0)
                    if pos > 0 and pos < total:
                        if props is None:
                            props = {}
                        props["ResumeTime"] = six.text_type(pos)
                        props["TotalTime"] = six.text_type(total)
                elif key == "art":
                    if art is None:
                        art = value
                elif key == "customproperties":
                    # THIS BLOCK IS FOR ATTACHING CONTEXT MENU ITEMS TO WIDGET ITEMS
                    # BUT DOESN'T WORK, DUE TO KODI LIMITATIONS.
                    #
                    # context_items = {
                    #     k: v for k, v in value.items() if "contextmenu" in k
                    # }
                    # items = [
                    #     (
                    #         context_items.get("contextmenulabel({})".format(i)),
                    #         context_items.get("contextmenuaction({})".format(i)),
                    #     )
                    #     for i in range(0, len(context_items) // 2)
                    # ]
                    # if cm is None:
                    #     cm = []
                    # cm.extend(items)

                    if props is None:
                        props = {}
                    props.update(value)
                elif key == "uniqueid":
                    item.setUniqueIDs(value)
                elif key == "streamdetails":
                    for d in value:
                        if len(value[d]) > 0:
                            item.addStreamInfo(d, value[d][0])
                else:
                    utils.log("Unknown dict-typed info key encountered: {}".format(key))
            else:
                if key == "mimetype":
                    item.setMimeType(value)
                elif key == "artist":
                    new_value = [value]
                else:
                    new_value = (
                        value
                        if isinstance(value, (int, float))
                        else six.text_type(value)
                    )
            if new_value is not None:
                valid_keys = _translations.get(info_types.get(mediatype, ""), {})
                new_key = valid_keys.get(key, key)
                def_info[new_key] = new_value

        for key in _remove_keys:
            def_info.pop(key, None)

        item.setInfo(info_type, def_info)

    if props is not None and isinstance(props, dict):
        for prop in props:
            item.setProperty(prop, six.text_type(props[prop]))

    if art is not None and isinstance(art, dict):
        if info:
            path = info.get("file", "")
            if any(i in path for i in ["studios", "countries", "genres"]):
                if "studios" in path:
                    art["icon"] = "resource://{}/{}.png".format(
                        settings.get_setting("icons.studios"), info.get("label", "")
                    )
                elif "countries" in path:
                    art["icon"] = "resource://{}/{}.png".format(
                        settings.get_setting("icons.countries"), info.get("label", "")
                    )
                elif "genres" in path:
                    if "videodb" in path:
                        art["icon"] = "resource://{}/{}.png".format(
                            settings.get_setting("icons.video_genre_icons"),
                            info.get("label", ""),
                        )
                        art["fanart"] = "resource://{}/{}.jpg".format(
                            settings.get_setting("icons.video_genre_fanart"),
                            info.get("label", ""),
                        )
                    elif "musicdb" in path:
                        art["icon"] = "resource://{}/{}.jpg".format(
                            settings.get_setting("icons.music_genre_icons"),
                            info.get("label", ""),
                        )
                        art["fanart"] = "resource://{}/{}.jpg".format(
                            settings.get_setting("icons.music_genre_fanart"),
                            info.get("label", ""),
                        )

        if not any([art.get(i) for i in ["landscape", "poster"]]) and all(
            [art.get(i) for i in ["thumb", "fanart"]]
        ):
            art["landscape"] = art["thumb"]
        item.setArt(art)

    if cm is not None and isinstance(cm, list):
        item.addContextMenuItems(cm)

    xbmcplugin.addDirectoryItem(
        handle=_handle, url=_plugin, listitem=item, isFolder=isFolder
    )
Пример #6
0
 def answer_request(s, sendData):
     try:
         request_path=s.path[1:]
         request_path=re.sub(r"\?.*","",request_path)
         url = urlparse(s.path)
         paramarrays = parse_qs(url.query)
         params = {}
         for key in paramarrays:
             params[key] = paramarrays[key][0]
         log_print ( "request path is: [%s]" % ( request_path,) )
         log_print ( "params are: %s" % params )
         subMgr.updateCommandID(s.headers.get('X-Plex-Client-Identifier', s.client_address[0]), params.get('commandID', False))
         if request_path=="version":
             s.response("PleXBMC Helper Remote Redirector: Running\r\nVersion: %s" % GLOBAL_SETUP['__version__'])
         elif request_path=="verify":
             result=jsonrpc("ping")
             s.response("XBMC JSON connection test:\r\n"+result)
         elif "resources" == request_path:
             resp = getXMLHeader()
             resp += "<MediaContainer>"
             resp += "<Player"
             resp += ' title="%s"' % settings.get_setting('devicename')
             resp += ' protocol="plex"'
             resp += ' protocolVersion="1"'
             resp += ' protocolCapabilities="navigation,playback,timeline"'
             resp += ' machineIdentifier="%s"' % settings.get_setting('client_id')
             resp += ' product="PleXBMC"'
             resp += ' platform="%s"' % get_platform()
             resp += ' platformVersion="%s"' % GLOBAL_SETUP['__version__']
             resp += ' deviceClass="pc"'
             resp += "/>"
             resp += "</MediaContainer>"
             log_print("crafted resources response: %s" % resp)
             s.response(resp, getPlexHeaders())
         elif "/subscribe" in request_path:
             s.response(getOKMsg(), getPlexHeaders())
             protocol = params.get('protocol', False)
             host = s.client_address[0]
             port = params.get('port', False)
             uuid = s.headers.get('X-Plex-Client-Identifier', "")
             commandID = params.get('commandID', 0)
             subMgr.addSubscriber(protocol, host, port, uuid, commandID)
         elif "/poll" in request_path:
             if params.get('wait', False) == '1':
                 xbmc.sleep(950)
             commandID = params.get('commandID', 0)
             s.response(re.sub(r"INSERTCOMMANDID", str(commandID), subMgr.msg(getPlayers())), {
               'X-Plex-Client-Identifier': settings.get_setting('client_id'),
               'Access-Control-Expose-Headers': 'X-Plex-Client-Identifier',
               'Access-Control-Allow-Origin': '*',
               'Content-Type': 'text/xml'
             })
         elif "/unsubscribe" in request_path:
             s.response(getOKMsg(), getPlexHeaders())
             uuid = s.headers.get('X-Plex-Client-Identifier', False) or s.client_address[0]
             subMgr.removeSubscriber(uuid)
         elif request_path == "player/playback/setParameters":
             s.response(getOKMsg(), getPlexHeaders())
             if 'volume' in params:
                 volume = int(params['volume'])
                 log_print("adjusting the volume to %s%%" % volume)
                 jsonrpc("Application.SetVolume", {"volume": volume})
         elif "/playMedia" in request_path:
             s.response(getOKMsg(), getPlexHeaders())
             resume = params.get('viewOffset', params.get('offset', "0"))
             protocol = params.get('protocol', "http")
             address = params.get('address', s.client_address[0])
             server = getServerByHost(address)
             port = params.get('port', server.get('port', '32400'))
             fullurl = protocol+"://"+address+":"+port+params['key']
             log_print("playMedia command -> fullurl: %s" % fullurl)
             jsonrpc("playmedia", [fullurl, resume])
             subMgr.lastkey = params['key']
             subMgr.server = server.get('server', 'localhost')
             subMgr.port = port
             subMgr.protocol = protocol
             subMgr.notify()
         elif request_path == "player/playback/play":
             s.response(getOKMsg(), getPlexHeaders())
             for playerid in getPlayerIds():
                 jsonrpc("Player.PlayPause", {"playerid" : playerid, "play": True})
         elif request_path == "player/playback/pause":
             s.response(getOKMsg(), getPlexHeaders())
             for playerid in getPlayerIds():
                 jsonrpc("Player.PlayPause", {"playerid" : playerid, "play": False})
         elif request_path == "player/playback/stop":
             s.response(getOKMsg(), getPlexHeaders())
             for playerid in getPlayerIds():
                 jsonrpc("Player.Stop", {"playerid" : playerid})
         elif request_path == "player/playback/seekTo":
             s.response(getOKMsg(), getPlexHeaders())
             for playerid in getPlayerIds():
                 jsonrpc("Player.Seek", {"playerid":playerid, "value":millisToTime(params.get('offset', 0))})
             subMgr.notify()
         elif request_path == "player/playback/stepForward":
             s.response(getOKMsg(), getPlexHeaders())
             for playerid in getPlayerIds():
                 jsonrpc("Player.Seek", {"playerid":playerid, "value":"smallforward"})
             subMgr.notify()
         elif request_path == "player/playback/stepBack":
             s.response(getOKMsg(), getPlexHeaders())
             for playerid in getPlayerIds():
                 jsonrpc("Player.Seek", {"playerid":playerid, "value":"smallbackward"})
             subMgr.notify()
         elif request_path == "player/playback/skipNext":
             s.response(getOKMsg(), getPlexHeaders())
             for playerid in getPlayerIds():
                 jsonrpc("Player.Seek", {"playerid":playerid, "value":"bigforward"})
             subMgr.notify()
         elif request_path == "player/playback/skipPrevious":
             s.response(getOKMsg(), getPlexHeaders())
             for playerid in getPlayerIds():
                 jsonrpc("Player.Seek", {"playerid":playerid, "value":"bigbackward"})
             subMgr.notify()
         elif request_path == "player/navigation/moveUp":
             s.response(getOKMsg(), getPlexHeaders())
             jsonrpc("Input.Up")
         elif request_path == "player/navigation/moveDown":
             s.response(getOKMsg(), getPlexHeaders())
             jsonrpc("Input.Down")
         elif request_path == "player/navigation/moveLeft":
             s.response(getOKMsg(), getPlexHeaders())
             jsonrpc("Input.Left")
         elif request_path == "player/navigation/moveRight":
             s.response(getOKMsg(), getPlexHeaders())
             jsonrpc("Input.Right")
         elif request_path == "player/navigation/select":
             s.response(getOKMsg(), getPlexHeaders())
             jsonrpc("Input.Select")
         elif request_path == "player/navigation/home":
             s.response(getOKMsg(), getPlexHeaders())
             jsonrpc("Input.Home")
         elif request_path == "player/navigation/back":
             s.response(getOKMsg(), getPlexHeaders())
             jsonrpc("Input.Back")
     except:
         traceback.print_exc()