aeidon.Project

Source: aeidon/project.py

Anchestors: aeidon.observable.Observable, builtins.object

class aeidon.Project

Model for subtitle data.

Project.calc

Instance of aeidon.Calculator used

Project.clipboard

Instance of aeidon.Clipboard used

Project.framerate

aeidon.framerates item corresponding to video

Project.main_changed

Integer, status of main document

At unchanged state (i.e. file on disk corresponds to the state of the document) this value is zero. Doing and redoing increase the value by one and undoing decreases value by one.

Project.main_file

Main instance of aeidon.SubtitleFile

Project.redoables

Stack of aeidon.RevertableAction instances

Project.subtitles

List of aeidon.Subtitle instances

Project.tran_changed

Integer, status of translation document

At unchanged state (i.e. file on disk corresponds to the state of the document) this value is zero. Doing and redoing increase the value by one and undoing decreases value by one.

Project.tran_file

Translation instance of aeidon.SubtitleFile

Project.undo_limit

Maximum size of undo/redo stacks or None for no limit

Project.undoables

Stack of aeidon.RevertableAction instances

Project.video_path

Full, absolute path to the video file on disk

Signals and their arguments for callback functions:
  • action-done: project, action
  • action-redone: project, action
  • action-undone: project, action
  • main-file-opened: project, main_file
  • main-file-saved: project, main_file
  • main-texts-changed: project, indices
  • positions-changed: project, indices
  • subtitles-changed: project, indices
  • subtitles-inserted: project, indices
  • subtitles-removed: project, indices
  • translation-file-opened: project, tran_file
  • translation-file-saved: project, tran_file
  • translation-texts-changed: project, indices

Methods

Project.__init__(framerate=None)

Initialize a Project instance.

Project.add_dialogue_dashes(indices, doc, register=-1)

Add dialogue dashes to all lines of texts.

Project.adjust_durations(indices=None, speed=None, lengthen=False, shorten=False, minimum=None, maximum=None, gap=None, register=-1)

Lengthen or shorten durations by changing end positions.

indices can be None to process all subtitles. speed is reading speed in characters per second. lengthen is True to increase durations to match reading speed. shorten is True to decrease durations to match reading speed. maximum is the greatest allowed duration in seconds. minimum is the smallest allowed duration in seconds. gap is seconds to be left between consecutive subtitles. Using a gap of at least zero is always a good idea if overlapping is not desired. Return changed indices.

Project.break_lines(indices, doc, patterns, length_func, max_length, max_lines, skip=False, max_skip_length=32768, max_skip_lines=32768, register=-1)

Break lines to fit defined maximum line length and count.

indices can be None to process all subtitles. patterns should be a sequence of instances of aeidon.Pattern. length_func should return the length of a string argument. max_length should be the maximum allowed length of lines in the same scale as returned by length_func. max_lines may be violated to avoid violating max_length. If skip is True, subtitles that do not violate or do not manage to reduce max_skip_length and max_skip_lines are skipped.

Raise re.error if a bad regular expression among patterns.

Project.can_redo(count=1)

Return True if one or more actions can be redone.

Project.can_undo(count=1)

Return True if one or more actions can be undone.

Project.capitalize(indices, doc, patterns, register=-1)

Capitalize texts as defined by patterns.

indices can be None to process all subtitles. patterns should be a sequence of instances of aeidon.Pattern. Raise re.error if a bad regular expression among patterns.

Project.change_case(indices, doc, method, register=-1)

Change the case of texts with method.

method should be “title”, “capitalize”, “upper” or “lower”, which correspond to the built-in Python string methods.

Project.clear_texts(indices, doc, register=-1)

Set texts to blank strings.

Project.convert_framerate(indices, framerate_in, framerate_out, register=-1)

Set the value of framerate and convert subtitles to it.

indices can be None to process all subtitles.

Project.copy_texts(indices, doc)

Copy texts to the clipboard.

Project.correct_common_errors(indices, doc, patterns, register=-1)

Correct common human and OCR errors in texts.

indices can be None to process all subtitles. patterns should be a sequence of instances of aeidon.Pattern. Raise re.error if a bad regular expression among patterns.

Project.cut_reversion_stacks()

Cut undo and redo stacks to their maximum lengths.

Project.cut_texts(indices, doc, register=-1)

Cut texts to the clipboard.

Project.emit_action_signal(register)

Emit an action signal for the most recent registered action.

Project.find_next(index=None, doc=None, pos=None)

