Added settings to exclude subtitles from specific provider to be synced

pull/2342/head
Vitiko 12 months ago committed by GitHub
parent 3b2d734301
commit c4f103e39b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -293,6 +293,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),
@ -402,7 +405,9 @@ array_keys = ['excluded_tags',
'enabled_providers', 'enabled_providers',
'path_mappings', 'path_mappings',
'path_mappings_movie', 'path_mappings_movie',
'language_equals'] 'language_equals',
'blacklisted_languages',
'blacklisted_providers']
empty_values = ['', 'None', 'null', 'undefined', None, []] empty_values = ['', 'None', 'null', 'undefined', None, []]
@ -628,7 +633,10 @@ def save_settings(settings_items):
reset_throttled_providers(only_auth_or_conf_error=True) reset_throttled_providers(only_auth_or_conf_error=True)
if settings_keys[0] == 'settings': if settings_keys[0] == 'settings':
settings[settings_keys[1]][settings_keys[2]] = value if len(settings_keys) == 3:
settings[settings_keys[1]][settings_keys[2]] = value
elif len(settings_keys) == 4:
settings[settings_keys[1]][settings_keys[2]][settings_keys[3]] = value
if settings_keys[0] == 'subzero': if settings_keys[0] == 'subzero':
mod = settings_keys[1] mod = settings_keys[1]
@ -775,3 +783,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

@ -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)
@ -79,13 +82,14 @@ def process_subtitle(subtitle, media_type, audio_language, path, max_score, is_u
series_id = episode_metadata.sonarrSeriesId series_id = episode_metadata.sonarrSeriesId
episode_id = episode_metadata.sonarrEpisodeId episode_id = episode_metadata.sonarrEpisodeId
from .sync import sync_subtitles if sync_checker(subtitle) is True:
sync_subtitles(video_path=path, srt_path=downloaded_path, from .sync import sync_subtitles
forced=subtitle.language.forced, sync_subtitles(video_path=path, srt_path=downloaded_path,
srt_lang=downloaded_language_code2, media_type=media_type, forced=subtitle.language.forced,
percent_score=percent_score, srt_lang=downloaded_language_code2, media_type=media_type,
sonarr_series_id=episode_metadata.sonarrSeriesId, percent_score=percent_score,
sonarr_episode_id=episode_metadata.sonarrEpisodeId) sonarr_series_id=episode_metadata.sonarrSeriesId,
sonarr_episode_id=episode_metadata.sonarrEpisodeId)
else: else:
movie_metadata = database.execute( movie_metadata = database.execute(
select(TableMovies.radarrId) select(TableMovies.radarrId)
@ -96,12 +100,13 @@ def process_subtitle(subtitle, media_type, audio_language, path, max_score, is_u
series_id = "" series_id = ""
episode_id = movie_metadata.radarrId episode_id = movie_metadata.radarrId
from .sync import sync_subtitles if sync_checker(subtitle) is True:
sync_subtitles(video_path=path, srt_path=downloaded_path, from .sync import sync_subtitles
forced=subtitle.language.forced, sync_subtitles(video_path=path, srt_path=downloaded_path,
srt_lang=downloaded_language_code2, media_type=media_type, forced=subtitle.language.forced,
percent_score=percent_score, srt_lang=downloaded_language_code2, media_type=media_type,
radarr_id=movie_metadata.radarrId) percent_score=percent_score,
radarr_id=movie_metadata.radarrId)
if use_postprocessing is True: if use_postprocessing is True:
command = pp_replace(postprocessing_cmd, path, downloaded_path, downloaded_language, downloaded_language_code2, command = pp_replace(postprocessing_cmd, path, downloaded_path, downloaded_language, downloaded_language_code2,

@ -5,6 +5,7 @@ import {
CollapseBox, CollapseBox,
Layout, Layout,
Message, Message,
MultiSelector,
Password, Password,
Section, Section,
Selector, Selector,
@ -23,6 +24,7 @@ import {
embeddedSubtitlesParserOption, embeddedSubtitlesParserOption,
folderOptions, folderOptions,
hiExtensionOptions, hiExtensionOptions,
providerOptions,
} from "./options"; } from "./options";
interface CommandOption { interface CommandOption {
@ -405,6 +407,13 @@ const SettingsSubtitlesView: FunctionComponent = () => {
subtitles. subtitles.
</Message> </Message>
<CollapseBox indent settingKey="settings-subsync-use_subsync"> <CollapseBox indent settingKey="settings-subsync-use_subsync">
<MultiSelector
placeholder="Select providers..."
label="Do not sync subtitles downloaded from those providers"
clearable
options={providerOptions}
settingKey="settings-subsync-checker-blacklisted_providers"
></MultiSelector>
<Check label="Debug" settingKey="settings-subsync-debug"></Check> <Check label="Debug" settingKey="settings-subsync-debug"></Check>
<Message> <Message>
Do not actually sync the subtitles but generate a .tar.gz file to be Do not actually sync the subtitles but generate a .tar.gz file to be

@ -1,4 +1,5 @@
import { SelectorOption } from "@/components"; import { SelectorOption } from "@/components";
import { ProviderList } from "../Providers/list";
export const hiExtensionOptions: SelectorOption<string>[] = [ export const hiExtensionOptions: SelectorOption<string>[] = [
{ {
@ -165,3 +166,10 @@ export const colorOptions: SelectorOption<string>[] = [
value: buildColor("dark-grey"), value: buildColor("dark-grey"),
}, },
]; ];
export const providerOptions: SelectorOption<string>[] = ProviderList.map(
(v) => ({
label: v.key,
value: v.key,
})
);

Loading…
Cancel
Save