diff --git a/bazarr/analytics.py b/bazarr/analytics.py index 27db704dd..8097c6719 100644 --- a/bazarr/analytics.py +++ b/bazarr/analytics.py @@ -30,6 +30,8 @@ def track_event(category=None, action=None, label=None): try: if settings.analytics.visitor: visitor = pickle.loads(base64.b64decode(settings.analytics.visitor), encoding='utf-8') + if visitor.user_agent is None: + visitor.user_agent = os.environ.get("SZ_USER_AGENT") if visitor.unique_id > int(0x7fffffff): visitor.unique_id = random.randint(0, 0x7fffffff) except: diff --git a/bazarr/list_subtitles.py b/bazarr/list_subtitles.py index 3dedf2f03..5806778a3 100644 --- a/bazarr/list_subtitles.py +++ b/bazarr/list_subtitles.py @@ -14,7 +14,6 @@ from subliminal import core from subliminal_patch import search_external_subtitles from subzero.language import Language from bs4 import UnicodeDammit -from itertools import islice import six from get_args import args @@ -91,10 +90,9 @@ def store_subtitles(original_path, reversed_path): if os.path.splitext(subtitle)[1] != ".sub": logging.debug("BAZARR falling back to file content analysis to detect language.") with open(os.path.join(os.path.dirname(reversed_path), subtitle), 'r') as f: - text = list(islice(f, 100)) - text = ' '.join(text) - encoding = UnicodeDammit(text) + text = f.read() try: + encoding = UnicodeDammit(text) text = text.decode(encoding.original_encoding) detected_language = langdetect.detect(text) except Exception as e: @@ -183,10 +181,9 @@ def store_subtitles_movie(original_path, reversed_path): if os.path.splitext(subtitle)[1] != ".sub": logging.debug("BAZARR falling back to file content analysis to detect language.") with open(os.path.join(os.path.dirname(reversed_path), dest_folder, subtitle), 'r') as f: - text = list(islice(f, 100)) - text = ' '.join(text) - encoding = UnicodeDammit(text) + text = f.read() try: + encoding = UnicodeDammit(text) text = text.decode(encoding.original_encoding) detected_language = langdetect.detect(text) except Exception as e: @@ -403,7 +400,7 @@ def guess_external_subtitles(dest_folder, subtitles): logging.debug("BAZARR falling back to file content analysis to detect language.") detected_language = None with open(subtitle_path, 'r') as f: - text = ' '.join(list(islice(f, 100))) + text = f.read() try: encoding = UnicodeDammit(text) text = text.decode(encoding.original_encoding)