subaligner.subtitle module¶
-
class
subaligner.subtitle.
Subtitle
(secret: object, subtitle_file_path: str, subtitle_format: str)[source]¶ Bases:
object
Load a subtitle file into internal data structure
-
ADVANCED_SSA_EXTENTIONS
= ['.ass']¶
-
MICRODVD_EXTENSIONS
= ['.sub']¶
-
MPL2_EXTENSIONS
= ['.txt']¶
-
SAMI_EXTENSIONS
= ['.smi', '.sami']¶
-
SBV_EXTENSIONS
= ['.sbv']¶
-
SCC_EXTENSIONS
= ['.scc']¶
-
SSA_EXTENTIONS
= ['.ssa']¶
-
STL_EXTENSIONS
= ['.stl']¶
-
SUBRIP_EXTENTIONS
= ['.srt']¶
-
TMP_EXTENSIONS
= ['.tmp']¶
-
TTML_EXTENSIONS
= ['.xml', '.ttml', '.dfxp']¶
-
TT_NS
= {'tt': 'http://www.w3.org/ns/ttml'}¶
-
WEBVTT_EXTENSIONS
= ['.vtt']¶
-
YT_TRANSCRIPT_EXTENSIONS
= ['.ytt']¶
-
static
export_subtitle
(source_file_path: str, subs: List[pysrt.SubRipItem], target_file_path: str, frame_rate: float = 25.0, encoding: Optional[str, None] = None) → None[source]¶ Export subtitle in the format determined by the file extension.
- Parameters
{string} -- The path to the original subtitle file. (source_file_path) –
{list} -- A list of SubRipItems. (subs) –
{string} -- The path to the exported subtitle file. (target_file_path) –
{float} -- The frame rate for frame-based subtitle formats {default (frame_rate) – 25.0}.
{str} -- The encoding of the exported subtitle file {default (encoding) – None}.
-
static
extract_text
(subtitle_file_path: str, delimiter: str = ' ') → str[source]¶ Extract plain texts from a subtitle file.
- Parameters
{string} -- The path to the subtitle file. (subtitle_file_path) –
- Returns
{string} – The plain text of subtitle.
-
classmethod
load
(subtitle_file_path: str) → subaligner.subtitle.Subtitle[source]¶ Load a SubRip or TTML subtitle file based on the file extension.
- Parameters
{string} -- The path to the subtitle file. (subtitle_file_path) –
- Returns
Subtitle – Subtitle object.
-
classmethod
load_ass
(subtitle_file_path: str) → subaligner.subtitle.Subtitle[source]¶ Load a Advanced SubStation Alpha v4.0+ subtitle file.
- Parameters
{string} -- The path to the subtitle file. (subtitle_file_path) –
- Returns
Subtitle – Subtitle object.
-
classmethod
load_microdvd
(subtitle_file_path: str) → subaligner.subtitle.Subtitle[source]¶ Load a MicroDVD subtitle file.
- Parameters
{string} -- The path to the subtitle file. (subtitle_file_path) –
- Returns
Subtitle – Subtitle object.
-
classmethod
load_mpl2
(subtitle_file_path: str) → subaligner.subtitle.Subtitle[source]¶ Load a MPL2 subtitle file.
- Parameters
{string} -- The path to the subtitle file. (subtitle_file_path) –
- Returns
Subtitle – Subtitle object.
-
classmethod
load_sami
(subtitle_file_path: str) → subaligner.subtitle.Subtitle[source]¶ Load a SAMI subtitle file.
- Parameters
{string} -- The path to the subtitle file. (subtitle_file_path) –
- Returns
Subtitle – Subtitle object.
-
classmethod
load_sbv
(subtitle_file_path: str) → subaligner.subtitle.Subtitle[source]¶ Load a SubViewer subtitle file.
- Parameters
{string} -- The path to the subtitle file. (subtitle_file_path) –
- Returns
Subtitle – Subtitle object.
-
classmethod
load_scc
(subtitle_file_path: str) → subaligner.subtitle.Subtitle[source]¶ Load a Scenarist Closed Caption subtitle file.
- Parameters
{string} -- The path to the subtitle file. (subtitle_file_path) –
- Returns
Subtitle – Subtitle object.
-
classmethod
load_ssa
(subtitle_file_path: str) → subaligner.subtitle.Subtitle[source]¶ Load a SubStation Alpha v4.0 subtitle file.
- Parameters
{string} -- The path to the subtitle file. (subtitle_file_path) –
- Returns
Subtitle – Subtitle object.
-
classmethod
load_stl
(subtitle_file_path: str) → subaligner.subtitle.Subtitle[source]¶ Load an EBU STL subtitle file.
- Parameters
{string} -- The path to the subtitle file. (subtitle_file_path) –
- Returns
Subtitle – Subtitle object.
-
classmethod
load_subrip
(subtitle_file_path: str) → subaligner.subtitle.Subtitle[source]¶ Load a SubRip subtitle file.
- Parameters
{string} -- The path to the subtitle file. (subtitle_file_path) –
- Returns
Subtitle – Subtitle object.
-
classmethod
load_subrip_str
(subrip_raw: str) → subaligner.subtitle.Subtitle[source]¶ Load a SubRip subtitle string.
- Parameters
{string} -- The string representation of the SubRip content. (subrip_str) –
- Returns
Subtitle – Subtitle object.
-
classmethod
load_tmp
(subtitle_file_path: str) → subaligner.subtitle.Subtitle[source]¶ Load a TMP subtitle file.
- Parameters
{string} -- The path to the subtitle file. (subtitle_file_path) –
- Returns
Subtitle – Subtitle object.
-
classmethod
load_ttml
(subtitle_file_path: str) → subaligner.subtitle.Subtitle[source]¶ Load a TTML subtitle file.
- Parameters
{string} -- The path to the subtitle file. (subtitle_file_path) –
- Returns
Subtitle – Subtitle object.
-
classmethod
load_webvtt
(subtitle_file_path: str) → subaligner.subtitle.Subtitle[source]¶ Load a WebVTT subtitle file.
- Parameters
{string} -- The path to the subtitle file. (subtitle_file_path) –
- Returns
Subtitle – Subtitle object.
-
classmethod
load_ytt
(subtitle_file_path: str) → subaligner.subtitle.Subtitle[source]¶ Load a YouTube transcript subtitle file.
- Parameters
{string} -- The path to the subtitle file. (subtitle_file_path) –
- Returns
Subtitle – Subtitle object.
-
static
remove_sound_effects_by_affixes
(subs: List[pysrt.SubRipItem], se_prefix: str, se_suffix: Optional[str, None] = None) → List[pysrt.SubRipItem][source]¶ Remove subtitles of sound effects based on prefix or prefix and suffix
- Parameters
{list} -- A list of SubRipItems. (subs) –
{string} -- A prefix indicating the start of the sound effect. (se_prefix) –
{string} -- A suffix indicating the end of the sound effect (default (se_suffix) – {None}).
- Returns
{list} – A list of SubRipItems.
-
static
remove_sound_effects_by_case
(subs: List[pysrt.SubRipItem], se_uppercase: bool = True) → List[pysrt.SubRipItem][source]¶ Remove subtitles of sound effects based on case
- Parameters
{list} -- A list of SubRipItems. (subs) –
{bool} -- True when the sound effect is in uppercase or False when in lowercase (default (se_uppercase) – {True}).
- Returns
{list} – A list of SubRipItems.
-
static
save_subs_as_target_format
(subs: List[pysrt.SubRipItem], source_file_path: str, target_file_path: str, frame_rate: Optional[float, None] = None, encoding: Optional[str, None] = None) → None[source]¶ Save SubRipItems with the format determined by the target file extension.
- Parameters
{list} -- A list of SubRipItems. (subs) –
{string} -- The path to the original subtitle file. (source_file_path) –
{string} -- The path to the output subtitle file. (target_file_path) –
{float} -- The frame rate used by conversion to formats such as MicroDVD (frame_rate) –
{str} -- The encoding of the exported output file {default (encoding) – None}.
-
classmethod
shift_subtitle
(subtitle_file_path: str, seconds: float, shifted_subtitle_file_path: Optional[str, None] = None, suffix: str = '_shifted') → Optional[str, None][source]¶ Shift subtitle cues based on the input seconds.
- Parameters
{string} -- The path to the subtitle file. (subtitle_file_path) –
{float} -- The number of seconds by which the cues are shifted. (seconds) –
- Keyword Arguments
{string} -- The path to the shifted subtitle file (default (shifted_subtitle_file_path) – {None}).
{string} -- The suffix used as part of the aligned subtitle file name. (suffix) –
- Returns
string – The path to the shifted subtitle file.
-
property
subs
¶
-
static
subtitle_extensions
() → set[source]¶ Get the file extensions of the supported subtitles.
- Returns
{set} – The subtitle extensions.
-
property
subtitle_file_path
¶
-