documents Package

documents Package

base Module

class ebu_tt_live.documents.base.CloningDocumentSequence[source]

Bases: ebu_tt_live.documents.base.DocumentSequence

Base class that picks up a document and creates an appropriate stream based on it. Bear in mind continuation/revision or reproduction of a received document stream.

classmethod create_from_document(document, *args, **kwargs)[source]

Extract data from document :param document: :param args: :param kwargs: parameter override to constructor :return:

class ebu_tt_live.documents.base.DocumentSequence[source]

Bases: object

Base class that facilitates most production-related workflows. The document stream should maintain the consistency across critical document attributes. It should maintain all sorts of counters and static information. It plays a key role in the validation of an outgoing stream of subtitle documents.

add_document(document)[source]

Add the document to the sequence on the consumer side of things. This will put the document on the timeline and validate the sequence in terms of timing resolution. :param document: :raises IncompatibleSequenceError meaning that the document cannot be part of this sequence for it does not match the semantics of the sequence.

fork(*args, **kwargs)[source]

Create a new stream with modified arguments. :param args: :param kwargs: parameter override to constructor :return: a new documentstream instance

get_document(seq_id)[source]

Retrieve document by sequence number :param seq_id: :return: a document :raises: KeyError meaning the document is not in the sequence

new_document(*args, **kwargs)[source]

Create a new document with the stream defaults :param args: :param kwargs: parameter override to constructor :return: a new document

class ebu_tt_live.documents.base.SubtitleDocument[source]

Bases: ebu_tt_live.utils.ComparableMixin

validate()[source]
class ebu_tt_live.documents.base.TimeBase[source]

Bases: object

CLOCK = 'clock'
MEDIA = 'media'
SMPTE = 'smpte'

ebutt3 Module

class ebu_tt_live.documents.ebutt3.EBUTT3Document(time_base, sequence_number, sequence_identifier, lang, clock_mode=None, availability_time=None, authors_group_identifier=None)[source]

Bases: ebu_tt_live.documents.ebutt3.TimelineUtilMixin, ebu_tt_live.documents.base.SubtitleDocument, ebu_tt_live.documents.ebutt3.EBUTT3ObjectBase

This class wraps the binding object representation of the XML and provides the features the applications in the specification require. e.g:availability time.

_availability_time = None
_cmp_checks(other)[source]

Extra checks that need to be fulfilled in order for the comparison to make sense. Any custom exceptions thrown here are preserved and propagated in original form. :param other: :return:

_cmp_key()[source]

Implement the delegation method. :return: comparable member

_computed_begin_time = None
_computed_end_time = None
_ebutt3_content = None
_resolved_begin_time = None
_resolved_end_time = None
_sequence = None
add_div(div)[source]
authors_group_control_token
authors_group_identifier
authors_group_selected_sequence_identifier
availability_time
binding
cleanup()[source]

This function is meant to get rid of all the validation added data that may be blocking garbage collection of the objects. :return:

clock_mode
computed_begin_time
computed_end_time
content_to_string(begin=None, end=None)[source]

Extract the document textual content between begin/end along with their activation times.

Parameters:
  • begin – From specified begin time or resolved begin time if begin is not specified.
  • end – Up to specified end time or resolved end time if end is not specified.
Returns:

String showing the activation and content of the elements.

classmethod create_from_raw_binding(binding, availability_time=None)[source]
classmethod create_from_xml(xml, availability_time=None)[source]
discard_document(resolved_end_time, verbose=False)[source]

This function discards the document by setting a resolved end time before the document begins. :param resolved_end_time:

discarded
extract_segment(begin=None, end=None, deconflict_ids=False)[source]

Create a valid ebutt3 document subset. As it collects data it will also prefix the ids in the document with the document sequence number so that later merge does not have collision.

Parameters:
  • begin
  • end
  • deconflict_ids – prevent id clash across documents by prefixing the IDs
Returns:

EBUTT3Document

get_dom()[source]
get_element_by_id(elem_id, elem_type=None)[source]
get_xml()[source]
lang
resolved_begin_time
resolved_end_time
sequence
sequence_identifier
sequence_number
set_begin(begin)[source]
set_dur(dur)[source]
set_end(end)[source]
time_base
validate()[source]
class ebu_tt_live.documents.ebutt3.EBUTT3DocumentSequence(sequence_identifier, reference_clock, lang, verbose=False, authors_group_identifier=None)[source]

Bases: ebu_tt_live.documents.ebutt3.TimelineUtilMixin, ebu_tt_live.documents.base.CloningDocumentSequence

EBU-TT Live specific document sequence. It maps the documents based on their sequence numbers and timing attributes.

