ffmpeg handling remove russian subs
remove subtitle removal for russian media
This commit is contained in:
1 parent
7fbda6b133
commit
b3e9bae3eb
2 files changed
+23
-22
No files matched your search
@@ -17,6 +17,8 @@ uv.lock
|
||||
youtubelist.txt
|
||||
*.mkv
|
||||
*.mp4
|
||||
*.m4b
|
||||
|
||||
.spotdl-cache
|
||||
script_template.txt
|
||||
|
||||
@@ -115,6 +115,8 @@ class ArgsBuffer:
|
||||
loud: bool = False
|
||||
key: str | None = None
|
||||
value: str | None = None
|
||||
audio_index: str | None = None
|
||||
dry_run: bool | None = None
|
||||
|
||||
def translate_audio_description(description: str) -> str:
|
||||
for src, dst in AUDIO_TRANSLATIONS.items():
|
||||
@@ -561,6 +563,8 @@ def cmd_remove_audio_track(args):
|
||||
|
||||
cmd.append(str(args.output))
|
||||
logger.debug(" ".join(cmd))
|
||||
if args.dry_run:
|
||||
return "No Output needed"
|
||||
try:
|
||||
result = subprocess.run(
|
||||
cmd,
|
||||
@@ -1020,32 +1024,20 @@ def cmd_remove_russian_from_db(args_in):
|
||||
media_files.extend(list(args_in.input.rglob("*"+ext)))
|
||||
for file in media_files:
|
||||
audio_tracks = translate_audio_tracks(get_audio_tracks(file))
|
||||
subtitle_tracks = translate_audio_tracks(get_subtitle_tracks(file))
|
||||
logger.trace(f"File: {file.name}: Audio tracks: {audio_tracks}")
|
||||
remove_tracks = []
|
||||
remove_subtitle_tracks = []
|
||||
for track in audio_tracks:
|
||||
if is_russian_track(track["description"]):
|
||||
remove_tracks.append(track["number"])
|
||||
logger.debug(f"Removing russian track {track['number']} from {file}")
|
||||
for track in subtitle_tracks:
|
||||
if is_russian_track(track["description"]):
|
||||
remove_subtitle_tracks.append(track["number"])
|
||||
logger.debug(f"Removing russian subtitle {track['number']} from {file}")
|
||||
for number in remove_tracks:
|
||||
args=ArgsBuffer()
|
||||
args.input = file
|
||||
args.dry_run = args_in.dry_run
|
||||
args.audio_index = number
|
||||
args.output = file.with_name(f"{file.stem}_remove_russian{file.suffix}")
|
||||
if cmd_remove_audio_track(args) == "No output needed":
|
||||
logger.debug(safe_rename(args.output, file))
|
||||
args=ArgsBuffer()
|
||||
args.input = file
|
||||
args.num = [remove_subtitle_tracks]
|
||||
args.output = file.with_name(f"{file.stem}_remove_russian{file.suffix}")
|
||||
|
||||
if cmd_remove_subs(args) == "No output needed":
|
||||
logger.debug(safe_rename(args.output, file))
|
||||
logger.debug(safe_rename(args.output, file,overwrite=True))
|
||||
|
||||
return "No output needed"
|
||||
|
||||
@@ -1258,11 +1250,11 @@ def cmd_test(args):
|
||||
logger.error(f"Found russian track: {audio_track} in file {file}")
|
||||
return return_value and False
|
||||
|
||||
logger.debug(f"Subtitle tracks: {subtitle_tracks}")
|
||||
for subtitle_track in subtitle_tracks:
|
||||
if is_russian_track(audio_track["description"]):
|
||||
logger.error(f"Found russian track: {subtitle_track} in file {file}")
|
||||
return return_value and False
|
||||
#logger.debug(f"Subtitle tracks: {subtitle_tracks}")
|
||||
#for subtitle_track in subtitle_tracks:
|
||||
# if is_russian_track(audio_track["description"]):
|
||||
# logger.error(f"Found russian track: {subtitle_track} in file {file}")
|
||||
# return return_value and False
|
||||
|
||||
logger.info(f"{green_tag("PASS")} {file_path}")
|
||||
return return_value
|
||||
@@ -1475,6 +1467,11 @@ def main():
|
||||
choices=["TRACE", "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
|
||||
help="Set log level",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--dry-run",
|
||||
action="store_true",
|
||||
help="Dry run only",
|
||||
)
|
||||
# ----------------------------
|
||||
# BASE ARGS (shared)
|
||||
# ----------------------------
|
||||
@@ -1660,9 +1657,9 @@ def main():
|
||||
# ----------------------------
|
||||
if args.command != "test":
|
||||
args.input = ensure(getattr(args, "input", None), f"Input file ({Path.cwd()})")
|
||||
args.input = Path(args.input).resolve()
|
||||
args.input = Path(args.input).expanduser().resolve()
|
||||
if not Path(args.input).exists():
|
||||
parser.error("Input file does not exist!")
|
||||
parser.error(f"Input file {args.input} does not exist!")
|
||||
if commands[args.command]["output"] and not getattr(args, "output", None):
|
||||
input_path = Path(args.input)
|
||||
if args.override:
|
||||
@@ -1739,7 +1736,9 @@ def main():
|
||||
counter+=1
|
||||
# ---- SINGLE FILE ----
|
||||
elif input_path.is_file():
|
||||
outputs.append(args.func(args))
|
||||
out = args.func(args)
|
||||
if out != "No output needed":
|
||||
outputs.append(out)
|
||||
else:
|
||||
raise ValueError(f"Invalid input path: {args.input}")
|
||||
|
||||
|
||||
Reference in new issue
Block a user