def build_input_settings()

in source/controlplaneapi/infrastructure/lambda/EventClipGenerator/mre-event-clip-generator.py [0:0]


def build_input_settings(dataplane, segment_group, event):

    # Check if an AudioTrack has been sent in the event.
    # If yes, set the AudioTrack for extraction in MediaConvert
    # Also use the AudioTrack in the Output video key prefix
    audioTrack = 1 if 'TrackNumber' not in event else event['TrackNumber']

    

    inputs = []
    for segment in segment_group:

        # If a Segment has been Optimized, use the Opt clip timings. If not, fall on back on the Original Clip timings
        # Commenting these Temporarily until the usecase if finalized.

        if "OptoEnd" in segment and "OptoStart" in segment:
            # Check if the Maps have content, if not fall back on Original Segment
            #if len(segment['OptoEnd']) > 0 and len(segment['OptoStart']) > 0 :
        
            #Ignore Starts that have -1 in it
            if get_OptoStart(segment, event) == -1:
                continue

            chunks = dataplane.get_chunks_for_segment(get_OptoStart(segment, event), get_OptoEnd(segment, event))

            # Only chunk, so will have Start and End Clipping time
            if len(chunks) == 1:
                inputClippings = []
                inputClip = {}
                ic = {}

                endtime, starttime = get_clip_timings(segment, event)
                ic['EndTimecode'] = str(endtime)
                ic['StartTimecode'] = str(starttime)

                #If we have a single Chunk we don't need the Endtime Configured if it is less than Start time. Remove it.
                if datetime.strptime(endtime, "%H:%M:%S:%f") < datetime.strptime(starttime, "%H:%M:%S:%f"):
                    ic.pop('EndTimecode', None)

                #ic['EndTimecode'], ic['StartTimecode'] = get_clip_timings(segment, event)
                inputClippings.append(ic)
                inputClip['InputClippings'] = inputClippings
                # inputClip['AudioSelectors'] = {
                #         "Audio Selector 1": {
                #             "DefaultSelection": "DEFAULT"
                #         } 
                #     }

                #------------- Update MediaConvert AudioSelectors Input -------------

                # Leave the default Input AudioSelectors as is if we are dealing with default Track or only one.
                # If we have multiple AudioTracks, this lambda will be provided with one.
                if int(audioTrack) > 0:
                    inputClip['AudioSelectors'] =   {
                                                    "Audio Selector 1": {
                                                        "Tracks": [
                                                            int(audioTrack)
                                                        ],
                                                        "DefaultSelection": "NOT_DEFAULT",
                                                        "SelectorType": "TRACK"
                                                    }
                                                }
                else:
                    inputClip['AudioSelectors'] =   {
                                            "Audio Selector 1": {
                                                "DefaultSelection": "DEFAULT"
                                            }
                                        }
                inputClip['AudioSelectorGroups'] =  {
                                                        "Audio Selector Group 1": {
                                                            "AudioSelectorNames": [
                                                            "Audio Selector 1"
                                                            ]
                                                        }
                                                    }
                                                    
                #------------- Update MediaConvert AudioSelectors Input Ends -------------
                
                inputClip['VideoSelector'] = {}
                inputClip['TimecodeSource'] = "ZEROBASED"
                inputClip['FileInput'] = f"s3://{chunks[0]['S3Bucket']}/{chunks[0]['S3Key']}"
                inputs.append(inputClip)
            elif len(chunks) > 1:
                for chunk_index in range(len(chunks)):
                    ic = {}
                    inputClippings = []
                    inputClip = {}
                    if chunk_index == 0:    # First Chunk
                        ic['StartTimecode'] = get_start_clip_timings(segment, event)
                        inputClippings.append(ic)
                        inputClip['InputClippings'] = inputClippings
                    elif chunk_index == len(chunks)-1:  # Last Chunk
                        ic['EndTimecode'] = get_end_clip_timings(segment, event)
                        inputClippings.append(ic)
                        inputClip['InputClippings'] = inputClippings
                    else:   # Sandwitch Chunks have no clippings
                        inputClip['InputClippings'] = []

                    
                    #------------- Update MediaConvert AudioSelectors Input -------------

                    # Leave the default Input AudioSelectors as is if we are dealing with default Track or only one.
                    # If we have multiple AudioTracks, this lambda will be provided with one.
                    if int(audioTrack) > 0:
                        inputClip['AudioSelectors'] =   {
                                                        "Audio Selector 1": {
                                                            "Tracks": [
                                                                int(audioTrack)
                                                            ],
                                                            "DefaultSelection": "NOT_DEFAULT",
                                                            "SelectorType": "TRACK"
                                                        }
                                                    }
                    else:
                        inputClip['AudioSelectors'] =   {
                                            "Audio Selector 1": {
                                                "DefaultSelection": "DEFAULT"
                                            }
                                        }
                    inputClip['AudioSelectorGroups'] =  {
                                                            "Audio Selector Group 1": {
                                                                "AudioSelectorNames": [
                                                                "Audio Selector 1"
                                                                ]
                                                            }
                                                        }
                                                        
                #------------- Update MediaConvert AudioSelectors Input Ends -------------
                    inputClip['VideoSelector'] = {}
                    inputClip['TimecodeSource'] = "ZEROBASED"
                    inputClip['FileInput'] = f"s3://{chunks[chunk_index]['S3Bucket']}/{chunks[chunk_index]['S3Key']}"
                    inputs.append(inputClip)
    

        
        # elif "End" in segment and "Start" in segment and event['GenerateOriginal']:
        
        #         #Ignore Starts that have -1 in it
        #         if segment['Start'] == -1:
        #             continue
                
        #         build_input_settings_for_orig_segment(dataplane, inputs, segment, event)
                

            
    return inputs