Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Controller to interface with the Plex-app.
- """
- from . import BaseController
- MESSAGE_TYPE = 'type'
- TYPE_PLAY = "PLAY"
- TYPE_PAUSE = "PAUSE"
- TYPE_STOP = "STOP"
- class PlexController(BaseController):
- """ Controller to interact with Plex namespace. """
- def __init__(self):
- super(PlexController, self).__init__(
- "urn:x-cast:plex", "9AC194DC")
- self.app_id="9AC194DC"
- self.namespace="urn:x-cast:plex"
- self.request_id = 0
- def stop(self):
- """ Send stop command. """
- self.namespace = "urn:x-cast:plex"
- self.request_id += 1
- self.send_message({MESSAGE_TYPE: TYPE_STOP})
- def pause(self):
- """ Send pause command. """
- self.namespace = "urn:x-cast:plex"
- self.request_id += 1
- self.send_message({MESSAGE_TYPE: TYPE_PAUSE})
- def play(self):
- """ Send play command. """
- self.namespace = "urn:x-cast:plex"
- self.request_id += 1
- self.send_message({MESSAGE_TYPE: TYPE_PLAY})
- def play_media(self,item,server,medtype="LOAD"):
- def app_launched_callback():
- self.set_load(item,server,medtype)
- receiver_ctrl = self._socket_client.receiver_controller
- receiver_ctrl.launch_app(self.app_id,
- callback_function=app_launched_callback)
- def set_load(self,item,server,medtype="LOAD"):
- transient_token = server.query("/security/token?type=delegation&scope=all").attrib.get('token')
- playqueue = server.createPlayQueue(item).playQueueID
- self.request_id += 1
- address = server.baseurl.split(":")[1][2:]
- self.namespace="urn:x-cast:com.google.cast.media"
- msg = {
- "type": medtype,
- "requestId": self.request_id,
- "sessionId": "python_player",
- "autoplay": True,
- "currentTime": 0,
- "media":{
- "contentId": item.key,
- "streamType": "BUFFERED",
- "contentType": "video",
- "customData": {
- "offset": 0,
- "server": {
- "machineIdentifier": server.machineIdentifier,
- "transcoderVideo": True,
- "transcoderVideoRemuxOnly": False,
- "transcoderAudio": True,
- "version": "1.3.3.3148",
- "myPlexSubscription": False,
- "isVerifiedHostname": True,
- "protocol": "https",
- "address": address,
- "port": "32400",
- "accessToken": transient_token,
- },
- "user": {"username": server.myPlexUsername},
- "containerKey": "/playQueues/{}?own=1&window=200".format(playqueue),
- },
- }
- }
- self.send_message(msg, inc_session_id=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement