use std::time::Duration;
use parse_book_source::{BookSource, BrowserFetcher, BrowserOptions, Engine, FetchMode};
pub fn authorized() -> bool {
crate::utils::novel_catch_dir()
.map(|d| d.join("browser_assist.on").exists())
.unwrap_or(false)
}
fn browser_options() -> BrowserOptions {
let mut opts = BrowserOptions::default();
if let Ok(dir) = crate::utils::novel_catch_dir() {
opts.profile_dir = dir.join("browser-profile");
}
opts.total_timeout = Duration::from_secs(90);
opts
}
pub fn build_engine(source: BookSource) -> parse_book_source::Result<Engine> {
let allow = !matches!(source.http.fetcher, FetchMode::Reqwest) && authorized();
if allow && let Some(browser) = BrowserFetcher::detect(browser_options()) {
Engine::with_browser_assist(source, Some(browser))
} else {
Engine::new(source)
}
}