removed TUI and others
This commit is contained in:
@@ -386,6 +386,25 @@ def is_url_supported_by_ytdlp(url: str) -> bool:
|
||||
|
||||
_FORMATS_CACHE: Dict[str, tuple[float, List[Dict[str, Any]]]] = {}
|
||||
|
||||
|
||||
def _audio_variant_base_selector(fmt: Any) -> Optional[str]:
|
||||
if not isinstance(fmt, dict):
|
||||
return None
|
||||
|
||||
format_id = str(fmt.get("format_id") or "").strip()
|
||||
if not format_id:
|
||||
return None
|
||||
|
||||
vcodec = str(fmt.get("vcodec", "none"))
|
||||
acodec = str(fmt.get("acodec", "none"))
|
||||
if vcodec != "none" or acodec == "none":
|
||||
return None
|
||||
|
||||
match = re.fullmatch(r"(?P<base>\d+)-[A-Za-z0-9]+", format_id)
|
||||
if not match:
|
||||
return None
|
||||
return match.group("base")
|
||||
|
||||
def list_formats(
|
||||
url: str,
|
||||
*,
|
||||
@@ -449,9 +468,26 @@ def list_formats(
|
||||
result_container[0] = None
|
||||
return
|
||||
|
||||
selector_cache: Dict[str, bool] = {}
|
||||
|
||||
def _selector_has_matches(selector: str) -> bool:
|
||||
cached = selector_cache.get(selector)
|
||||
if cached is not None:
|
||||
return cached
|
||||
try:
|
||||
matches = ydl.build_format_selector(selector)(info)
|
||||
cached = any(True for _ in matches)
|
||||
except Exception:
|
||||
cached = False
|
||||
selector_cache[selector] = cached
|
||||
return cached
|
||||
|
||||
out: List[Dict[str, Any]] = []
|
||||
for fmt in formats:
|
||||
if isinstance(fmt, dict):
|
||||
base_selector = _audio_variant_base_selector(fmt)
|
||||
if base_selector and not _selector_has_matches(base_selector):
|
||||
fmt["_medios_selector_valid"] = False
|
||||
out.append(fmt)
|
||||
result_container[0] = out
|
||||
except Exception as exc:
|
||||
@@ -596,6 +632,9 @@ def is_browseable_format(fmt: Any) -> bool:
|
||||
"""
|
||||
if not isinstance(fmt, dict):
|
||||
return False
|
||||
|
||||
if fmt.get("_medios_selector_valid") is False:
|
||||
return False
|
||||
|
||||
format_id = str(fmt.get("format_id") or "").strip()
|
||||
if not format_id:
|
||||
|
||||
Reference in New Issue
Block a user