Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion etc/pyca.conf
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
# Default: sqlite:///pyca.db
#database = sqlite:///pyca.db

# Selectable inputs
# A track will only be ingested if the flavor of the track matches one of the
# selected inputs.
# If not specified, all inputs are always selected.
# Default: inputs = ''
#inputs = 'presenter/source, presentation/source'


[capture]

Expand Down Expand Up @@ -170,7 +177,7 @@ command = 'ffmpeg -nostats -re -f lavfi -r 25 -i testsrc -f lavfi -i si
# org.opencastproject.server.url setting of Opencast.
# Type: string
# Default: https://develop.opencast.org
url = 'https://develop.opencast.org'
url = 'http://localhost:8080'

# Analogue of -k, --insecure option in curl. Allows insercure SSL connections
# while using HTTPS on the server.
Expand Down
4 changes: 3 additions & 1 deletion pyca/agentstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
:license: LGPL – see license.lgpl for more details.
'''

from pyca.utils import set_service_status, update_agent_state, timestamp
from pyca.utils import set_service_status, update_agent_state, timestamp, \
update_agent_config
from pyca.utils import terminate
from pyca.config import config
from pyca.db import Service, ServiceStatus
Expand All @@ -34,6 +35,7 @@ def control_loop():

if not terminate():
update_agent_state()
update_agent_config()

logger.info('Shutting down agentstate service')
set_service_status(Service.AGENTSTATE, ServiceStatus.STOPPED)
Expand Down
1 change: 1 addition & 0 deletions pyca/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
cal_lookahead = integer(min=0, default=14)
backup_mode = boolean(default=false)
database = string(default='sqlite:///pyca.db')
inputs = force_list(default=list())

[capture]
directory = string(default='./recordings')
Expand Down
58 changes: 52 additions & 6 deletions pyca/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,49 @@
notify = sdnotify.SystemdNotifier()


def inputs_from_event(event):
''' Parse inputs from event attachment
'''

inputs = []
for attachment in event.get_data().get('attach'):
data = attachment.get('data')
if (attachment.get('x-apple-filename') ==
'org.opencastproject.capture.agent.properties'):
for prop in data.split('\n'):
if prop.startswith('capture.device.names'):
param = prop.split('=', 1)
inputs = param[1].split(',')
break
return inputs


def is_track_selected(event, flavor):
''' If inputs are configured, check if track was selected
'''

# inputs not configured -> add all
inputs_conf = config('agent', 'inputs')
if not inputs_conf:
logger.info('No inputs in config')
return True

# Get inputs from event attachment
inputs_event = inputs_from_event(event)

# inputs not in attachment -> add all
if not inputs_event:
logger.info('No inputs in schedule')
return True

# input is selected
if flavor in inputs_event:
return True

# input is not selected
return False


def get_config_params(properties):
'''Extract the set of configuration parameters from the properties attached
to the schedule
Expand Down Expand Up @@ -87,12 +130,15 @@ def ingest(event):

# add track
for (flavor, track) in event.get_tracks():
logger.info('Adding track (%s -> %s)', flavor, track)
track = track.encode('ascii', 'ignore')
fields = [('mediaPackage', mediapackage), ('flavor', flavor),
('BODY1', (pycurl.FORM_FILE, track))]
mediapackage = http_request(service_url + '/addTrack', fields,
timeout=0)
if is_track_selected(event, flavor):
logger.info('Adding track (%s -> %s)', flavor, track)
track = track.encode('ascii', 'ignore')
fields = [('mediaPackage', mediapackage), ('flavor', flavor),
('BODY1', (pycurl.FORM_FILE, track))]
mediapackage = http_request(service_url + '/addTrack', fields,
timeout=0)
else:
logger.info('Not adding track (%s -> %s)', flavor, track)

# ingest
logger.info('Ingest recording')
Expand Down
27 changes: 27 additions & 0 deletions pyca/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,33 @@ def update_agent_state():
register_ca(status=status)


def update_agent_config():
'''Update the current agent configuration in opencast.
'''

if config('agent', 'backup_mode'):
return
service_endpoint = service('capture.admin')
if not service_endpoint:
logger.warning('Missing endpoint for updating agent status.')
return

inputs = ",".join(config('agent', 'inputs'))
params = [(
'configuration',
'{\'capture.device.names\': \'' + inputs + '\'}'
)]

name = urlquote(config('agent', 'name').encode('utf-8'), safe='')
url = f'{service_endpoint[0]}/agents/{name}/configuration'
try:
response = http_request(url, params).decode('utf-8')
if response:
logger.info(response)
except pycurl.error as e:
logger.warning('Could not set configuration of agent %s: %s', name, e)


def terminate(shutdown=None):
'''Mark process as to be terminated.
'''
Expand Down
Loading