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