transcode.py: add --filter
This commit is contained in:
+23
-7
@@ -357,7 +357,7 @@ def transcode_file(input_file, output_file=None, skip_av1=True, replace_mode=Fal
|
||||
)
|
||||
return
|
||||
|
||||
# 2. Check if file is ready (simple size stability check)
|
||||
# 2. Check if file is ready
|
||||
if not input_path.exists():
|
||||
logging.warning(f"File vanished during checks: {input_path}")
|
||||
return
|
||||
@@ -386,7 +386,7 @@ def transcode_file(input_file, output_file=None, skip_av1=True, replace_mode=Fal
|
||||
logging.warning(f"File vanished during checks: {input_path}")
|
||||
return
|
||||
|
||||
# 3. Check Codec (Optional Skip)
|
||||
# 3. Check Codec
|
||||
if skip_av1:
|
||||
codec = get_video_codec(input_path)
|
||||
if codec == "av1":
|
||||
@@ -582,10 +582,13 @@ def transcode_file(input_file, output_file=None, skip_av1=True, replace_mode=Fal
|
||||
|
||||
|
||||
class NewFileHandler(FileSystemEventHandler):
|
||||
def __init__(self, output_dir=None, skip_av1=True, replace_mode=False):
|
||||
def __init__(
|
||||
self, output_dir=None, skip_av1=True, replace_mode=False, filter_pattern="*"
|
||||
):
|
||||
self.output_dir = Path(output_dir) if output_dir else None
|
||||
self.skip_av1 = skip_av1
|
||||
self.replace_mode = replace_mode
|
||||
self.filter_pattern = filter_pattern
|
||||
|
||||
def on_created(self, event):
|
||||
if event.is_directory:
|
||||
@@ -604,7 +607,11 @@ class NewFileHandler(FileSystemEventHandler):
|
||||
return
|
||||
|
||||
input_path = Path(file_path_str)
|
||||
# Filter for video extensions
|
||||
|
||||
# Check filter first
|
||||
if not input_path.match(self.filter_pattern):
|
||||
return
|
||||
|
||||
if input_path.suffix.lower() not in VIDEO_EXTENSIONS:
|
||||
logging.debug(f"Ignored non-video file: {input_path}")
|
||||
return
|
||||
@@ -628,7 +635,7 @@ def process_recursive_directory(input_path, args, skip_av1):
|
||||
|
||||
# We collect files first to avoid modifying directory while iterating if possible,
|
||||
# though rglob is a generator. We check STOP_REQUESTED inside loop.
|
||||
for video_file in input_path.rglob("*"):
|
||||
for video_file in input_path.rglob(args.filter):
|
||||
if STOP_REQUESTED:
|
||||
logging.info("Stopping recursive scan due to signal.")
|
||||
break
|
||||
@@ -683,6 +690,12 @@ def main():
|
||||
action="store_true",
|
||||
help="Recursively scan directories for input files",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--filter",
|
||||
type=str,
|
||||
default="*",
|
||||
help="Glob pattern to filter input files (e.g. '*.avi'). Defaults to '*' (all).",
|
||||
)
|
||||
|
||||
# Set defaults from config
|
||||
default_watch = config.get("watch") or False
|
||||
@@ -731,7 +744,7 @@ def main():
|
||||
else:
|
||||
# Process directory non-recursively (all files in this directory only)
|
||||
logging.info(f"Processing directory non-recursively: {input_path}")
|
||||
for video_file in input_path.iterdir():
|
||||
for video_file in input_path.glob(args.filter):
|
||||
if STOP_REQUESTED:
|
||||
break
|
||||
if (
|
||||
@@ -805,7 +818,10 @@ def main():
|
||||
logging.info("Outputting in-place (replacing originals).")
|
||||
|
||||
event_handler = NewFileHandler(
|
||||
output_dir_path, skip_av1=skip_av1, replace_mode=args.replace
|
||||
output_dir_path,
|
||||
skip_av1=skip_av1,
|
||||
replace_mode=args.replace,
|
||||
filter_pattern=args.filter,
|
||||
)
|
||||
observer = Observer()
|
||||
observer.schedule(event_handler, str(watch_dir), recursive=args.recursive)
|
||||
|
||||
Reference in New Issue
Block a user