From bea09fd1af21f998a77804e2886465c44b102145 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Fri, 8 May 2026 02:04:39 +0200 Subject: [PATCH] Add cookie support for video processing and CLI arguments --- backend_cli.py | 10 ++++++++ src-tauri/src/main.rs | 57 +++++++++++++++++++++++++++++++++++++++++++ youtube_summarizer.py | 20 ++++++++++++--- 3 files changed, 84 insertions(+), 3 deletions(-) diff --git a/backend_cli.py b/backend_cli.py index 21ec4ec..ccce04b 100644 --- a/backend_cli.py +++ b/backend_cli.py @@ -52,6 +52,8 @@ def summarize(args: argparse.Namespace) -> int: model=args.model, prompt_template=prompt_template, output_json=args.output_json, + cookies_from_browser=args.cookies_from_browser, + cookies_file=args.cookies_file, ) if not args.output_json: print(json.dumps(meta, ensure_ascii=False), flush=True) @@ -98,6 +100,14 @@ def build_parser() -> argparse.ArgumentParser: "--output-json", help="Write the result metadata to a JSON file instead of stdout", ) + summarize_parser.add_argument( + "--cookies-from-browser", + help="Browser cookie source for yt-dlp, e.g. chrome, firefox:default, or chrome+gnomekeyring:Default", + ) + summarize_parser.add_argument( + "--cookies-file", + help="Netscape cookies.txt file to pass to yt-dlp", + ) summarize_parser.set_defaults(use_whisper=True, handler=summarize) translate_parser = subparsers.add_parser("translate", help="Translate an English summary") diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 73ebcc2..c05e5a4 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -61,6 +61,18 @@ struct SummarizeVideoRequest { use_whisper: bool, model: Option, master_prompt: Option, + cookie_source: Option, +} + +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +struct YoutubeCookieSourceRequest { + source_type: String, + browser: Option, + profile: Option, + keyring: Option, + container: Option, + cookies_file: Option, } #[derive(Debug, Deserialize)] @@ -107,6 +119,51 @@ struct OllamaModel { name: String, } +#[derive(Clone, Copy, Debug, Serialize)] +struct YoutubeCookieBrowserOption { + id: &'static str, + label: &'static str, +} + +const YOUTUBE_COOKIE_BROWSER_OPTIONS: &[YoutubeCookieBrowserOption] = &[ + YoutubeCookieBrowserOption { + id: "chrome", + label: "Google Chrome", + }, + YoutubeCookieBrowserOption { + id: "firefox", + label: "Firefox", + }, + YoutubeCookieBrowserOption { + id: "safari", + label: "Safari", + }, + YoutubeCookieBrowserOption { + id: "edge", + label: "Microsoft Edge", + }, + YoutubeCookieBrowserOption { + id: "brave", + label: "Brave", + }, + YoutubeCookieBrowserOption { + id: "chromium", + label: "Chromium", + }, + YoutubeCookieBrowserOption { + id: "vivaldi", + label: "Vivaldi", + }, + YoutubeCookieBrowserOption { + id: "opera", + label: "Opera", + }, + YoutubeCookieBrowserOption { + id: "whale", + label: "Naver Whale", + }, +]; + #[derive(Debug)] struct StoredSummary { id: i64, diff --git a/youtube_summarizer.py b/youtube_summarizer.py index ae0603d..0a3b0bc 100644 --- a/youtube_summarizer.py +++ b/youtube_summarizer.py @@ -275,7 +275,9 @@ YOUTUBE_AUTH_ERROR_MARKERS = ( ) -def parse_cookies_from_browser_spec(spec: Optional[str]) -> Optional[Tuple[Optional[str], Optional[str], Optional[str], Optional[str]]]: +def parse_cookies_from_browser_spec( + spec: Optional[str], +) -> Optional[Tuple[Optional[str], Optional[str], Optional[str], Optional[str]]]: """Parse yt-dlp's browser cookie spec into the tuple YoutubeDL expects.""" if not spec: return None @@ -990,6 +992,10 @@ def main(): help="Prompt template for the summary LLM call.") parser.add_argument('--prompt-template-file', type=str, default=None, help="Path to a text file containing the prompt template.") + parser.add_argument('--cookies-from-browser', type=str, default=None, + help="Browser cookie source to pass to yt-dlp.") + parser.add_argument('--cookies-file', type=str, default=None, + help="Netscape cookies.txt file to pass to yt-dlp.") args = parser.parse_args() use_whisper = not args.no_ai @@ -1001,10 +1007,18 @@ def main(): try: # If a transcript file is provided, skip the normal processing and only rewrite summary if args.transcript_file: - vid, title, _ = fetch_video_metadata(args.url) + vid, title, _ = fetch_video_metadata(args.url, args.cookies_from_browser, args.cookies_file) meta = rewrite_summary(title, args.transcript_file, args.model, args.output_json, prompt_template) else: - meta = process_video(args.url, use_whisper, args.model, args.output_json, prompt_template) + meta = process_video( + args.url, + use_whisper, + args.model, + args.output_json, + prompt_template, + args.cookies_from_browser, + args.cookies_file, + ) # If no JSON output specified, print metadata as JSON to stdout if not args.output_json: print(json.dumps(meta, ensure_ascii=False, indent=2))