mirror of
https://github.com/morpheus65535/bazarr
synced 2024-12-24 16:52:06 +00:00
Added fallback to chardet if cchardet is not available.
This commit is contained in:
parent
9c9cbe8f19
commit
a459b2d32e
2 changed files with 23 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue