in src/process_results/ad_placements.py [0:0]
def get_available_placement_text(self):
available_slots = []
# treat the end as if it was another piece of text
self.add_text_presence(self.video_length_in_ms)
# and make sure we handle the start of the video, if there is room for an ad
if self.text_shown_segments[0]['start'] > self.min_ad_duration_in_msec:
self.text_shown_segments.insert(0, {'start': 0, 'end': 0})
# calculate the slots
for segment_number in range(0, len(self.text_shown_segments) - 1):
last_segment_end = self.text_shown_segments[segment_number]['end']
next_segment_start = self.text_shown_segments[segment_number + 1]['start']
# add 1 second padding to the end of one and the start of the next, since
# Rekognition tends to detect text in videos at 1 second intervals
last_segment_end += 1000
next_segment_start -= 1000
intra_segment_length_in_msec = next_segment_start - last_segment_end
if intra_segment_length_in_msec > self.min_ad_duration_in_msec:
start_segment_string = self.format_time(last_segment_end)
end_segment_string = self.format_time(next_segment_start)
segment_length_string = self.format_time(intra_segment_length_in_msec)
new_slot_description = (
f"Available slot from {start_segment_string} to {end_segment_string}, "
f"duration: {segment_length_string}")
available_slots.append(new_slot_description)
# and then return a string with them
return '\n'.join(available_slots)