Skip to content

limelight.export.subtitles

CUE_EVENTS = (EventName.NARRATE, EventName.TITLE) module-attribute

CUE_MS_FALLBACK = 4500 module-attribute

subtitles_export

A function that builds the export for the subtitle track.

Returns:

  • TextExport –

    The export that writes the WebVTT file.

Source code in limelight/export/subtitles.py
def subtitles_export() -> TextExport:
    """
    A function that builds the export for the subtitle track.

    :return: The export that writes the WebVTT file.
    """

    return TextExport(SUBTITLES_FILE_NAME, vtt_render)

vtt_render

A function that renders the narration events as a WebVTT track.

Parameters:

  • events (list[Event]) –

    The recorded events of the run.

Returns:

  • str –

    The subtitle track.

Source code in limelight/export/subtitles.py
def vtt_render(events: list[Event]) -> str:
    """
    A function that renders the narration events as a WebVTT track.

    :param events: The recorded events of the run.
    :return: The subtitle track.
    """

    lines = ['WEBVTT']

    for index, event in enumerate(events):
        if event.get('event') not in CUE_EVENTS:
            continue

        start_ms = event_offset_ms(event)
        end_ms = _cue_end_ms(events, index=index, start_ms=start_ms)

        lines += [
            '',
            f'{_timestamp(start_ms)} --> {_timestamp(end_ms)}',
            _cue_text(event),
        ]

    return '\n'.join(lines) + '\n'