cli: align directory handling with codebase style

Use warnings.warn() for errors instead of print(), show detailed
messages only with --verbose, and simplify user prompts. Keep
error handling consistent with the rest of the codebase.
This commit is contained in:
Cavit Erginsoy 2025-01-20 22:27:15 +00:00
parent de4f28f3d7
commit cde50ec846

View File

@ -255,16 +255,14 @@ def main():
if path.is_dir(): if path.is_dir():
media_files = get_media_files(path) media_files = get_media_files(path)
if not media_files: if not media_files:
print(f"No media files found in directory: {path}") warnings.warn(f"No files found in directory: {path}")
continue
print(f"Found {len(media_files)} files in directory{path}")
response = input("Continue processing all files in target directory? [Y/n] ").strip()
if response.lower() in ['n', 'no']:
continue continue
if args.get("verbose"): if args.get("verbose"):
print(f"Processing {len(media_files)} files in {path}...") print(f"Found {len(media_files)} files in {path}")
response = input("Process all files? [Y/n] ").strip()
if response.lower() in ['n', 'no']:
continue
for file_path in media_files: for file_path in media_files:
try: try:
@ -275,8 +273,9 @@ def main():
) )
writer(result, file_path.stem, **writer_args) writer(result, file_path.stem, **writer_args)
except Exception as e: except Exception as e:
traceback.print_exc() warnings.warn(f"Failed to process {file_path}: {str(e)}")
print(f"Skipping {file_path} due to {type(e).__name__}: {str(e)}") if args.get("verbose"):
traceback.print_exc()
continue continue
output_name = output_name or path.stem output_name = output_name or path.stem
@ -288,8 +287,9 @@ def main():
) )
writer(result, output_name, **writer_args) writer(result, output_name, **writer_args)
except Exception as e: except Exception as e:
traceback.print_exc() warnings.warn(f"Failed to process {audio_obj}: {str(e)}")
print(f"Skipping {audio_obj} due to {type(e).__name__}: {str(e)}") if args.get("verbose"):
traceback.print_exc()
if __name__ == "__main__": if __name__ == "__main__":