in broadcast-monitoring/src/expected_program/app/main.py [0:0]
def lambda_handler(event, context):
"""
:param event:
{
"s3Bucket": "aws-rnd-broadcast-maas-video-processing-dev",
"s3Key": "live/test_video_single_pipeline/test_1.m3u8",
"s3VersionId": "KJCfz6c8Il5E_23jbzwYuFhGIpvMnrJE",
"config": {
"audio_check_enabled": true,
"station_logo_check_enabled": true,
"language_detect_check_enabled": true,
"team_detect_check_enabled": true,
"appsync_notify_enabled": true
},
"parsed": {
{
"isMasterManifest": false,
"streamId": "test_1",
"lastSegment": {
"s3Key": "live/test_video_single_pipeline/test_1_00039.ts",
"startDateTime": "2020-01-23T21:36:35.290000Z",
"durationSec": 6
}
}
}
}
:return:
"""
manifest_s3_bucket = event['s3Bucket']
segment_s3_key = event['parsed']['lastSegment']['s3Key']
stream_id = event['parsed']['streamId']
# the cleanup_dir decorator will ensure the tmp/ working directory gets cleaned up if lambda container is reused
segment_file = download_file_from_s3(manifest_s3_bucket, segment_s3_key)
start_time = get_relative_start_sec(segment_file)
duration_sec = event['parsed']['lastSegment']['durationSec']
# TODO: add support for if the input stream is actual live video
# (perhaps a slightly different lookup mechanism based on absolute timestamp)
expected_program = find_expected_program_for_looping_input(stream_id, start_time, duration_sec)
event['parsed']['lastSegment']['startTimeRelative'] = start_time
event['parsed']['expectedProgram'] = expected_program
available_detection = check_available_detection(event, stream_id, expected_program['Segment_Start_Time_In_Loop'],
event['parsed']['lastSegment']['startDateTime'],
duration_sec)
if available_detection:
event['reuse'] = {
'enabled': True,
'segment': available_detection
}
else:
event['reuse'] = {
'enabled': False
}
# disable team check when there's no expected team in program
if 'Team_Info' not in expected_program:
event['config'][TEAM_CHECK_CONFIG_KEY] = False
event['config'][TEAM_LOGO_CHECK_CONFIG_KEY] = False
# disable sports check when the program is not sports
if 'Sports_Type' not in expected_program:
event['config'][SPORTS_CHECK_CONFIG_KEY] = False
return event