Find the next match starting from given position.

index, doc and pos can be None to start from beginning. Raise StopIteration if no (more) matches exist. Return tuple of index, document, match span.

Project.find_previous(index=None, doc=None, pos=None)

Find the previous match starting from given position.

index, doc and pos can be None to start from end. Raise StopIteration if no (more) matches exist. Return tuple of index, document, match span.

Project.find_video()

Find and return the video file path based on main file’s path.

The video file is searched for in the same directory as the subtitle file. The subtitle file’s filename without extension is assumed to start with or match the video file’s filename without extension, e.g. ‘movie.avi’ for ‘movie.en.srt’.

Project.get_all_indices()

Return a list of all indices of subtitles.

Project.get_changed(doc)

Return the changed value corresponding to doc.

Project.get_file(doc)

Return the file corresponding to doc.

Project.get_format(doc)

Return format of the file corresponding to doc.

For a translation file that is None, return format of main file. If main file is None, return None.

Project.get_liner(doc)

Return a new aeidon.Liner instance.

Project.get_markup(doc)

Return doc‘s markup instance or None.

Project.get_markup_clean_func(doc)

Return the function to clean markup or None.

Project.get_markup_tag_regex(doc)

Return the regular expression for a markup tag or None.

Project.get_mode()

Return mode of the main file or default.

Project.get_parser(doc)

Return a new aeidon.Parser instance.

Project.get_text_length(index, doc)

Return the amount of characters in text excluding markup.

Project.get_text_signal(doc)

Return the texts-changed signal corresponding to doc.

Project.group_actions(register, count, description)

Group the registered actions as one item in the stack.

Project.insert_subtitles(indices, subtitles=None, register=-1)

Insert subtitles at indices.

If subtitles is None, insert blank subtitles with sensible equal duration positions within given window or with 3 second durations if window not limited.

Project.italicize(indices, doc, register=-1)

Surround texts with italic markup.

Project.merge_subtitles(indices, register=-1)

Merge subtitles at indices to form one subtitle.

Project.new_subtitle()

Return a new aeidon.Subtitle instance.

Project.new_temp_file(doc, encoding=None)

Return path to a new temporary file with subtitles from doc.

Raise IOError if writing to temporary file fails. Raise UnicodeError if encoding temporary file fails.

Project.open(doc, path, encoding=None, align_method=None)

Read and parse subtitle data for doc from path.

encoding can be None to use the system default encoding. Return the amount of subtitles that needed to be moved in order to arrange them in ascending chronological order.

Raise IOError if reading fails. Raise UnicodeError if decoding fails. Raise aeidon.FormatError if unable to detect format. Raise aeidon.ParseError if parsing fails.

Project.open_main(path, encoding=None)

Read and parse subtitle data for main file from path.

encoding can be None to use the system default encoding. Return the amount of subtitles that needed to be moved in order to arrange them in ascending chronological order.

Raise IOError if reading fails. Raise UnicodeError if decoding fails. Raise aeidon.FormatError if unable to detect format. Raise aeidon.ParseError if parsing fails.

Project.open_translation(path, encoding=None, align_method=None)

Read and parse subtitle data for translation file from path.

encoding can be None to use the system default encoding. align_method specifies how translation texts are attached to existing subtitles. aeidon.align_methods.NUMBER is the simple way, which adds the translation texts in order, one-by-one to the exising subtitles. aeidon.align_methods.POSITION (the default) is the smarter way, which compares the position data in the translation subtitles with the existing subtitles, skips and inserts subtitles as needed to have at least a rough chronological match. The latter thus takes into account that not all subtitles are translated, or vice versa and that one main subtitle may correspond to two translation subtitles, or vice versa, as per length restrictions etc.

Return the amount of subtitles that needed to be moved in order to arrange them in ascending chronological order.

Raise IOError if reading fails. Raise UnicodeError if decoding fails. Raise aeidon.FormatError if unable to detect format. Raise aeidon.ParseError if parsing fails.

Project.paste_texts(index, doc, register=-1)

Paste texts from the clipboard and return pasted indices.

Project.preview(position, doc, command, offset, encoding=None, temp=False)

Start video player with command from position.

command can have variables $MILLISECONDS, $SECONDS, $SUBFILE and $VIDEOFILE. offset should be the amount of seconds before position to start. encoding can be specified if different from doc file encoding. Use True for temp to always use a temporary file for preview regardless of whether the file is changed or not.

