Sync checker

This commit is contained in:
Vitiko 2023-11-19 03:11:17 -04:00
parent bc0b101fd7
commit 0f4e5e0a7a
2 changed files with 48 additions and 12 deletions

View file

@ -290,6 +290,9 @@ validators = [
Validator('subsync.subsync_movie_threshold', must_exist=True, default=70, is_type_of=int, gte=0, lte=100), Validator('subsync.subsync_movie_threshold', must_exist=True, default=70, is_type_of=int, gte=0, lte=100),
Validator('subsync.debug', must_exist=True, default=False, is_type_of=bool), Validator('subsync.debug', must_exist=True, default=False, is_type_of=bool),
Validator('subsync.force_audio', must_exist=True, default=False, is_type_of=bool), Validator('subsync.force_audio', must_exist=True, default=False, is_type_of=bool),
Validator('subsync.checker', must_exist=True, default={}, is_type_of=dict),
Validator('subsync.checker.blacklisted_providers', must_exist=True, default=[], is_type_of=list),
Validator('subsync.checker.blacklisted_languages', must_exist=True, default=[], is_type_of=list),
# series_scores section # series_scores section
Validator('series_scores.hash', must_exist=True, default=359, is_type_of=int), Validator('series_scores.hash', must_exist=True, default=359, is_type_of=int),
@ -774,3 +777,31 @@ def configure_proxy_func():
def get_scores(): def get_scores():
settings = get_settings() settings = get_settings()
return {"movie": settings["movie_scores"], "episode": settings["series_scores"]} return {"movie": settings["movie_scores"], "episode": settings["series_scores"]}
def sync_checker(subtitle):
" This function can be extended with settings. It only takes a Subtitle argument"
logging.debug("Checker data [%s] for %s", settings.subsync.checker, subtitle)
bl_providers = settings.subsync.checker.blacklisted_providers
# TODO
# bl_languages = settings.subsync.checker.blacklisted_languages
verdicts = set()
# You can add more inner checkers. The following is a verfy basic one for providers,
# but you can make your own functions, etc to handle more complex stuff. You have
# subtitle data to compare.
verdicts.add(subtitle.provider_name not in bl_providers)
met = False not in verdicts
if met is True:
logging.debug("BAZARR Sync checker passed.")
return True
else:
logging.debug("BAZARR Sync checker not passed. Won't sync.")
return False

View file

@ -3,7 +3,7 @@
import logging import logging
from app.config import settings from app.config import settings, sync_checker as _defaul_sync_checker
from utilities.path_mappings import path_mappings from utilities.path_mappings import path_mappings
from utilities.post_processing import pp_replace, set_chmod from utilities.post_processing import pp_replace, set_chmod
from languages.get_languages import alpha2_from_alpha3, alpha2_from_language, alpha3_from_language, language_from_alpha3 from languages.get_languages import alpha2_from_alpha3, alpha2_from_language, alpha3_from_language, language_from_alpha3
@ -69,6 +69,9 @@ def process_subtitle(subtitle, media_type, audio_language, path, max_score, is_u
message = (f"{downloaded_language}{modifier_string} subtitles {action} from {downloaded_provider} with a score of " message = (f"{downloaded_language}{modifier_string} subtitles {action} from {downloaded_provider} with a score of "
f"{percent_score}%.") f"{percent_score}%.")
sync_checker = _defaul_sync_checker
logging.debug("Sync checker: %s", sync_checker)
if media_type == 'series': if media_type == 'series':
episode_metadata = database.execute( episode_metadata = database.execute(
select(TableEpisodes.sonarrSeriesId, TableEpisodes.sonarrEpisodeId) select(TableEpisodes.sonarrSeriesId, TableEpisodes.sonarrEpisodeId)
@ -80,6 +83,7 @@ def process_subtitle(subtitle, media_type, audio_language, path, max_score, is_u
episode_id = episode_metadata.sonarrEpisodeId episode_id = episode_metadata.sonarrEpisodeId
from .sync import sync_subtitles from .sync import sync_subtitles
if sync_checker(subtitle) is True:
sync_subtitles(video_path=path, srt_path=downloaded_path, sync_subtitles(video_path=path, srt_path=downloaded_path,
forced=subtitle.language.forced, forced=subtitle.language.forced,
srt_lang=downloaded_language_code2, media_type=media_type, srt_lang=downloaded_language_code2, media_type=media_type,
@ -97,6 +101,7 @@ def process_subtitle(subtitle, media_type, audio_language, path, max_score, is_u
episode_id = movie_metadata.radarrId episode_id = movie_metadata.radarrId
from .sync import sync_subtitles from .sync import sync_subtitles
if sync_checker(subtitle) is True:
sync_subtitles(video_path=path, srt_path=downloaded_path, sync_subtitles(video_path=path, srt_path=downloaded_path,
forced=subtitle.language.forced, forced=subtitle.language.forced,
srt_lang=downloaded_language_code2, media_type=media_type, srt_lang=downloaded_language_code2, media_type=media_type,