def create_session(self, info): if not info.get('ratingKey'): log.warn('Invalid ratingKey provided from activity info') return None # Metadata metadata = Metadata.get(info['ratingKey']) # Guid guid = Guid.parse(metadata.guid) if metadata else None ws = WatchSession.from_info(info, metadata, guid, info['ratingKey']) ws.skip = not metadata # Fetch client by `machineIdentifier` ws.client = Plex.clients().get(info['machineIdentifier']) if not ws.client: # Create dummy client from `info` ws.client = Client(Plex.client, 'clients') ws.client.name = info.get('client', None) ws.client.machine_identifier = info.get('machineIdentifier', None) ws.client.address = info.get('address', None) ws.client.port = info.get('port', None) # Create dummy user from `info` ws.user = User(Plex.client, 'accounts') ws.user.id = info['user_id'] ws.user.title = info['user_name'] ws.save() log.debug('created session: %s', ws) return ws
def fetch(result, player): # Fetch client details client = Plex.clients().get(player['key']) if not client: log.info('Unable to find client with key %r', player['key']) return result, None # Merge client details from plex API result = merge(result, dict([ (key, getattr(client, key)) for key in [ 'device_class', 'product', 'version', 'host', 'address', 'port', 'protocol', 'protocol_capabilities', 'protocol_version' ] if getattr(client, key) ])) return result, client
def create_session(self, session_key, state): """ :type session_key: str :type state: str :rtype: WatchSession or None """ log.debug('Creating a WatchSession for the current media') item = Plex['status'].sessions().get(session_key) if not item: log.warn('Unable to find session with key "%s"', session_key) return None # Metadata metadata = Metadata.get(item.rating_key) # Guid guid = Guid.parse(metadata.guid) if metadata else None # Create WatchSession ws = WatchSession.from_session(item.session, metadata, guid, item.rating_key, state) ws.skip = not metadata # Fetch client by `machineIdentifier` ws.client = Plex.clients().get(item.session.player.machine_identifier) ws.save() log.debug('created session: %s', ws) return ws
def test_clients_filter(): responses.add( responses.GET, 'http://mock:32400/clients', body=read('fixtures/clients.xml'), status=200, content_type='application/xml' ) container = Plex.clients() assert container is not None items = list(container.filter(["a7d1b50a-42d1-40b5-9db6-6b0afd013438"])) assert len(items) == 1 assert items[0].machine_identifier == "a7d1b50a-42d1-40b5-9db6-6b0afd013438"
def test_clients_filter(): responses.add(responses.GET, 'http://mock:32400/clients', body=read('fixtures/clients.xml'), status=200, content_type='application/xml') container = Plex.clients() assert container is not None items = list(container.filter(["a7d1b50a-42d1-40b5-9db6-6b0afd013438"])) assert len(items) == 1 assert items[ 0].machine_identifier == "a7d1b50a-42d1-40b5-9db6-6b0afd013438"
def test_clients(): responses.add( responses.GET, 'http://mock:32400/clients', body=read('fixtures/clients.xml'), status=200, content_type='application/xml' ) container = Plex.clients() assert container is not None items = list(container) assert len(items) == 1 assert items[0].name == "One" assert items[0].address == "192.168.1.100" assert items[0].version == "1.2.2.331-2d6426d7" assert items[0].protocol_capabilities == "navigation,playback,timeline,mirror,playqueues"
def test_clients_get(): responses.add(responses.GET, 'http://mock:32400/clients', body=read('fixtures/clients.xml'), status=200, content_type='application/xml') container = Plex.clients() assert container is not None # Try retrieve item that exists item = container.get("a7d1b50a-42d1-40b5-9db6-6b0afd013438") assert item is not None assert item.machine_identifier == "a7d1b50a-42d1-40b5-9db6-6b0afd013438" # Try retrieve item that doesn't exist item = container.get("invalid-identifier") assert item is None
def test_clients(): responses.add(responses.GET, 'http://mock:32400/clients', body=read('fixtures/clients.xml'), status=200, content_type='application/xml') container = Plex.clients() assert container is not None items = list(container) assert len(items) == 1 assert items[0].name == "One" assert items[0].address == "192.168.1.100" assert items[0].version == "1.2.2.331-2d6426d7" assert items[ 0].protocol_capabilities == "navigation,playback,timeline,mirror,playqueues"
def test_clients_get(): responses.add( responses.GET, 'http://mock:32400/clients', body=read('fixtures/clients.xml'), status=200, content_type='application/xml' ) container = Plex.clients() assert container is not None # Try retrieve item that exists item = container.get("a7d1b50a-42d1-40b5-9db6-6b0afd013438") assert item is not None assert item.machine_identifier == "a7d1b50a-42d1-40b5-9db6-6b0afd013438" # Try retrieve item that doesn't exist item = container.get("invalid-identifier") assert item is None