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_file_for_corruption(file_path: Path, error_queue): """Check a file for corruption using FFmpeg.""" try: file_extension = file_path.suffix.lower() if file_extension in Config.VIDEO_EXTENSIONS | Config.AUDIO_EXTENSIONS | Config.IMAGE_EXTENSIONS: base_command = [str(Config.FFMPEG), '-v', 'error', '-i', str(file_path)]
if file_extension in Config.VIDEO_EXTENSIONS: command = base_command + ['-map', '0:a:0', '-f', 'null', '-'] else: command = base_command + ['-f', 'null', '-'] process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) output, error = process.communicate() combined_output = output.decode('utf-8', errors='ignore') + error.decode('utf-8', errors='ignore') error_messages = [line.strip() for line in combined_output.split('\n') 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}: {str(e)}"])) - Assistant