def get_clip_metadata()

in source/dataplaneapi/runtime/app.py [0:0]


def get_clip_metadata(name, program, start, duration, tracknumber, classifier, mode):
    try:
        event = urllib.parse.unquote(name)
        program = urllib.parse.unquote(program)
        clip_startsAt_secs = Decimal(urllib.parse.unquote(start))
        clip_duration = Decimal(urllib.parse.unquote(duration))
        tracknumber = str(urllib.parse.unquote(tracknumber))
        classifier = urllib.parse.unquote(classifier)

        clips_info = get_clipinfo_from_plugin_results(name, program, start, duration)

        # We need to generate 2 Datasets from the Clips Info for this Specific Clip
        # Range based Event - Silence detection, Scene Detection etc.
        # Single value Feature - Ace Shot, Labels - Far/Near etc.

        range_based_events = []
        unique_range_labels = []
        single_value_features = []
        unique_feature_labels = []
        range_based_events_chart = []

        for item in clips_info:

            # Its a Single Value feature if the Start and End times are the same
            if item['Start'] == item['End']:
                if mode == 'Optimized':
                    tmp_feature = create_feature(item, clip_startsAt_secs, tracknumber, "Optimized")
                else:
                    tmp_feature = create_feature(item, clip_startsAt_secs, -1, "Original")

                if tmp_feature is not None:
                    single_value_features.append(tmp_feature)

                # Return Labels for Chart rendering
                if f"{item['PluginName']}-{item['Label']}" not in unique_feature_labels:
                    unique_feature_labels.append(f"{item['PluginName']}-{item['Label']}")
            else:
                # Only display Featurers in the Range Plugin Table
                if item['PluginClass'] in ['Featurer', 'Labeler', 'Classifier']:
                    if mode == 'Optimized':
                        range_event = create_range_event(item, clip_startsAt_secs, tracknumber, "Optimized")
                    else:
                        range_event = create_range_event(item, clip_startsAt_secs, -1, "Original")

                    if range_event is not None:
                        range_based_events.append(range_event)

                    if item['PluginName'] not in unique_range_labels:
                        unique_range_labels.append(item['PluginName'])

                    # Data for the Bar Chart
                    # -X--|------                           |
                    #    |         -------------           |
                    #    |               ------------------|--Y--      
                    #    |    --------------               | 
                    #    |       -----------------------   |
                    # Marker represents the start and end of a Bar in the Bar Chart.
                    # The Start time will be set to Zero if the ClipsStart time was Negative. (X in the above schematic)
                    # The Length of Each bar is Sum of Start and Duration. For example, Starttime is 4 Secs and Duration 10 secs. 
                    # The Bar would start from 4 Secs and End at 14 secs on the Bar Chart.
                    # If the Bar length goes beyond the Clip's length, we truncate the Bar length (Y in the above schematic)
                    if range_event is not None:
                        range_event_chart = {}
                        range_event_chart[range_event['Marker']] = [range_event['Start'],
                                                                    range_event['Start'] + range_event['Duration'] if (
                                                                                                                              range_event[
                                                                                                                                  'Start'] +
                                                                                                                              range_event[
                                                                                                                                  'Duration']) < clip_duration else
                                                                    range_event['Start'] + (
                                                                            clip_duration - range_event['Start'])]
                        range_event_chart['Start'] = range_event['Start']
                        range_based_events_chart.append(range_event_chart)


    except Exception as e:
        print(f"Unable to retrieve Plugin results '{name}' in Program '{program}': {str(e)}")
        raise ChaliceViewError(e)

    else:

        clip_url = ""

        if mode == 'Optimized':
            clip_url = get_clip_signed_url(clip_startsAt_secs, event, program, classifier, tracknumber, 'Optimized')
        else:
            clip_url = get_clip_signed_url(clip_startsAt_secs, event, program, classifier, tracknumber, 'Original')

        finalresults = {
            "RangeEvents": range_based_events,
            "RangeEventsChart": range_based_events_chart,
            "RangeLabels": unique_range_labels,
            "Features": single_value_features,
            "FeatureLabels": unique_feature_labels
        }
        if mode == 'Optimized':
            finalresults['OptimizedClipLocation'] = clip_url
        else:
            finalresults['OriginalClipLocation'] = clip_url

        return replace_decimals(finalresults)