monolith/src/main.rs

44 lines
1.5 KiB
Rust
Raw Normal View History

2019-08-23 11:49:14 +02:00
#[macro_use]
2019-08-23 05:17:15 +02:00
extern crate clap;
extern crate monolith;
2019-08-23 20:24:45 +02:00
use clap::{App, Arg};
use monolith::html::{html_to_dom, print_dom, walk_and_embed_assets};
use monolith::http::{is_valid_url, retrieve_asset};
2019-08-23 05:17:15 +02:00
2019-08-23 20:33:18 +02:00
static DEFAULT_USER_AGENT: &str = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:66.0) Gecko/20100101 Firefox/66.0";
2019-08-23 05:17:15 +02:00
fn main() {
let command = App::new("monolith")
2019-08-23 11:49:14 +02:00
.version(crate_version!())
.author(crate_authors!())
.about(crate_description!())
2019-08-23 20:24:45 +02:00
.arg(
Arg::with_name("url")
.required(true)
.takes_value(true)
.index(1)
.help("URL to download"),
)
2019-08-23 10:33:30 +02:00
.args_from_usage("-j, --no-js 'Excludes JavaScript'")
.args_from_usage("-i, --no-images 'Removes images'")
2019-08-23 20:33:18 +02:00
.args_from_usage("-u, --user-agent=<Iceweasel> 'Custom User-Agent string'")
2019-08-23 05:17:15 +02:00
.get_matches();
// Process the command
let arg_target = command.value_of("url").unwrap();
2019-08-23 10:33:30 +02:00
let opt_no_js = command.is_present("no-js");
let opt_no_img = command.is_present("no-images");
2019-08-23 20:33:18 +02:00
let opt_user_agent = command.value_of("user-agent").unwrap_or(DEFAULT_USER_AGENT);
2019-08-23 05:17:15 +02:00
2019-08-23 20:24:45 +02:00
if is_valid_url(arg_target) {
2019-08-23 20:33:18 +02:00
let data = retrieve_asset(&arg_target, false, "", opt_user_agent);
2019-08-23 05:17:15 +02:00
let dom = html_to_dom(&data.unwrap());
2019-08-23 20:33:18 +02:00
walk_and_embed_assets(&arg_target, &dom.document, opt_no_js, opt_no_img, opt_user_agent);
2019-08-23 05:17:15 +02:00
2019-08-23 10:33:30 +02:00
print_dom(&dom.document);
2019-08-23 11:08:38 +02:00
println!(); // Ensure newline at end of output
2019-08-23 05:17:15 +02:00
}
}