f
This commit is contained in:
@@ -27,6 +27,7 @@ from SYS.models import (
|
||||
)
|
||||
from SYS.pipeline_progress import PipelineProgress
|
||||
from SYS.utils import ensure_directory, sha256_file
|
||||
from SYS.metadata import extract_ytdlp_tags
|
||||
|
||||
_YTDLP_TRANSFER_STATE: Dict[str, Dict[str, Any]] = {}
|
||||
|
||||
@@ -37,7 +38,7 @@ try:
|
||||
except Exception as exc: # pragma: no cover - handled at runtime
|
||||
yt_dlp = None # type: ignore
|
||||
gen_extractors = None # type: ignore
|
||||
YTDLP_IMPORT_ERROR = exc
|
||||
YTDLP_IMPORT_ERROR: Optional[Exception] = exc
|
||||
else:
|
||||
YTDLP_IMPORT_ERROR = None
|
||||
|
||||
@@ -739,16 +740,16 @@ class YtDlpTool:
|
||||
|
||||
# Progress + utility helpers for yt-dlp driven downloads (previously in cmdlet/download_media).
|
||||
_YTDLP_PROGRESS_BAR = ProgressBar()
|
||||
_YTDLP_TRANSFER_STATE: Dict[str, Dict[str, Any]] = {}
|
||||
_YTDLP_PROGRESS_ACTIVITY_LOCK = threading.Lock()
|
||||
_YTDLP_PROGRESS_LAST_ACTIVITY = 0.0
|
||||
_YTDLP_PROGRESS_ACTIVITY_LOCK = threading.Lock()
|
||||
_YTDLP_PROGRESS_LAST_ACTIVITY = 0.0
|
||||
_SUBTITLE_EXTS = (".vtt", ".srt", ".ass", ".ssa", ".lrc")
|
||||
|
||||
|
||||
def _progress_label(status: Dict[str, Any]) -> str:
|
||||
info_dict = status.get("info_dict") if isinstance(status.get("info_dict"), dict) else {}
|
||||
def _progress_label(status: Optional[Dict[str, Any]]) -> str:
|
||||
if not status:
|
||||
return "unknown"
|
||||
raw_info = status.get("info_dict")
|
||||
info_dict = raw_info if isinstance(raw_info, dict) else {}
|
||||
|
||||
candidates = [
|
||||
status.get("filename"),
|
||||
@@ -1244,7 +1245,7 @@ def download_media(opts: DownloadOptions, *, debug_logger: Optional[DebugLogger]
|
||||
debug(
|
||||
f"Skipping probe for playlist (item selection: {opts.playlist_items}), proceeding with download"
|
||||
)
|
||||
probe_result = {"url": opts.url}
|
||||
probe_result: Optional[Dict[str, Any]] = {"url": opts.url}
|
||||
else:
|
||||
probe_cookiefile = None
|
||||
try:
|
||||
@@ -1286,7 +1287,7 @@ def download_media(opts: DownloadOptions, *, debug_logger: Optional[DebugLogger]
|
||||
debug(f"[yt-dlp] force_keyframes_at_cuts: {ytdl_options.get('force_keyframes_at_cuts', False)}")
|
||||
|
||||
session_id = None
|
||||
first_section_info = {}
|
||||
first_section_info: Dict[str, Any] = {}
|
||||
if ytdl_options.get("download_sections"):
|
||||
live_ui, _ = PipelineProgress(pipeline_context).ui_and_pipe_index()
|
||||
quiet_sections = bool(opts.quiet) or (live_ui is not None)
|
||||
@@ -1447,20 +1448,20 @@ def download_media(opts: DownloadOptions, *, debug_logger: Optional[DebugLogger]
|
||||
raise DownloadError(str(exc)) from exc
|
||||
|
||||
file_hash = sha256_file(media_path)
|
||||
tags = []
|
||||
section_tags: List[str] = []
|
||||
title = ""
|
||||
if first_section_info:
|
||||
title = first_section_info.get("title", "")
|
||||
if title:
|
||||
tags.append(f"title:{title}")
|
||||
section_tags.append(f"title:{title}")
|
||||
debug(f"Added title tag for section download: {title}")
|
||||
|
||||
if first_section_info:
|
||||
info_dict = first_section_info
|
||||
info_dict_sec = first_section_info
|
||||
else:
|
||||
info_dict = {"id": media_path.stem, "title": title or media_path.stem, "ext": media_path.suffix.lstrip(".")}
|
||||
info_dict_sec = {"id": media_path.stem, "title": title or media_path.stem, "ext": media_path.suffix.lstrip(".")}
|
||||
|
||||
return DownloadMediaResult(path=media_path, info=info_dict, tag=tags, source_url=opts.url, hash_value=file_hash, paths=media_paths)
|
||||
return DownloadMediaResult(path=media_path, info=info_dict_sec, tag=section_tags, source_url=opts.url, hash_value=file_hash, paths=media_paths)
|
||||
|
||||
if not isinstance(info, dict):
|
||||
log(f"Unexpected yt-dlp response: {type(info)}", file=sys.stderr)
|
||||
@@ -1483,7 +1484,7 @@ def download_media(opts: DownloadOptions, *, debug_logger: Optional[DebugLogger]
|
||||
hash_value = None
|
||||
|
||||
tags: List[str] = []
|
||||
if extract_ytdlp_tags:
|
||||
if extract_ytdlp_tags is not None:
|
||||
try:
|
||||
tags = extract_ytdlp_tags(entry)
|
||||
except Exception as exc:
|
||||
@@ -1524,10 +1525,10 @@ def download_media(opts: DownloadOptions, *, debug_logger: Optional[DebugLogger]
|
||||
if debug_logger is not None:
|
||||
debug_logger.write_record("hash-error", {"path": str(media_path), "error": str(exc)})
|
||||
|
||||
tags = []
|
||||
if extract_ytdlp_tags:
|
||||
tags_res: List[str] = []
|
||||
if extract_ytdlp_tags is not None:
|
||||
try:
|
||||
tags = extract_ytdlp_tags(entry)
|
||||
tags_res = extract_ytdlp_tags(entry)
|
||||
except Exception as exc:
|
||||
log(f"Error extracting tags: {exc}", file=sys.stderr)
|
||||
|
||||
@@ -1546,7 +1547,7 @@ def download_media(opts: DownloadOptions, *, debug_logger: Optional[DebugLogger]
|
||||
},
|
||||
)
|
||||
|
||||
return DownloadMediaResult(path=media_path, info=entry, tag=tags, source_url=source_url, hash_value=hash_value)
|
||||
return DownloadMediaResult(path=media_path, info=entry, tag=tags_res, source_url=source_url, hash_value=hash_value)
|
||||
|
||||
|
||||
def _download_with_timeout(opts: DownloadOptions, timeout_seconds: int = 300) -> Any:
|
||||
|
||||
Reference in New Issue
Block a user