Improved FFmpeg downloader error handling and permissions

This commit is contained in:
pacnpal
2024-11-15 01:31:37 +00:00
parent dccd16e776
commit 826f5e1b3e

View File

@@ -93,6 +93,13 @@ class FFmpegDownloader:
self.base_dir.mkdir(parents=True, exist_ok=True)
os.chmod(str(self.base_dir), 0o777)
# Clean up any existing file or directory
if self.ffmpeg_path.exists():
if self.ffmpeg_path.is_dir():
shutil.rmtree(str(self.ffmpeg_path))
else:
self.ffmpeg_path.unlink()
with temp_path_context() as temp_dir:
# Download archive
archive_path = self._download_archive(temp_dir)
@@ -101,7 +108,7 @@ class FFmpegDownloader:
self._extract_binary(archive_path, temp_dir)
# Set proper permissions
os.chmod(str(self.ffmpeg_path), 0o777)
os.chmod(str(self.ffmpeg_path), 0o755)
return self.ffmpeg_path
@@ -131,10 +138,6 @@ class FFmpegDownloader:
"""Extract FFmpeg binary from archive"""
logger.info("Extracting FFmpeg binary")
# Remove existing binary if it exists
if self.ffmpeg_path.exists():
self.ffmpeg_path.unlink()
if self.system == "Windows":
self._extract_zip(archive_path, temp_dir)
else:
@@ -169,7 +172,7 @@ class FFmpegDownloader:
return False
# Ensure proper permissions
os.chmod(str(self.ffmpeg_path), 0o777)
os.chmod(str(self.ffmpeg_path), 0o755)
# Test FFmpeg functionality
result = subprocess.run(