Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _init_filters(self):
"""Initialize file filters."""
file_filter = Gtk.FileFilter()
file_filter.set_name(_("All files"))
file_filter.add_pattern("*")
self.add_filter(file_filter)
file_filter = Gtk.FileFilter()
file_filter.set_name(_("All supported files"))
for format in aeidon.formats:
pattern = "*."
for x in format.extension[1:]:
pattern += "[{}{}]".format(x.upper(), x.lower())
file_filter.add_pattern(pattern)
self.add_filter(file_filter)
self.set_filter(file_filter)
for format in aeidon.formats:
extension = format.extension
pattern = "*."
for x in extension[1:]:
pattern += "[{}{}]".format(x.upper(), x.lower())
format = format.label
name = _("{format} (*{extension})").format(**locals())
file_filter = Gtk.FileFilter()
file_filter.set_name(name)
file_filter.add_pattern(pattern)
Base class for subtitle files.
:cvar format: :attr:`aeidon.formats` item corresponding to file format
:cvar mode: :attr:`aeidon.modes` item corresponding to native positions
:ivar encoding: Character encoding used to read and write file
:ivar has_utf_16_bom: True if BOM found for UTF-16-BE or UTF-16-LE
:ivar header: String of metadata at the top of the file
:ivar newline: :attr:`aeidon.newlines` item, detected upon read
:ivar path: Full, absolute path to the file on disk
If the file format contains a header, it will default to a fairly blank
template header read upon instantiation of the class, from either
``aeidon.DATA_DIR/headers`` or ``aeidon.DATA_HOME_DIR/headers``. If the
read file contains a header, it will replace the template.
"""
format = aeidon.formats.NONE
mode = aeidon.modes.NONE
def __init__(self, path, encoding, newline=None):
"""Initialize a :class:`SubtitleFile` instance."""
self.encoding = encoding
self.has_utf_16_bom = False
self.header = (aeidon.util.get_template_header(self.format)
if self.format.has_header else "")
self.newline = newline or aeidon.util.get_default_newline()
self.path = os.path.abspath(path)
def copy_from(self, other):
"""Copy generic properties from `other`."""
self.has_utf_16_bom = other.has_utf_16_bom
if self.format != other.format: return
"""Text markup for the TMPlayer format."""
import aeidon
__all__ = ("TMPlayer",)
class TMPlayer(aeidon.Markup):
"""
Text markup for the TMPlayer format.
TMPlayer format is assumed to contain no markup.
"""
format = aeidon.formats.TMPLAYER
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
"""TMPlayer file."""
import aeidon
import re
__all__ = ("TMPlayer",)
class TMPlayer(aeidon.SubtitleFile):
"""TMPlayer file."""
format = aeidon.formats.TMPLAYER
mode = aeidon.modes.TIME
_re_one_digit_hour = re.compile(r"^-?\d:\d\d:\d\d:")
_re_two_digit_hour = re.compile(r"^-?\d\d:\d\d:\d\d:")
def __init__(self, path, encoding, newline=None):
"""Initialize an :class:`TMPlayer` instance."""
aeidon.SubtitleFile.__init__(self, path, encoding, newline)
self.two_digit_hour = True
def copy_from(self, other):
"""Copy generic properties from `other` file."""
aeidon.SubtitleFile.copy_from(self, other)
if self.format != other.format: return
self.two_digit_hour = other.two_digit_hour
def read(self):
* ``<b>...................</b>``
* ``<i>...................</i>``
* ``<u>...................</u>``
* ``...``
* ``........``
* ``......``
:class:`Markup` is effectively equivalent to a format with no markup and
can therefore be merely subclassed with a ``pass``-statement by formats
that do not implement any markup. The caller of any tagging methods, e.g.
:meth:`bolden`, must be prepared to handle :exc:`NotImplementedError`.
"""
_flags = re.DOTALL | re.MULTILINE
format = aeidon.formats.NONE
def bolden(self, text, bounds=None):
"""Return bolded `text`."""
raise NotImplementedError
def clean(self, text):
"""
Return `text` with less ugly markup.
Subclasses can implement this to, for example, remove redundant markup,
finetune tag positioning or to join or split tags; in general, whatever
that changes the style of the markup but not that of the text.
"""
return text
def colorize(self, text, color, bounds=None):
"""Text markup for the SubViewer 2.0 format."""
import aeidon
__all__ = ("SubViewer2",)
class SubViewer2(aeidon.markups.SubRip):
"""
Text markup for the SubViewer 2.0 format.
SubViewer 2.0 format is assumed to contain the same markup as SubRip.
"""
format = aeidon.formats.SUBVIEWER2
def get_format(self):
"""Return the selected format."""
index = self._format_combo.get_active()
return aeidon.formats[index]
"""Text markup for the MPsub format."""
import aeidon
__all__ = ("MPsub",)
class MPsub(aeidon.Markup):
"""
Text markup for the MPsub format.
MPsub format is assumed to contain no markup.
"""
format = aeidon.formats.MPSUB
import aeidon
import re
__all__ = ("SubStationAlpha",)
class SubStationAlpha(aeidon.SubtitleFile):
"""
Sub Station Alpha file.
:ivar event_fields: Tuple of field names for the ``[Events]`` section
"""
format = aeidon.formats.SSA
mode = aeidon.modes.TIME
_re_file_time = re.compile(r"^(-?)(.+)$")
_re_separator = re.compile(r",\s*")
_re_subtitle_time = re.compile(r"(-?)\d(.{10})\d")
def __init__(self, path, encoding, newline=None):
"""Initialize a :class:`SubStationAlpha` instance."""
aeidon.SubtitleFile.__init__(self, path, encoding, newline)
self.event_fields = (
"Marked", "Start", "End", "Style", "Name",
"MarginL", "MarginR", "MarginV", "Effect", "Text")
def copy_from(self, other):
"""Copy generic properties from `other` file."""
aeidon.SubtitleFile.copy_from(self, other)
import aeidon
import re
__all__ = ("LRC",)
class LRC(aeidon.SubtitleFile):
"""
LRC file.
https://en.wikipedia.org/wiki/LRC_(file_format)
"""
format = aeidon.formats.LRC
mode = aeidon.modes.TIME
_re_line = re.compile(r"^\[(-?\d\d:\d\d.\d\d)\](.*)$")
def read(self):
"""
Read file and return subtitles.
Raise :exc:`IOError` if reading fails.
Raise :exc:`UnicodeError` if decoding fails.
"""
self.header = ""
subtitles = [self._get_subtitle()]
for line in self._read_lines():
match = self._re_line.match(line)
if match is None and len(subtitles) == 1:
# Read line into file header.