This commit is contained in:
2026-02-28 14:04:03 -08:00
parent b6e4971caf
commit 818d0c0338
4 changed files with 27 additions and 15 deletions

View File

@@ -285,6 +285,9 @@ db = Database()
_LOG_QUEUE: Queue[tuple[str, str, str]] = Queue()
_LOG_THREAD_STARTED = False
_LOG_THREAD_LOCK = threading.Lock()
_LOG_WRITE_COUNT = 0
_LOG_PRUNE_INTERVAL = 500 # prune every N successful writes
_LOG_MAX_AGE_DAYS = 7 # keep logs for this many days
def _ensure_log_db_schema() -> None:
@@ -323,6 +326,7 @@ def _log_worker_loop() -> None:
"""Background log writer using a temporary per-write connection with
small retry/backoff and a file fallback when writes fail repeatedly.
"""
global _LOG_WRITE_COUNT
while True:
level, module, message = _LOG_QUEUE.get()
try:
@@ -340,6 +344,14 @@ def _log_worker_loop() -> None:
cur = conn.cursor()
cur.execute("INSERT INTO logs (level, module, message) VALUES (?, ?, ?)", (level, module, message))
conn.commit()
_LOG_WRITE_COUNT += 1
if _LOG_WRITE_COUNT % _LOG_PRUNE_INTERVAL == 0:
try:
cutoff = (datetime.datetime.utcnow() - datetime.timedelta(days=_LOG_MAX_AGE_DAYS)).strftime("%Y-%m-%d %H:%M:%S")
cur.execute("DELETE FROM logs WHERE timestamp < ?", (cutoff,))
conn.commit()
except Exception:
pass
cur.close()
conn.close()
written = True

View File

@@ -2092,7 +2092,7 @@ def expand_tag_lists(tags_set: Set[str]) -> Set[str]:
return tags_set
try:
with open(adjective_path, "r") as f:
with open(adjective_path, "r", encoding="utf-8") as f:
adjective_lists = json.load(f)
except Exception as e:
debug(f"Error loading adjective.json: {e}")

View File

@@ -1044,7 +1044,7 @@ class Download_File(Cmdlet):
vcodec = str(chosen.get("vcodec", "none"))
acodec = str(chosen.get("acodec", "none"))
if vcodec != "none" and acodec == "none":
selection_format_id = f"{selection_format_id}+bestaudio/best"
selection_format_id = f"{selection_format_id}+bestaudio"
except Exception:
pass
@@ -1339,7 +1339,7 @@ class Download_File(Cmdlet):
selection_format_id = format_id
try:
if vcodec != "none" and acodec == "none" and format_id:
selection_format_id = f"{format_id}+bestaudio/best"
selection_format_id = f"{format_id}+bestaudio"
except Exception:
selection_format_id = format_id
@@ -1485,7 +1485,7 @@ class Download_File(Cmdlet):
actual_playlist_items = None
if mode == "audio" and not actual_format:
actual_format = "bestaudio/best"
actual_format = "bestaudio"
if mode == "video" and not actual_format:
configured = (ytdlp_tool.default_format("video") or "").strip()
@@ -1514,7 +1514,7 @@ class Download_File(Cmdlet):
and isinstance(actual_format, str)
and actual_format == "audio"
):
actual_format = "bestaudio/best"
actual_format = "bestaudio"
# DEBUG: Render config panel for tracking pipeline state
if is_debug_enabled():
@@ -1553,8 +1553,8 @@ class Download_File(Cmdlet):
and not forced_single_applied
and actual_format not in {"best", "bestaudio", "bw", "ba"}
):
debug(f"Appending fallback to specific audio format: {actual_format} -> {actual_format}/bestaudio/best")
actual_format = f"{actual_format}/bestaudio/best"
debug(f"Appending fallback to specific audio format: {actual_format} -> {actual_format}/bestaudio")
actual_format = f"{actual_format}/bestaudio"
if (
actual_format
@@ -1579,8 +1579,8 @@ class Download_File(Cmdlet):
vcodec = str(fmt_match.get("vcodec", "none"))
acodec = str(fmt_match.get("acodec", "none"))
if vcodec != "none" and acodec == "none":
debug(f"Selected video-only format {actual_format}; using {actual_format}+bestaudio/best for audio")
actual_format = f"{actual_format}+bestaudio/best"
debug(f"Selected video-only format {actual_format}; using {actual_format}+bestaudio for audio")
actual_format = f"{actual_format}+bestaudio"
except Exception as e:
pass
@@ -1725,7 +1725,7 @@ class Download_File(Cmdlet):
vcodec = str(only.get("vcodec", "none"))
acodec = str(only.get("acodec", "none"))
if vcodec != "none" and acodec == "none" and fallback_format:
selection_format_id = f"{fallback_format}+bestaudio/best"
selection_format_id = f"{fallback_format}+bestaudio"
except Exception:
selection_format_id = fallback_format
@@ -1755,7 +1755,7 @@ class Download_File(Cmdlet):
selection_format_id = format_id
try:
if vcodec != "none" and acodec == "none" and format_id:
selection_format_id = f"{format_id}+bestaudio/best"
selection_format_id = f"{format_id}+bestaudio"
except Exception:
selection_format_id = format_id
@@ -2089,9 +2089,9 @@ class Download_File(Cmdlet):
except Exception:
height_selector = None
if query_wants_audio:
# Explicit `format:audio` must always force bestaudio fallback chain
# Explicit `format:audio` must always force bestaudio selection
# and avoid format-list/selector ambiguity.
ytdl_format = "bestaudio/best"
ytdl_format = "bestaudio"
elif height_selector:
ytdl_format = height_selector
elif query_format:
@@ -2473,7 +2473,7 @@ class Download_File(Cmdlet):
else:
chosen_format = None
if mode == "audio":
chosen_format = "bestaudio/best"
chosen_format = "bestaudio"
opts = DownloadOptions(
url=url_str,

View File

@@ -726,7 +726,7 @@ class YtDlpDefaults:
format: str = "best"
video_format: str = "bestvideo+bestaudio/best"
audio_format: str = "bestaudio/best"
audio_format: str = "bestaudio"
format_sort: Optional[List[str]] = None
cookies_from_browser: Optional[str] = None