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: # --- Corrupted Files ---
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)]
codeif 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)}"]))
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))
- Assistantpython
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.