Return a three tuple of subprocess.POpen instance, command with variables expanded and a file object to which process standard output and standard error are directed.

Raise IOError if writing to temporary file fails. Raise UnicodeError if encoding temporary file fails. Raise aeidon.ProcessError if unable to start process.

Project.redo(count=1)

Redo count amount of actions from the redoable stack.

Project.register_action(action)

Register action as done, undone or redone.

Project.remove_dialogue_dashes(indices, doc, register=-1)

Remove dialogue dashes from all lines of texts.

Project.remove_hearing_impaired(indices, doc, patterns, register=-1)

Remove hearing impaired parts from subtitles.

indices can be None to process all subtitles. patterns should be a sequence of instances of aeidon.Pattern. Raise re.error if a bad regular expression among patterns.

Project.remove_subtitles(indices, register=-1)

Remove subtitles at indices.

Project.replace(register=-1)

Replace the current match of pattern.

Raise re.error if bad replacement.

Project.replace_all(register=-1)

Replace all matches of pattern and return amount of replacements made.

Raise re.error if bad replacement.

Project.replace_positions(indices, subtitles, register=-1)

Replace positions at indices with those from subtitles.

Project.replace_texts(indices, doc, texts, register=-1)

Replace texts in doc‘s indices with texts.

Project.save(doc, file=None, keep_changes=True)

Write subtitle data from doc to file.

file can be None to use existing file. Raise IOError if writing fails. Raise UnicodeError if encoding fails.

Project.save_main(file=None, keep_changes=True)

Write subtitle data from main document to file.

file can be None to use main_file. Raise IOError if writing fails. Raise UnicodeError if encoding fails.

Project.save_translation(file=None, keep_changes=True)

Write subtitle data from translation document to file.

file can be None to use tran_file. Raise IOError if writing fails. Raise UnicodeError if encoding fails.

Project.set_action_description(register, description)

Set the description of the most recent registered action.

Project.set_duration(index, value, register=-1)

Set the value of duration position.

value can be time, frame or seconds. Use aeidon.as_time(), aeidon.as_frame() or aeidon.as_seconds() if necessary to ensure correct type.

Project.set_end(index, value, register=-1)

Set the value of end position.

value can be time, frame or seconds. Use aeidon.as_time(), aeidon.as_frame() or aeidon.as_seconds() if necessary to ensure correct type.

Project.set_framerate(framerate, register=-1)

Set the value of framerate.

Project.set_main_text(index, value, register=-1)

Set the value of main document’s text.

Project.set_search_regex(pattern, flags=24)

Set the regular expression pattern to find.

Raise re.error if bad pattern.

Project.set_search_replacement(replacement)

Set the replacement string.

Project.set_search_string(pattern, ignore_case=False)

Set the string pattern to find.

Project.set_search_target(indices=None, docs=None, wrap=True)

Set the targets to search in.

indices can be None to target all subtitles. docs can be None to target all documents.

Project.set_start(index, value, register=-1)

Set the value of start position.

value can be time, frame or seconds. Use aeidon.as_time(), aeidon.as_frame() or aeidon.as_seconds() if necessary to ensure correct type.

Project.set_text(index, doc, value, register=-1)

Set the value of doc‘s text.

Project.set_translation_text(index, value, register=-1)

Set the value of translation document’s text.

Project.shift_positions(indices, value, register=-1)

Make subtitles appear earlier or later.

indices can be None to process all subtitles.

Project.spell_check_join_words(indices, doc, language, register=-1)

Join misspelled words based on spell-checker suggestions.

Raise enchant.Error if dictionary instatiation fails.

Project.spell_check_split_words(indices, doc, language, register=-1)

Split misspelled words based on spell-checker suggestions.

Using this is usually not a good idea unless you have an insane dictionary that contains all possible compound words in language. Raise enchant.Error if dictionary instatiation fails.

Project.split_subtitle(index, register=-1)

Split subtitle in two equal duration ones.

Project.toggle_dialogue_dashes(indices, doc, register=-1)

Show or hide dialogue dashes on texts.

Project.toggle_italicization(indices, doc, register=-1)

Add or remove italic markup surrounding texts.

Project.transform_positions(indices, p1, p2, register=-1)

Change positions by a linear two-point correction.

indices can be None to process all subtitles. p1 and p2 should be tuples of index, position.

Project.undo(count=1)

Undo count amount of actions from the undoable stack.

Project.unitalicize(indices, doc, register=-1)

Remove any italic markup surrounding texts.