The sequence object can be used in 2 different modes:
  • It can be used to produce a sequence(i.e.: new_document method)
  • as well as it is the pivotal point of the consumer use-case when the document timings need to be resolved. (i.e.: add_document method)

The sequence is responsible to keep the documents ordered and filter those documents out, which were eventually overwritten. It ensures that at any given time exactly 0 or 1 document is active (R14).

_authors_group_identifier = None
_check_document_compatibility(document)[source]
_clock_mode = None
_documents = None
_find_resolved_begin_event(document)[source]
_find_resolved_end_event(document)[source]
_insert_document(document, ends=None)[source]

In the end this function adds the document to the sequence registers.

Parameters:
  • document
  • ends
Returns:

_insert_or_discard(document)[source]

This function does the heavy lifting of timing resolution. It inspects the close vicinity in which the new document is coming by looking at the timeline in both directions.

Based on that information it can detect 3 different cases:
  • out of order delivery of documents in which case it inserts and trims the document,
  • sequence override scenario in which case an exception is raised.
  • Document discard scenario in which case the document is already overwritten in the sequence so it will not get inserted.
Raises:ValueError, SequenceOverridden, DocumentDiscardedError
_lang = None
_last_sequence_number = None
_override_sequence(document)[source]

This function clears the timeline and the associated documents after the document in the parameter. This happens when a document with a higher sequence number is added preceding some other documents with lower sequence numbers.

Parameters:document
Returns:
_reference_clock = None
_sequence_identifier = None
_time_base = None
_verbose = None
add_document(document)[source]

Add the document to the sequence on the consumer side of things. This will put the document on the timeline and validate the sequence in terms of timing resolution. :param document: :raises IncompatibleSequenceError meaning that the document cannot be part of this sequence for it does not match the semantics of the sequence.

authors_group_identifier
cleanup()[source]
create_compatible_document(*args, **kwargs)[source]

This utility function is used by the converter to extract segments and by the new_document function.

Parameters:
  • args
  • kwargs
Returns:

classmethod create_from_document(document, verbose=False, *args, **kwargs)[source]

Extract data from document :param document: :param args: :param kwargs: parameter override to constructor :return:

discard_before(document)[source]

This function gets rid of old documents we do not wish to keep any longer. :param document: The document up to which we would like to discard things :return:

extract_segment(begin=None, end=None, sequence_number=None, discard=False)[source]

Extract the subtitles from the sequence in the given timeframe. The return value is one merged EBUTT3Document

Parameters:
  • begin
  • end
Returns:

EBUTT3Document

fork(*args, **kwargs)[source]

Create a new stream with modified arguments. :param args: :param kwargs: parameter override to constructor :return: a new documentstream instance

get_document(seq_id)[source]

Retrieve document by sequence number :param seq_id: :return: a document :raises: KeyError meaning the document is not in the sequence

is_compatible(document)[source]
last_sequence_number
new_document(*args, **kwargs)[source]

Create a new document with the stream defaults :param args: :param kwargs: parameter override to constructor :return: a new document

reference_clock
resolved_begin_time(document)[source]
resolved_end_time(document)[source]
sequence_identifier
class ebu_tt_live.documents.ebutt3.EBUTT3ObjectBase[source]

Bases: object

classmethod create_from_raw_binding(**kwargs)[source]
classmethod create_from_xml(xml, **kwargs)[source]
get_dom()[source]
get_xml()[source]
message_type_mapping = {'authorsGroupControlRequest': <class 'ebu_tt_live.documents.ebutt3.EBUTTAuthorsGroupControlRequest'>}
class ebu_tt_live.documents.ebutt3.EBUTTAuthorsGroupControlRequest(sequence_identifier, payload, availability_time=None, sender=None, recipient=None)[source]

Bases: ebu_tt_live.documents.ebutt3.EBUTTLiveMessage

_create_binding()[source]
classmethod create_from_raw_binding(binding, availability_time=None, **kwargs)[source]
get_dom()[source]
get_xml()[source]
message_type_id = 'authorsGroupControlRequest'
class ebu_tt_live.documents.ebutt3.EBUTTLiveMessage[source]

Bases: ebu_tt_live.documents.ebutt3.EBUTT3ObjectBase

_availability_time = None
_payload = None
_recipient = None
_sender = None
_sequence_identifier = None
availability_time
payload
recipient
sender
sequence_identifier
class ebu_tt_live.documents.ebutt3.TimelineUtilMixin[source]

Bases: object

This mixin is responsible for managing the shared timeline functionality

_timeline = None
add_to_timeline(element)[source]

The element gets added to the timeline so it would be easier to look up. :param element: :return:

