Refactor: Strengthen error handling and remove debug prints

This commit is contained in:
Ramforth
2025-11-01 12:11:21 +01:00
parent 03330eeb19
commit a73569a5e8
2 changed files with 19 additions and 3 deletions

View File

@@ -42,14 +42,24 @@ def main():
print(f"Error: '{input_file_path}' is not a file.", file=sys.stderr) print(f"Error: '{input_file_path}' is not a file.", file=sys.stderr)
sys.exit(1) sys.exit(1)
if not os.access(input_file_path, os.R_OK):
print(f"Error: No read permission for input file '{input_file_path}'.", file=sys.stderr)
sys.exit(1)
output_dir = args.output_dir output_dir = args.output_dir
if output_dir: if output_dir:
output_dir = os.path.abspath(output_dir) output_dir = os.path.abspath(output_dir)
if not os.path.isdir(output_dir): if not os.path.isdir(output_dir):
print(f"Error: Output directory '{output_dir}' does not exist or is not a directory.", file=sys.stderr) print(f"Error: Output directory '{output_dir}' does not exist or is not a directory.", file=sys.stderr)
sys.exit(1) sys.exit(1)
if not os.access(output_dir, os.W_OK):
print(f"Error: No write permission for output directory '{output_dir}'.", file=sys.stderr)
sys.exit(1)
else: else:
output_dir = os.path.dirname(input_file_path) output_dir = os.path.dirname(input_file_path)
if not os.access(output_dir, os.W_OK):
print(f"Error: No write permission for input file's directory '{output_dir}'.", file=sys.stderr)
sys.exit(1)
# Perform conversion # Perform conversion
print(f"Starting conversion for {input_file_path}...") print(f"Starting conversion for {input_file_path}...")

View File

@@ -15,10 +15,16 @@ def get_video_info(file_path):
] ]
try: try:
result = subprocess.run(command, capture_output=True, text=True, check=True) result = subprocess.run(command, capture_output=True, text=True, check=True)
# Filter out known non-critical ffprobe stderr messages
filtered_stderr = "\n".join([line for line in result.stderr.splitlines() if not ("mpp_soc" in line or "mpp_platform" in line)])
if filtered_stderr:
print(f"ffprobe Stderr: {filtered_stderr}", file=sys.stderr)
return json.loads(result.stdout) return json.loads(result.stdout)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
filtered_stderr = "\n".join([line for line in e.stderr.splitlines() if not ("mpp_soc" in line or "mpp_platform" in line)])
print(f"Error running ffprobe: {e}", file=sys.stderr) print(f"Error running ffprobe: {e}", file=sys.stderr)
print(f"Stderr: {e.stderr}", file=sys.stderr) if filtered_stderr:
print(f"ffprobe Stderr: {filtered_stderr}", file=sys.stderr)
return None return None
except FileNotFoundError: except FileNotFoundError:
print("Error: ffprobe not found. Please ensure FFmpeg is installed and in your PATH.", file=sys.stderr) print("Error: ffprobe not found. Please ensure FFmpeg is installed and in your PATH.", file=sys.stderr)
@@ -29,8 +35,8 @@ def get_audio_info(file_path):
command = [ command = [
'ffprobe', 'ffprobe',
'-v', 'error', '-v', 'error',
'-select_streams', 'a:0', '-select_streams', 'v:0',
'-show_entries', 'stream=codec_name,sample_rate,channels,bit_rate', '-show_entries', 'stream=codec_name,width,height,avg_frame_rate,duration_ts,bit_rate,pix_fmt',
'-of', 'json', '-of', 'json',
file_path file_path
] ]