mirror of
https://github.com/denizsafak/abogen.git
synced 2026-07-18 13:40:27 +02:00
feat: Update audio sink to manage ffmpeg cache by platform
This commit is contained in:
@@ -5,6 +5,7 @@ import math
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
from contextlib import ExitStack
|
from contextlib import ExitStack
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -312,16 +313,17 @@ def _open_audio_sink(
|
|||||||
fmt: Optional[str] = None,
|
fmt: Optional[str] = None,
|
||||||
metadata: Optional[Dict[str, str]] = None,
|
metadata: Optional[Dict[str, str]] = None,
|
||||||
) -> AudioSink:
|
) -> AudioSink:
|
||||||
ffmpeg_cache = get_internal_cache_path("ffmpeg")
|
ffmpeg_cache_root = get_internal_cache_path("ffmpeg")
|
||||||
os.makedirs(ffmpeg_cache, exist_ok=True)
|
platform_cache = os.path.join(ffmpeg_cache_root, sys.platform)
|
||||||
|
os.makedirs(platform_cache, exist_ok=True)
|
||||||
try:
|
try:
|
||||||
import static_ffmpeg.run as static_ffmpeg_run # type: ignore
|
import static_ffmpeg.run as static_ffmpeg_run # type: ignore
|
||||||
|
|
||||||
static_ffmpeg_run.LOCK_FILE = os.path.join(ffmpeg_cache, "lock.file")
|
static_ffmpeg_run.LOCK_FILE = os.path.join(ffmpeg_cache_root, "lock.file")
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
static_ffmpeg.add_paths(download_dir=ffmpeg_cache)
|
static_ffmpeg.add_paths(weak=True, download_dir=platform_cache)
|
||||||
fmt_value = (fmt or job.output_format).lower()
|
fmt_value = (fmt or job.output_format).lower()
|
||||||
|
|
||||||
if fmt_value in {"wav", "flac"}:
|
if fmt_value in {"wav", "flac"}:
|
||||||
|
|||||||
Reference in New Issue
Block a user