locate_element_begin(element)[source]
locate_element_end(element)[source]
lookup_range_on_timeline(begin=None, end=None)[source]

Extract a segment of the timeline and :param begin: :param end: :return: A list of elements in chronological order

reset_timeline()[source]
timeline
class ebu_tt_live.documents.ebutt3.TimingEvent(element, when)[source]

Bases: object

This class wraps a document and an associated resolved timing event into an object that can be placed on the timeline.

_element = None
_when = None
element
when
class ebu_tt_live.documents.ebutt3.TimingEventBegin(element)[source]

Bases: ebu_tt_live.documents.ebutt3.TimingEvent

Element/document resolved begin time

class ebu_tt_live.documents.ebutt3.TimingEventEnd(element)[source]

Bases: ebu_tt_live.documents.ebutt3.TimingEvent

Element/document resolved end time.

ebutt3_segmentation Module

class ebu_tt_live.documents.ebutt3_segmentation.EBUTT3Segmenter(document, begin=None, end=None, deconflict_ids=False)[source]

Bases: ebu_tt_live.bindings.pyxb_utils.RecursiveOperation

_after_element(value, element=None, parent_binding=None, **kwargs)[source]
_before_element(value, element=None, parent_binding=None, **kwargs)[source]
_begin = None
_convert_time(timedelta_value)[source]
_deconflict_ids = None
_do_copy(element, dataset)[source]
_do_deconflict_id(element)[source]
_document = None
_end = None
_instance_mapping = None
_process_element(value, element=None, parent_binding=None, **kwargs)[source]
_process_non_element(value, non_element, parent_binding=None, **kwargs)[source]
_prune_orphan_elements()[source]

Unused elements need to go from the head section. :return:

_segment = None
_semantic_dataset = None
begin
compute_document_segment()[source]
deconflict_ids
document
end
proceed(**kwargs)[source]
segment

ebutt3_splicer Module

class ebu_tt_live.documents.ebutt3_splicer.EBUTT3Splicer(document_segments, sequence_identifier, sequence_number)[source]

Bases: object

_dataset = None
_do_splice()[source]
_document_segments = None
_sequence_identifier = None
_sequence_number = None
_spliced_document = None
spliced_document

bindings_converters Module

class ebu_tt_live.bindings.converters.ebutt3_ebuttd.EBUTT3EBUTTDConverter(media_clock)[source]

Bases: object

_adjusted_font_style_map()[source]
_children_contain(container_elem, binding_type)[source]
_dataset_key_for_font_styles = 'adjusted_sizing_styles'
_fix_fontsize(elem, celem, parent, dataset)[source]

This function generates styles for the purpose of conversion from c,px values to percentage values. The fontSize attributes were removed in the initial styling copy function so here we generate new ones to serve our purpose best and easiest :param elem: the original instance :param celem: the converted instance :param parent: the parent of the original :param dataset: semantic dataset :return:

_font_size_style_template = 'autogenFontStyle_{}_{}'
_get_font_size_style(vertical, dataset, horizontal=None)[source]

This function either points us to an already generated version of this style or creates it on demand. :param vertical: :param horizontal: :return:

_media_clock = None
_process_timing_type(timing_type, dataset)[source]
_semantic_dataset = None
convert_body(body_in, dataset)[source]
convert_br(br_in, dataset)[source]
convert_children(element, dataset)[source]

Recursive step :param element: :param dataset: :return:

convert_div(div_in, dataset)[source]
convert_document(root_element, dataset=None)[source]
convert_element(element, dataset)[source]
convert_head(head_in, dataset)[source]
convert_layout(layout_in, dataset)[source]
convert_p(p_in, dataset)[source]
convert_region(region_in, dataset)[source]
convert_span(span_in, dataset)[source]
convert_style(style_in, dataset)[source]
convert_styling(styling_in, dataset)[source]
convert_tt(tt_in, dataset)[source]
convert_unknown(element, dataset)[source]
map_type(in_element)[source]

document_converters Module

ebu_tt_live.documents.converters.ebutt3_to_ebuttd(ebutt3_in, media_clock)[source]

This function takes an EBUTT3Document instance and returns the same document as an EBUTTDDocument instance. :param ebutt3_in: :return:

ebuttd Module

class ebu_tt_live.documents.ebuttd.EBUTTDDocument(lang)[source]

Bases: ebu_tt_live.documents.base.SubtitleDocument

_ebuttd_content = None
_get_bds()[source]
_implicit_ns = False
classmethod create_from_raw_binding(binding)[source]
classmethod create_from_xml(xml)[source]
get_dom()[source]
get_xml()[source]
set_implicit_ns(value)[source]
validate()[source]