diff --git a/bazarr/app/signalr_client.py b/bazarr/app/signalr_client.py index b731e09e8..9f930e215 100644 --- a/bazarr/app/signalr_client.py +++ b/bazarr/app/signalr_client.py @@ -12,7 +12,7 @@ from signalrcore.hub_connection_builder import HubConnectionBuilder from collections import deque from time import sleep -from constants import headers +from constants import HEADERS from app.event_handler import event_stream from sonarr.sync.episodes import sync_episodes, sync_one_episode from sonarr.sync.series import update_series, update_one_series @@ -39,7 +39,7 @@ class SonarrSignalrClientLegacy: self.session = Session() self.session.timeout = 60 self.session.verify = False - self.session.headers = headers + self.session.headers = HEADERS self.connection = None self.connected = False @@ -162,7 +162,7 @@ class SonarrSignalrClient: .with_url(f"{url_sonarr()}/signalr/messages?access_token={self.apikey_sonarr}", options={ "verify_ssl": False, - "headers": headers + "headers": HEADERS }) \ .with_automatic_reconnect({ "type": "raw", @@ -229,7 +229,7 @@ class RadarrSignalrClient: .with_url(f"{url_radarr()}/signalr/messages?access_token={self.apikey_radarr}", options={ "verify_ssl": False, - "headers": headers + "headers": HEADERS }) \ .with_automatic_reconnect({ "type": "raw", diff --git a/bazarr/app/ui.py b/bazarr/app/ui.py index 540c26d68..df43f7b0c 100644 --- a/bazarr/app/ui.py +++ b/bazarr/app/ui.py @@ -9,7 +9,7 @@ from flask import (request, abort, render_template, Response, session, send_file from functools import wraps from urllib.parse import unquote -from constants import headers +from constants import HEADERS from literals import FILE_LOG from sonarr.info import url_api_sonarr from radarr.info import url_api_radarr @@ -118,7 +118,7 @@ def series_images(url): baseUrl = settings.sonarr.base_url url_image = f'{url_api_sonarr()}{url.lstrip(baseUrl)}?apikey={apikey}'.replace('poster-250', 'poster-500') try: - req = requests.get(url_image, stream=True, timeout=15, verify=False, headers=headers) + req = requests.get(url_image, stream=True, timeout=15, verify=False, headers=HEADERS) except Exception: return '', 404 else: @@ -132,7 +132,7 @@ def movies_images(url): baseUrl = settings.radarr.base_url url_image = f'{url_api_radarr()}{url.lstrip(baseUrl)}?apikey={apikey}' try: - req = requests.get(url_image, stream=True, timeout=15, verify=False, headers=headers) + req = requests.get(url_image, stream=True, timeout=15, verify=False, headers=HEADERS) except Exception: return '', 404 else: @@ -173,7 +173,7 @@ def proxy(protocol, url): url = f'{protocol}://{unquote(url)}' params = request.args try: - result = requests.get(url, params, allow_redirects=False, verify=False, timeout=5, headers=headers) + result = requests.get(url, params, allow_redirects=False, verify=False, timeout=5, headers=HEADERS) except Exception as e: return dict(status=False, error=repr(e)) else: diff --git a/bazarr/constants.py b/bazarr/constants.py index 4f8af9614..f49c07cc0 100644 --- a/bazarr/constants.py +++ b/bazarr/constants.py @@ -4,10 +4,10 @@ import os import re # set Bazarr user-agent used to make requests -headers = {"User-Agent": os.environ["SZ_USER_AGENT"]} - -# hearing-impaired detection regex -hi_regex = re.compile(r'[*¶♫♪].{3,}[*¶♫♪]|[\[\(\{].{3,}[\]\)\}](? 1 * 1024 * 1024: + if os.path.getsize(subtitle_path) > MAXIMUM_SUBTITLE_SIZE: logging.debug(f"BAZARR subtitles file is too large to be text based. Skipping this file: " f"{subtitle_path}") continue @@ -119,7 +119,7 @@ def guess_external_subtitles(dest_folder, subtitles, media_type, previously_inde # check if file exist: if os.path.exists(subtitle_path) and os.path.splitext(subtitle_path)[1] in core.SUBTITLE_EXTENSIONS: # to improve performance, skip detection of files larger that 1M - if os.path.getsize(subtitle_path) > 1 * 1024 * 1024: + if os.path.getsize(subtitle_path) > MAXIMUM_SUBTITLE_SIZE: logging.debug(f"BAZARR subtitles file is too large to be text based. Skipping this file: " f"{subtitle_path}") continue @@ -136,6 +136,6 @@ def guess_external_subtitles(dest_folder, subtitles, media_type, previously_inde continue text = text.decode(encoding) - if bool(re.search(hi_regex, text)): + if bool(re.search(core.HI_REGEX, text)): subtitles[subtitle] = Language.rebuild(subtitles[subtitle], forced=False, hi=True) return subtitles diff --git a/custom_libs/subliminal_patch/core.py b/custom_libs/subliminal_patch/core.py index db34b6d95..cb21f4581 100644 --- a/custom_libs/subliminal_patch/core.py +++ b/custom_libs/subliminal_patch/core.py @@ -49,6 +49,8 @@ SUBTITLE_EXTENSIONS = ('.srt', '.sub', '.smi', '.txt', '.ssa', '.ass', '.mpl', ' _POOL_LIFETIME = datetime.timedelta(hours=12) +HI_REGEX = re.compile(r'[*¶♫♪].{3,}[*¶♫♪]|[\[\(\{].{3,}[\]\)\}](?