def METHOD_NAME(self, fname: str, *_) -> "GenericSubtitleParser":
    if self.caching and self.fit_fname == ("<stdin>" if fname is None else fname):
        return self
    encodings_to_try = (self.encoding,)
    with open_file(fname, "rb") as f:
        subs = f.read()
    if self.encoding == "infer":
        encodings_to_try = (chardet.detect(subs)["encoding"],)
        self.detected_encoding_ = encodings_to_try[0]
        logger.info("detected encoding: %s" % self.detected_encoding_)
    exc = None
    for encoding in encodings_to_try:
        try:
            decoded_subs = subs.decode(encoding, errors="replace").strip()
            if self.sub_format == "srt":
                parsed_subs = srt.parse(decoded_subs)
            elif self.sub_format in ("ass", "ssa", "sub"):
                parsed_subs = pysubs2.SSAFile.from_string(decoded_subs)
            else:
                raise NotImplementedError(
                    "unsupported format: %s" % self.sub_format
                )
            extra_generic_subtitle_file_kwargs = {}
            if isinstance(parsed_subs, pysubs2.SSAFile):
                extra_generic_subtitle_file_kwargs.update(
                    dict(
                        styles=parsed_subs.styles,
                        # pysubs2 on Python >= 3.6 doesn't support this
                        fonts_opaque=getattr(parsed_subs, "fonts_opaque", None),
                        info=parsed_subs.info if not self._skip_ssa_info else None,
                    )
                )
            self.subs_ = GenericSubtitlesFile(
                _preprocess_subs(
                    parsed_subs,
                    max_subtitle_seconds=self.max_subtitle_seconds,
                    start_seconds=self.start_seconds,
                ),
                sub_format=self.sub_format,
                encoding=encoding,
                **extra_generic_subtitle_file_kwargs,
            )
            self.fit_fname = "<stdin>" if fname is None else fname
            if len(encodings_to_try) > 1:
                self.detected_encoding_ = encoding
                logger.info("detected encoding: %s" % self.detected_encoding_)
            return self
        except Exception as e:
            exc = e
            continue
    raise exc