How to use the pysubs2.load function in pysubs2

To help you get started, we’ve selected a few pysubs2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yc9701 / pansori / slice.py View on Github external
vid = None if vids == None else vids[0]

	v_dir = os.path.join(data_path, vid)
	out_dir = os.path.join(v_dir, out_stage)

	try:
		# Get information on the YouTube content
		yt = YouTube(yt_uri)

		# Filename for audio stream (.mp4) and subtitle (.srt) files
		audio = os.path.join(v_dir, vid + ".mp4")
		subtitle = os.path.join(v_dir, vid + ".srt")

		# Retrieving subtitle information
		audio_content = AudioSegment.from_file(audio, format='mp4')
		subtitle_content = pysubs2.load(subtitle)

		punctuation_filter = str.maketrans('', '', string.punctuation)

		os.makedirs(out_dir, exist_ok=True)

		# Writing to file
		for index, event in enumerate(subtitle_content):

			try:
				if event.text.translate(punctuation_filter) == "":
				 	continue
				
				ev_subtitle = os.path.join(out_dir, str(index).zfill(4) + '.txt')
				ev_audio = os.path.join(out_dir, str(index).zfill(4) + '.wav')

				ev_subtitle_file = open(ev_subtitle, 'w')
github morpheus65535 / bazarr / libs / subzero / modification / main.py View on Github external
def load(self, fn=None, content=None, language=None, encoding="utf-8"):
        """
        
        :param encoding: used for decoding the content when fn is given, not used in case content is given
        :param language: babelfish.Language language of the subtitle
        :param fn:  filename
        :param content: unicode 
        :return: 
        """
        if language:
            self.language = Language.rebuild(language, forced=False)
        self.initialized_mods = {}
        try:
            if fn:
                self.f = pysubs2.load(fn, encoding=encoding)
            elif content:
                self.f = pysubs2.SSAFile.from_string(content)
        except (IOError,
                UnicodeDecodeError,
                pysubs2.exceptions.UnknownFPSError,
                pysubs2.exceptions.UnknownFormatIdentifierError,
                pysubs2.exceptions.FormatAutodetectionError):
            if fn:
                logger.exception("Couldn't load subtitle: %s: %s", fn, traceback.format_exc())
            elif content:
                logger.exception("Couldn't load subtitle: %s", traceback.format_exc())

        return bool(self.f)
github Endilll / vapoursynth-preview / vspreview / toolbars / scening.py View on Github external
def import_ass(self, path: Path, scening_list: SceningList, out_of_range_count: int) -> None:
        '''
        Imports lines as scenes.
        Text is ignored.
        '''
        import pysubs2

        subs = pysubs2.load(str(path))
        for line in subs:
            t_start = Time(milliseconds=line.start)
            t_end   = Time(milliseconds=line.end)
            try:
                scening_list.add(Frame(t_start), Frame(t_end))
            except ValueError:
                out_of_range_count += 1
github rr- / dotfiles / cfg / bubblesub / scripts / cc.py View on Github external
async def _run(self, main_window: QtWidgets.QMainWindow) -> None:
        path = load_dialog(
            main_window, "Subtitles (*.ass *.srt);;All files (*.*)"
        )
        if not path:
            return

        source = pysubs2.load(str(path))
        with self.api.undo.capture():
            for line in source:
                self.api.subs.events.append(
                    AssEvent(
                        start=line.start,
                        end=line.end,
                        note=line.text,
                        style=self.api.subs.default_style_name,
                    )
github WeebSearch / worker / worker / ingest / subs.py View on Github external
"""
    Loads subtitles from a relative path as opposed
    to the absolute path that pysubs2 restricts
    the user to
    Args:
        path: relative path of the subtitle location
    Returns:
        pysubs2 subtitle file
    Raises:
        FileNotFoundError - invalid path
    """
    if not is_sub_file(path):
        raise ValueError(f'{path} is not a subtitle file')

    destination = os.path.abspath(str(path))
    return pysubs2.load(destination)