Add cookie support for video processing and CLI arguments
This commit is contained in:
@@ -52,6 +52,8 @@ def summarize(args: argparse.Namespace) -> int:
|
|||||||
model=args.model,
|
model=args.model,
|
||||||
prompt_template=prompt_template,
|
prompt_template=prompt_template,
|
||||||
output_json=args.output_json,
|
output_json=args.output_json,
|
||||||
|
cookies_from_browser=args.cookies_from_browser,
|
||||||
|
cookies_file=args.cookies_file,
|
||||||
)
|
)
|
||||||
if not args.output_json:
|
if not args.output_json:
|
||||||
print(json.dumps(meta, ensure_ascii=False), flush=True)
|
print(json.dumps(meta, ensure_ascii=False), flush=True)
|
||||||
@@ -98,6 +100,14 @@ def build_parser() -> argparse.ArgumentParser:
|
|||||||
"--output-json",
|
"--output-json",
|
||||||
help="Write the result metadata to a JSON file instead of stdout",
|
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)
|
summarize_parser.set_defaults(use_whisper=True, handler=summarize)
|
||||||
|
|
||||||
translate_parser = subparsers.add_parser("translate", help="Translate an English summary")
|
translate_parser = subparsers.add_parser("translate", help="Translate an English summary")
|
||||||
|
|||||||
@@ -61,6 +61,18 @@ struct SummarizeVideoRequest {
|
|||||||
use_whisper: bool,
|
use_whisper: bool,
|
||||||
model: Option<String>,
|
model: Option<String>,
|
||||||
master_prompt: Option<String>,
|
master_prompt: Option<String>,
|
||||||
|
cookie_source: Option<YoutubeCookieSourceRequest>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
struct YoutubeCookieSourceRequest {
|
||||||
|
source_type: String,
|
||||||
|
browser: Option<String>,
|
||||||
|
profile: Option<String>,
|
||||||
|
keyring: Option<String>,
|
||||||
|
container: Option<String>,
|
||||||
|
cookies_file: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
@@ -107,6 +119,51 @@ struct OllamaModel {
|
|||||||
name: String,
|
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)]
|
#[derive(Debug)]
|
||||||
struct StoredSummary {
|
struct StoredSummary {
|
||||||
id: i64,
|
id: i64,
|
||||||
|
|||||||
@@ -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."""
|
"""Parse yt-dlp's browser cookie spec into the tuple YoutubeDL expects."""
|
||||||
if not spec:
|
if not spec:
|
||||||
return None
|
return None
|
||||||
@@ -990,6 +992,10 @@ def main():
|
|||||||
help="Prompt template for the summary LLM call.")
|
help="Prompt template for the summary LLM call.")
|
||||||
parser.add_argument('--prompt-template-file', type=str, default=None,
|
parser.add_argument('--prompt-template-file', type=str, default=None,
|
||||||
help="Path to a text file containing the prompt template.")
|
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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
use_whisper = not args.no_ai
|
use_whisper = not args.no_ai
|
||||||
@@ -1001,10 +1007,18 @@ def main():
|
|||||||
try:
|
try:
|
||||||
# If a transcript file is provided, skip the normal processing and only rewrite summary
|
# If a transcript file is provided, skip the normal processing and only rewrite summary
|
||||||
if args.transcript_file:
|
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)
|
meta = rewrite_summary(title, args.transcript_file, args.model, args.output_json, prompt_template)
|
||||||
else:
|
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 no JSON output specified, print metadata as JSON to stdout
|
||||||
if not args.output_json:
|
if not args.output_json:
|
||||||
print(json.dumps(meta, ensure_ascii=False, indent=2))
|
print(json.dumps(meta, ensure_ascii=False, indent=2))
|
||||||
|
|||||||
Reference in New Issue
Block a user