diff options
author | Louis Vézina <[email protected]> | 2020-06-12 21:57:52 -0400 |
---|---|---|
committer | Louis Vézina <[email protected]> | 2020-06-12 21:57:52 -0400 |
commit | a459b2d32e52cda09c6c104afda186045c04f8c2 (patch) | |
tree | 71c6a45730ad0ef57cc714b3c12d20733d1ba5fe /libs/ffsubsync | |
parent | 9c9cbe8f192612490bdbb3986754d27e64f4276b (diff) | |
download | bazarr-a459b2d32e52cda09c6c104afda186045c04f8c2.tar.gz bazarr-a459b2d32e52cda09c6c104afda186045c04f8c2.zip |
Added fallback to chardet if cchardet is not available.
Diffstat (limited to 'libs/ffsubsync')
-rw-r--r-- | libs/ffsubsync/__init__.py | 18 | ||||
-rw-r--r-- | libs/ffsubsync/subtitle_parser.py | 7 |
2 files changed, 23 insertions, 2 deletions
diff --git a/libs/ffsubsync/__init__.py b/libs/ffsubsync/__init__.py index 56a39bcc9..3c40aeeba 100644 --- a/libs/ffsubsync/__init__.py +++ b/libs/ffsubsync/__init__.py @@ -1,3 +1,21 @@ # -*- coding: utf-8 -*- +import logging +import sys + +try: + from rich.console import Console + from rich.logging import RichHandler + + # configure logging here because some other later imported library does it first otherwise + # TODO: use a fileconfig + logging.basicConfig( + level=logging.INFO, + format="%(message)s", + datefmt="[%X]", + handlers=[RichHandler(console=Console(file=sys.stderr))] + ) +except ImportError: + logging.basicConfig(stream=sys.stderr, level=logging.INFO) + from .version import __version__ # noqa from .ffsubsync import main # noqa diff --git a/libs/ffsubsync/subtitle_parser.py b/libs/ffsubsync/subtitle_parser.py index 5da184f56..e24b55590 100644 --- a/libs/ffsubsync/subtitle_parser.py +++ b/libs/ffsubsync/subtitle_parser.py @@ -2,7 +2,10 @@ from datetime import timedelta import logging -import chardet +try: + import cchardet +except ImportError: + import chardet as cchardet import pysubs2 from .sklearn_shim import TransformerMixin import srt @@ -79,7 +82,7 @@ class GenericSubtitleParser(SubsMixin, TransformerMixin): with open_file(fname, 'rb') as f: subs = f.read() if self.encoding == 'infer': - encodings_to_try = (chardet.detect(subs)['encoding'],) + encodings_to_try = (cchardet.detect(subs)['encoding'],) self.detected_encoding_ = encodings_to_try[0] logger.info('detected encoding: %s' % self.detected_encoding_) exc = None |