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: Do not split into several functions. Code: def check_for_corrupted_files(): """Check for corrupted files in the input folder using FFmpeg.""" image_processor.reset_results()
codetry: check_ffmpeg() except FileNotFoundError as error: log_error(str(error)) return valid_extensions = Config.VIDEO_EXTENSIONS | Config.AUDIO_EXTENSIONS | Config.IMAGE_EXTENSIONS tasks = [file for file in Config.INPUT_FOLDER.rglob("*") if file.is_file() and file.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 check_file(file_path: Path): try: base_command = [str(Config.FFMPEG), "-v", "error", "-i", str(file_path)] if file_path.suffix.lower() in Config.VIDEO_EXTENSIONS: base_command += ["-map", "0:a:0"] base_command += ["-f", "null", "-"] result = subprocess.run(base_command, capture_output=True, text=True, encoding="utf-8", errors="ignore") error_messages = [line.strip() for line in f"{result.stdout}\n{result.stderr}".splitlines() if "error" in line.lower()] if error_messages: error_queue.put((file_path.resolve(), error_messages)) except Exception as e: error_queue.put((file_path.resolve(), [f"Error processing file {file_path}: {e}"])) finally: 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, check_file) log_errors(error_queue) - Assistant