1
0
Fork 0
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:
Louis Vézina 2020-06-12 21:57:52 -04:00
parent 9c9cbe8f19
commit a459b2d32e
2 changed files with 23 additions and 2 deletions

View file

@ -1,3 +1,21 @@
# -*- coding: utf-8 -*- # -*- 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 .version import __version__ # noqa
from .ffsubsync import main # noqa from .ffsubsync import main # noqa

View file

@ -2,7 +2,10 @@
from datetime import timedelta from datetime import timedelta
import logging import logging
import chardet try:
import cchardet
except ImportError:
import chardet as cchardet
import pysubs2 import pysubs2
from .sklearn_shim import TransformerMixin from .sklearn_shim import TransformerMixin
import srt import srt
@ -79,7 +82,7 @@ class GenericSubtitleParser(SubsMixin, TransformerMixin):
with open_file(fname, 'rb') as f: with open_file(fname, 'rb') as f:
subs = f.read() subs = f.read()
if self.encoding == 'infer': 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] self.detected_encoding_ = encodings_to_try[0]
logger.info('detected encoding: %s' % self.detected_encoding_) logger.info('detected encoding: %s' % self.detected_encoding_)
exc = None exc = None