You are a Python programmer tasked with refactoring code. You are proficient in…
- User
SYSTEM: You are a Python programmer tasked with refactoring code. You are proficient in Python 3.12 and use modern features where appropriate. Your code is clear, easy to read, and free of unnecessary verbosity. You use single-line docstrings and occasional comments for documentation. Often, the code you receive is just one part of a larger program. USER: def check_for_corrupted_files(): """Check for corrupted files in the input folder.""" image_processor.reset_results()
try: check_ffmpeg() except FileNotFoundError as e: log_error(str(e)) return tasks = [file_path for file_path in Config.INPUT_FOLDER.rglob('*') if file_path.is_file() and file_path.suffix.lower() in Config.VIDEO_EXTENSIONS | Config.AUDIO_EXTENSIONS | Config.IMAGE_EXTENSIONS] if not tasks: log_error(f"No valid media files found in '{Config.INPUT_FOLDER}'") return error_queue = Queue() def process_task(file_path, error_queue, start_time, total_files): check_file_for_corruption(file_path, error_queue) with shared_state.processed_files_lock: shared_state.processed_files_count += 1 update_status(start_time, shared_state.processed_files_count, total_files) run_with_thread_pool(tasks, process_task, error_queue, time.time(), len(tasks)) log_errors(error_queue) - Assistant
from pathlib import Path from queue import Queue import time def check_for_corrupted_files(): """Check for corrupted files in the input folder.""" image_processor.reset_results() try: check_ffmpeg() except FileNotFoundError as error: log_error(str(error)) return # Combine all valid extensions into a single set for efficient lookup valid_extensions = ( Config.VIDEO_EXTENSIONS | Config.AUDIO_EXTENSIONS | Config.IMAGE_EXTENSIONS ) # Gather all relevant file paths tasks = [ file_path for file_path in Config.INPUT_FOLDER.rglob('*') if file_path.is_file() and file_path.suffix.lower() in valid_extensions ] if not tasks: log_error(f"No valid media files found in '{Config.INPUT_FOLDER}'") return error_queue = Queue() start_time = time.time() total_files = len(tasks) def process_task(file_path: Path, error_queue: Queue, start_time: float, total_files: int): """Process a single file for corruption.""" check_file_for_corruption(file_path, error_queue) with shared_state.processed_files_lock: shared_state.processed_files_count += 1 update_status(start_time, shared_state.processed_files_count, total_files) run_with_thread_pool(tasks, process_task, error_queue, start_time, total_files) log_errors(error_queue)