def construct_url(self): """Construct a full plex request URI, with `params`.""" path = [self.path] path.extend([str(x) for x in self.params]) url = self.client.base_url + '/'.join(x for x in path if x) query = self.kwargs.get('query') if query: url += '?' + urlencode(query) return url
def connect(self): uri = 'ws://%s:%s/:/websockets/notifications' % ( Plex.configuration.get('server.host', '127.0.0.1'), Plex.configuration.get('server.port', 32400)) params = {} # Set authentication token (if one is available) if Plex.configuration['authentication.token']: params['X-Plex-Token'] = Plex.configuration['authentication.token'] # Append parameters to uri if params: uri += '?' + urlencode(params) # Create websocket connection self.ws = websocket.create_connection(uri)
def connect(self): uri = 'ws://%s:%s/:/websockets/notifications' % ( Plex.configuration.get('server.host', '127.0.0.1'), Plex.configuration.get('server.port', 32400) ) params = {} # Set authentication token (if one is available) if Plex.configuration['authentication.token']: params['X-Plex-Token'] = Plex.configuration['authentication.token'] # Append parameters to uri if params: uri += '?' + urlencode(params) # Create websocket connection self.ws = websocket.create_connection(uri)
def construct_url(self): """Construct a full plex request URI, with `params`.""" path = [self.path] path.extend([str(x) for x in self.params]) url = self.client.base_url + '/'.join(x for x in path if x) query = self.kwargs.get('query') if query: # Dict -> List if type(query) is dict: query = query.items() # Remove items with `None` value query = [(k, v) for (k, v) in query if v is not None] # Encode query, append to URL url += '?' + urlencode(query) return url
def connect(self): uri = 'ws://%s:%s/:/websockets/notifications' % ( Plex.configuration.get('server.host', '127.0.0.1'), Plex.configuration.get('server.port', 32400) ) params = {} # Set authentication token (if one is available) if Plex.configuration['authentication.token']: params['X-Plex-Token'] = Plex.configuration['authentication.token'] # Append parameters to uri if params: uri += '?' + urlencode(params) # Ensure existing websocket has been closed if self.ws: try: self.ws.close() except Exception as ex: log.info('Unable to close existing websocket: %s', ex) # Update state self.state = ConnectionState.connecting # Try connect to notifications websocket try: self.ws = websocket.create_connection(uri) # Update state self.state = ConnectionState.connected except Exception as ex: # Reset state self.ws = None self.state = ConnectionState.disconnected raise ex
def construct_url(self): """Construct a full plex request URI, with `params`.""" path = [self.path] path.extend([str(x) for x in self.params]) url = self.client.base_url + '/'.join(x for x in path if x) query = self.kwargs.get('query') if query: # Dict -> List if type(query) is dict: query = query.items() # Remove items with `None` value query = [ (k, v) for (k, v) in query if v is not None ] # Encode query, append to URL url += '?' + urlencode(query) return url
def connect(self): uri = 'ws://%s:%s/:/websockets/notifications' % ( Plex.configuration.get('server.host', '127.0.0.1'), Plex.configuration.get('server.port', 32400)) params = {} # Set authentication token (if one is available) if Plex.configuration['authentication.token']: params['X-Plex-Token'] = Plex.configuration['authentication.token'] # Append parameters to uri if params: uri += '?' + urlencode(params) # Ensure existing websocket has been closed if self.ws: try: self.ws.close() except Exception as ex: log.info('Unable to close existing websocket: %s', ex) # Update state self.state = ConnectionState.connecting # Try connect to notifications websocket try: self.ws = websocket.create_connection(uri) # Update state self.state = ConnectionState.connected except Exception as ex: # Reset state self.ws = None self.state = ConnectionState.disconnected raise ex