fix: close remaining concurrent yt-dlp session sources
Three more code paths were bypassing the _meta_lock guard and firing raw yt-dlp processes concurrently with active downloads: - Popular fetch Phase 1 (flat-playlist channel crawl): changed from ytdlp._run to ytdlp._meta_run so it waits for active downloads - download_subs_only: changed from _run to _meta_run - fetch_video_comments: returns empty list immediately if a download is active (avoids blocking a 90s call indefinitely) - Diagnostic test endpoint (settings): switched to _meta_run Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -743,7 +743,7 @@ def _fetch_popular_task(channel_id: int, youtube_channel_id: str, channel_name:
|
|||||||
else:
|
else:
|
||||||
url = f"https://www.youtube.com/channel/{youtube_channel_id}/videos"
|
url = f"https://www.youtube.com/channel/{youtube_channel_id}/videos"
|
||||||
|
|
||||||
stdout, _, _ = ytdlp._run([
|
stdout, _, _ = ytdlp._meta_run([
|
||||||
"yt-dlp", url,
|
"yt-dlp", url,
|
||||||
"--dump-json", "--flat-playlist",
|
"--dump-json", "--flat-playlist",
|
||||||
"--quiet",
|
"--quiet",
|
||||||
|
|||||||
@@ -250,7 +250,7 @@ def ytdlp_test(
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
result = subprocess.run(
|
test_stdout, test_stderr, test_code = ytdlp._meta_run(
|
||||||
[
|
[
|
||||||
"yt-dlp",
|
"yt-dlp",
|
||||||
"https://www.youtube.com/watch?v=dQw4w9WgXcQ",
|
"https://www.youtube.com/watch?v=dQw4w9WgXcQ",
|
||||||
@@ -258,15 +258,15 @@ def ytdlp_test(
|
|||||||
"--extractor-args", "youtube:player_client=web",
|
"--extractor-args", "youtube:player_client=web",
|
||||||
*cookie_args,
|
*cookie_args,
|
||||||
],
|
],
|
||||||
capture_output=True, text=True, timeout=30,
|
timeout=30,
|
||||||
)
|
)
|
||||||
return {
|
return {
|
||||||
"node_path": node_path,
|
"node_path": node_path,
|
||||||
"node_version": node_version,
|
"node_version": node_version,
|
||||||
"yt_dlp_version": yt_version,
|
"yt_dlp_version": yt_version,
|
||||||
"cookie_args": cookie_args,
|
"cookie_args": cookie_args,
|
||||||
"returncode": result.returncode,
|
"returncode": test_code,
|
||||||
"stdout_lines": result.stdout.splitlines()[:5],
|
"stdout_lines": test_stdout.splitlines()[:5],
|
||||||
"stderr_tail": result.stderr.splitlines()[-20:],
|
"stderr_tail": test_stderr.splitlines()[-20:],
|
||||||
"success": result.returncode == 0,
|
"success": test_code == 0,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -607,7 +607,7 @@ def download_subs_only(video_id: str, subtitle_langs: str) -> bool:
|
|||||||
"""Download subtitle files only (no video) for an already-downloaded video."""
|
"""Download subtitle files only (no video) for an already-downloaded video."""
|
||||||
url = f"https://www.youtube.com/watch?v={video_id}"
|
url = f"https://www.youtube.com/watch?v={video_id}"
|
||||||
output_template = str(Path(settings.download_path) / f"{video_id}.%(ext)s")
|
output_template = str(Path(settings.download_path) / f"{video_id}.%(ext)s")
|
||||||
_, _, code = _run([
|
_, _, code = _meta_run([
|
||||||
"yt-dlp", url,
|
"yt-dlp", url,
|
||||||
"--skip-download", "--no-playlist",
|
"--skip-download", "--no-playlist",
|
||||||
"--write-subs", "--write-auto-subs",
|
"--write-subs", "--write-auto-subs",
|
||||||
@@ -656,6 +656,11 @@ def fetch_video_comments(youtube_video_id: str, max_comments: int = 20) -> list[
|
|||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
|
# Don't fire a concurrent yt-dlp session while a download is running — it
|
||||||
|
# causes YouTube to see two simultaneous authenticated sessions and invalidates cookies.
|
||||||
|
if is_download_active():
|
||||||
|
return []
|
||||||
|
|
||||||
url = f"https://www.youtube.com/watch?v={youtube_video_id}"
|
url = f"https://www.youtube.com/watch?v={youtube_video_id}"
|
||||||
|
|
||||||
with tempfile.TemporaryDirectory() as tmpdir:
|
with tempfile.TemporaryDirectory() as tmpdir:
|
||||||
|
|||||||
Reference in New Issue
Block a user