aboutsummaryrefslogtreecommitdiffhomepage
path: root/libs
diff options
context:
space:
mode:
Diffstat (limited to 'libs')
-rw-r--r--libs/ffsubsync/__init__.py18
-rw-r--r--libs/ffsubsync/subtitle_parser.py7
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