|
15 | 15 | TEMP_FILE = "temp.mp4" |
16 | 16 | TEMP_DIRECTORY = "temp" |
17 | 17 |
|
18 | | -# monkey patch ssl for mac |
19 | | -if platform.system().lower() == "darwin": |
20 | | - ssl._create_default_https_context = ssl._create_unverified_context |
21 | | - |
22 | 18 |
|
23 | 19 | def run_ffmpeg(args: List[str]) -> bool: |
24 | 20 | """Run ffmpeg with hardware acceleration and optimized settings.""" |
@@ -286,16 +282,29 @@ def conditional_download(download_directory_path: str, urls: List[str]) -> None: |
286 | 282 | download_directory_path, os.path.basename(url) |
287 | 283 | ) |
288 | 284 | if not os.path.exists(download_file_path): |
289 | | - request = urllib.request.urlopen(url) # type: ignore[attr-defined] |
290 | | - total = int(request.headers.get("Content-Length", 0)) |
| 285 | + request = urllib.request.Request(url) |
| 286 | + |
| 287 | + # Create a specific SSL context for macOS to avoid globally disabling verification |
| 288 | + ctx = None |
| 289 | + if platform.system().lower() == "darwin": |
| 290 | + ctx = ssl._create_unverified_context() |
| 291 | + |
| 292 | + response = urllib.request.urlopen(request, context=ctx) |
| 293 | + total = int(response.headers.get("Content-Length", 0)) |
291 | 294 | with tqdm( |
292 | 295 | total=total, |
293 | 296 | desc="Downloading", |
294 | 297 | unit="B", |
295 | 298 | unit_scale=True, |
296 | 299 | unit_divisor=1024, |
297 | 300 | ) as progress: |
298 | | - urllib.request.urlretrieve(url, download_file_path, reporthook=lambda count, block_size, total_size: progress.update(block_size)) # type: ignore[attr-defined] |
| 301 | + with open(download_file_path, "wb") as f: |
| 302 | + while True: |
| 303 | + buffer = response.read(8192) |
| 304 | + if not buffer: |
| 305 | + break |
| 306 | + f.write(buffer) |
| 307 | + progress.update(len(buffer)) |
299 | 308 |
|
300 | 309 |
|
301 | 310 | def resolve_relative_path(path: str) -> str: |
|
0 commit comments