feat(ffmpeg_handling): dictonary expansion, change russ search function
generate search function from translation keys dont require perfect match for translation expand vocabulary
This commit is contained in:
1 parent
4b4b0fcb5f
commit
22522549b5
1 file changed
+82
-85
@@ -49,26 +49,41 @@ commands = {
|
||||
}
|
||||
# ------ Russian Dictonary --------------#
|
||||
AUDIO_TRANSLATIONS = {
|
||||
# Additional descriptors
|
||||
# Voice-over / dubbing
|
||||
"Закадровый": "Voice-over",
|
||||
"Закадровое озвучивание": "Voice-over",
|
||||
"Многоголосый закадровый": "Multi-voice voice-over",
|
||||
"Многоголосное закадровое озвучивание": "Multi-voice voice-over",
|
||||
# Variants found in metadata
|
||||
"Оригинален език": "Original language",
|
||||
"Многоголосное озвучивание": "Multi-voice dub",
|
||||
"Многоголосый": "Multi-voice",
|
||||
"Любительский": "Amateur voice-over",
|
||||
"многоголосый": "Multi-voice",
|
||||
"Профессиональный": "Professional",
|
||||
"Одноголосый": "Single voice",
|
||||
"Двухголосый": "Dual voice",
|
||||
"Авторский": "Author voice-over",
|
||||
"закадровый": "Voice-over",
|
||||
"Многоголосый закадровый": "Voice-over",
|
||||
"Многоголосное закадровое озвучивание": "Voice-over",
|
||||
"Многоголосное озвучивание": "Voice-over",
|
||||
"Многоголосый": "Voice-over",
|
||||
"Одноголосый": "Voice-over",
|
||||
"Двухголосый": "Voice-over",
|
||||
"Авторский": "Voice-over",
|
||||
"Любительский": "Voice-over",
|
||||
"Профессиональный": "Professional",
|
||||
"Оригинал": "Original",
|
||||
"Дубляж": "Dubbed",
|
||||
# Russian groups
|
||||
# Languages
|
||||
r"русск": "Russian",
|
||||
"Английски": "English",
|
||||
"български": "Bulgarian",
|
||||
"Български": "Bulgarian",
|
||||
"Українська": "Ukrainian",
|
||||
"українська": "Ukrainian",
|
||||
"Македонски": "Macedonian",
|
||||
"Српски": "Serbian",
|
||||
"Немецкая": "German",
|
||||
"Немецкое": "German",
|
||||
"немецкие": "German",
|
||||
"Английская": "English",
|
||||
"Английское": "English",
|
||||
"Французская": "French",
|
||||
"Французское": "French",
|
||||
# Studios / groups
|
||||
"Кубик в кубе": "Kubik v Kube",
|
||||
"Синема УС": "Cinema US",
|
||||
"Озвучка Rumble": "Rumble",
|
||||
"LostFilm": "LostFilm",
|
||||
"AlexFilm": "AlexFilm",
|
||||
"Baibako": "Baibako",
|
||||
@@ -77,60 +92,42 @@ AUDIO_TRANSLATIONS = {
|
||||
"Kerob": "Kerob",
|
||||
"TVShows": "TVShows",
|
||||
"HDRezka": "HDRezka",
|
||||
# Groups / studios
|
||||
"Синема УС": "Cinema US",
|
||||
"KinoPub": "KinoPub",
|
||||
"Озвучка Rumble": "Rumble",
|
||||
"Rumble": "Rumble",
|
||||
# Voice actor
|
||||
"супербит": "Superbit",
|
||||
"Видеосервис": "Videoservice",
|
||||
"Семён Гальцев": "Semyon Galtsev",
|
||||
# Voice actors
|
||||
"Юрий Сербин": "Yuriy Serbin",
|
||||
"Ю. Сербин": "Y. Serbin",
|
||||
# Languages
|
||||
"Английски": "English",
|
||||
"Русский": "Russian",
|
||||
"Русская": "Russian",
|
||||
"Русское": "Russian",
|
||||
# ISO codes
|
||||
"П.Либергал": "P. Libergal",
|
||||
"Визгунов": "Vizgunov",
|
||||
# Misc
|
||||
# Subtitles
|
||||
"субтитры": "Russian Subtitles",
|
||||
"Оригинален език": "Original language",
|
||||
# ISO
|
||||
"rus": "Russian",
|
||||
"ru": "Russian",
|
||||
"ger": "German",
|
||||
"deu": "German",
|
||||
"eng": "English",
|
||||
"und": "Unknown",
|
||||
}
|
||||
IGNORE_WORDS = {
|
||||
"English",
|
||||
"German",
|
||||
"French",
|
||||
}
|
||||
|
||||
RUSSIAN_RE = re.compile(
|
||||
r"\brus\b|"
|
||||
r"\bru\b|"
|
||||
r"russian|"
|
||||
r"рус|"
|
||||
r"русский|"
|
||||
r"русская|"
|
||||
r"русское|"
|
||||
r"дубляж|"
|
||||
r"оригинал|"
|
||||
r"многоголос|"
|
||||
r"двухголос|"
|
||||
r"одноголос|"
|
||||
r"авторский|"
|
||||
r"любительский|"
|
||||
r"профессиональн|"
|
||||
r"закадров|"
|
||||
r"юрий\s+сербин|"
|
||||
r"ю\.\s*сербин|"
|
||||
r"сербин|"
|
||||
r"синема\s+ус|"
|
||||
r"kinopub|"
|
||||
r"rumble|"
|
||||
r"озвучка\s+rumble|"
|
||||
r"кубик\s+в\s+кубе|"
|
||||
r"lostfilm|"
|
||||
r"alexfilm|"
|
||||
r"baibako|"
|
||||
r"newstudio|"
|
||||
r"jaskier|"
|
||||
r"kerob|"
|
||||
r"tvshows|"
|
||||
r"hdrezka",
|
||||
"|".join(
|
||||
sorted(
|
||||
(
|
||||
re.escape(key)
|
||||
for key in AUDIO_TRANSLATIONS
|
||||
if AUDIO_TRANSLATIONS[key] not in IGNORE_WORDS
|
||||
),
|
||||
key=len,
|
||||
reverse=True,
|
||||
)
|
||||
),
|
||||
re.IGNORECASE,
|
||||
)
|
||||
|
||||
@@ -175,18 +172,13 @@ def translate_audio_tracks(tracks: list[dict]) -> list[dict]:
|
||||
for key, value in new_track.items():
|
||||
if not isinstance(value, str):
|
||||
continue
|
||||
|
||||
for src, dst in AUDIO_TRANSLATIONS.items():
|
||||
value = re.sub(
|
||||
rf"\b{re.escape(src)}\b",
|
||||
dst,
|
||||
value,
|
||||
flags=re.IGNORECASE,
|
||||
)
|
||||
|
||||
if re.search(rf"\b{re.escape(src)}\b", value, flags=re.IGNORECASE):
|
||||
value = dst
|
||||
break
|
||||
if CYRILLIC_RE.search(value):
|
||||
raise ValueError(
|
||||
f"Contains unidentified Cyrillic characters in {key}: {value}"
|
||||
f"Track contains unidentified Cyrillic characters in {key}: {value}"
|
||||
)
|
||||
|
||||
new_track[key] = value
|
||||
@@ -520,7 +512,10 @@ def cmd_convert_video(args):
|
||||
)
|
||||
return True, out
|
||||
|
||||
|
||||
from collections.abc import Callable
|
||||
|
||||
|
||||
def remove_streams(
|
||||
args,
|
||||
remove_indices: set[int] | list[int],
|
||||
@@ -533,8 +528,7 @@ def remove_streams(
|
||||
remaining_audio = [
|
||||
s
|
||||
for s in probe["streams"]
|
||||
if s["codec_type"] == "audio"
|
||||
and s["index"] not in remove_indices
|
||||
if s["codec_type"] == "audio" and s["index"] not in remove_indices
|
||||
]
|
||||
|
||||
if not remaining_audio:
|
||||
@@ -618,14 +612,13 @@ def remove_streams(
|
||||
logger.error("STDERR:\n%s", e.stderr)
|
||||
raise
|
||||
|
||||
|
||||
def cmd_remove_subs(args):
|
||||
probe = ffmpeg.probe(str(args.input))
|
||||
|
||||
if args.num is None:
|
||||
remove_indices = {
|
||||
s["index"]
|
||||
for s in probe["streams"]
|
||||
if s["codec_type"] == "subtitle"
|
||||
s["index"] for s in probe["streams"] if s["codec_type"] == "subtitle"
|
||||
}
|
||||
else:
|
||||
remove_indices = set(args.num)
|
||||
@@ -635,10 +628,10 @@ def cmd_remove_subs(args):
|
||||
remove_indices=remove_indices,
|
||||
)
|
||||
|
||||
|
||||
def cmd_remove_audio_track(args):
|
||||
remove_indices = {
|
||||
select_audio_stream(args.input, audio_index)
|
||||
for audio_index in args.audio_index
|
||||
select_audio_stream(args.input, audio_index) for audio_index in args.audio_index
|
||||
}
|
||||
|
||||
return remove_streams(
|
||||
@@ -646,6 +639,8 @@ def cmd_remove_audio_track(args):
|
||||
remove_indices=remove_indices,
|
||||
output_subtitle_codec=True,
|
||||
)
|
||||
|
||||
|
||||
def cmd_extract_audio_track(args):
|
||||
"""
|
||||
1. Saves that specific audio track as a standalone MP3 (Extra Output).
|
||||
@@ -929,6 +924,7 @@ def cmd_set_primary_audio(args):
|
||||
|
||||
return True, out
|
||||
|
||||
|
||||
def cmd_show_metadata(args, show_metadata=False, return_tags=None):
|
||||
probe = ffmpeg.probe(str(args.input))
|
||||
format_tags = probe.get("format", {}).get("tags", {})
|
||||
@@ -942,7 +938,6 @@ def cmd_show_metadata(args, show_metadata=False, return_tags=None):
|
||||
for k, v in format_tags.items():
|
||||
logger.info(f"{k}: {v}")
|
||||
|
||||
|
||||
# logger.info(f"\n=== STREAM METADATA ===")
|
||||
# for i, stream in enumerate(probe.get("streams", [])):
|
||||
# logger.info(f"\n--- Stream {i} ({stream.get('codec_type')}) ---")
|
||||
@@ -1113,8 +1108,8 @@ def cmd_remove_russian_from_db(args):
|
||||
try:
|
||||
audio_tracks = translate_audio_tracks(get_audio_tracks(file))
|
||||
subtitle_tracks = translate_audio_tracks(get_subtitle_tracks(file))
|
||||
except ValueError as e:
|
||||
logger.warning("%s", e)
|
||||
except ValueError as error_msg:
|
||||
logger.warning(f"File {file.name} {error_msg}")
|
||||
return False, "nooutputneeded"
|
||||
|
||||
logger.trace("Remove Russian from File: %s", file.name)
|
||||
@@ -1147,7 +1142,7 @@ def cmd_remove_russian_from_db(args):
|
||||
return remove_streams(
|
||||
args=args,
|
||||
remove_indices=remove_indices,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def cmd_test(args):
|
||||
@@ -1179,7 +1174,7 @@ def cmd_test(args):
|
||||
_test_dict = []
|
||||
logger.info(f"TEST: {name}")
|
||||
# Run FFmpeg for this single command only
|
||||
return_value ,outputs = cmd_func(args_probe)
|
||||
return_value, outputs = cmd_func(args_probe)
|
||||
if not outputs:
|
||||
logger.error("No outputs returned.")
|
||||
return False
|
||||
@@ -1290,7 +1285,7 @@ def cmd_test(args):
|
||||
args = ArgsBuffer()
|
||||
args.input = file_path
|
||||
tags = {}
|
||||
cmd_show_metadata(args,return_tags=tags)
|
||||
cmd_show_metadata(args, return_tags=tags)
|
||||
|
||||
return_value = True
|
||||
|
||||
@@ -1408,9 +1403,11 @@ def cmd_test(args):
|
||||
subtitle_tracks = translate_audio_tracks(get_audio_tracks(file_path))
|
||||
logger.debug(f"Subtitle tracks: {subtitle_tracks}")
|
||||
for subtitle_track in subtitle_tracks:
|
||||
if is_russian_track(subtitle_track):
|
||||
logger.error(f"Found russian track: {subtitle_track} in file {file_path}")
|
||||
return return_value and False
|
||||
if is_russian_track(subtitle_track):
|
||||
logger.error(
|
||||
f"Found russian track: {subtitle_track} in file {file_path}"
|
||||
)
|
||||
return return_value and False
|
||||
|
||||
logger.info(f"{green_tag('PASS')} {file_path}")
|
||||
return return_value
|
||||
|
||||
Reference in new issue
Block a user