refactor: Improve ffmpeg_downloader module

- Enhanced Docker compatibility with proper permissions
- Better error handling and logging
- Improved download and extraction process
- Added detailed type hints and documentation
This commit is contained in:
pacnpal
2024-11-14 22:37:42 +00:00
parent 2f449e6120
commit 2ba89edbd9

View File

@@ -10,6 +10,8 @@ import subprocess
import tempfile
from pathlib import Path
from contextlib import contextmanager
from typing import Optional
from .exceptions import DownloadError
logger = logging.getLogger("VideoArchiver")
@@ -62,6 +64,7 @@ class FFmpegDownloader:
}
def __init__(self, system: str, machine: str, base_dir: Path):
"""Initialize FFmpeg downloader"""
self.system = system
self.machine = machine.lower()
if self.machine == "arm64":
@@ -112,6 +115,7 @@ class FFmpegDownloader:
archive_path = Path(temp_dir) / f"ffmpeg_archive{'.zip' if self.system == 'Windows' else '.tar.xz'}"
logger.info(f"Downloading FFmpeg from {url}")
try:
response = requests.get(url, stream=True, timeout=30)
response.raise_for_status()
@@ -120,6 +124,8 @@ class FFmpegDownloader:
f.write(chunk)
return archive_path
except Exception as e:
raise DownloadError(f"Failed to download FFmpeg: {str(e)}")
def _extract_binary(self, archive_path: Path, temp_dir: str):
"""Extract FFmpeg binary from archive"""