Add flag for silent mode
This commit is contained in:
parent
fddc059291
commit
2b96f9a32a
5 changed files with 25 additions and 8 deletions
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "monolith"
|
||||
version = "2.0.13"
|
||||
version = "2.0.14"
|
||||
authors = [
|
||||
"Sunshine <sunshine@uberspace.net>",
|
||||
"Mahdi Robatipoor <mahdi.robatipoor@gmail.com>",
|
||||
|
|
|
@ -25,6 +25,7 @@ If compared to saving websites with `wget -mpk`, `monolith` embeds all assets as
|
|||
### Options
|
||||
- `-i`: Remove images
|
||||
- `-j`: Exclude JavaScript
|
||||
- `-s`: Silent mode
|
||||
- `-u`: Specify custom User-Agent
|
||||
|
||||
### License
|
||||
|
|
10
src/html.rs
10
src/html.rs
|
@ -69,6 +69,7 @@ pub fn walk_and_embed_assets(
|
|||
opt_no_js: bool,
|
||||
opt_no_images: bool,
|
||||
opt_user_agent: &str,
|
||||
opt_silent: bool,
|
||||
) {
|
||||
match node.data {
|
||||
NodeData::Document => {
|
||||
|
@ -79,6 +80,7 @@ pub fn walk_and_embed_assets(
|
|||
opt_no_js,
|
||||
opt_no_images,
|
||||
opt_user_agent,
|
||||
opt_silent,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -130,6 +132,7 @@ pub fn walk_and_embed_assets(
|
|||
true,
|
||||
"",
|
||||
opt_user_agent,
|
||||
opt_silent,
|
||||
).unwrap_or(EMPTY_STRING.clone());
|
||||
attr.value.clear();
|
||||
attr.value.push_slice(favicon_datauri.as_str());
|
||||
|
@ -149,6 +152,7 @@ pub fn walk_and_embed_assets(
|
|||
true,
|
||||
"text/css",
|
||||
opt_user_agent,
|
||||
opt_silent,
|
||||
).unwrap_or(EMPTY_STRING.clone());
|
||||
attr.value.clear();
|
||||
attr.value.push_slice(css_datauri.as_str());
|
||||
|
@ -185,6 +189,7 @@ pub fn walk_and_embed_assets(
|
|||
true,
|
||||
"",
|
||||
opt_user_agent,
|
||||
opt_silent,
|
||||
).unwrap_or(EMPTY_STRING.clone());
|
||||
attr.value.clear();
|
||||
attr.value.push_slice(img_datauri.as_str());
|
||||
|
@ -210,6 +215,7 @@ pub fn walk_and_embed_assets(
|
|||
true,
|
||||
"",
|
||||
opt_user_agent,
|
||||
opt_silent,
|
||||
).unwrap_or(EMPTY_STRING.clone());
|
||||
attr.value.clear();
|
||||
attr.value.push_slice(source_datauri.as_str());
|
||||
|
@ -255,6 +261,7 @@ pub fn walk_and_embed_assets(
|
|||
true,
|
||||
"application/javascript",
|
||||
opt_user_agent,
|
||||
opt_silent,
|
||||
).unwrap_or(EMPTY_STRING.clone());
|
||||
attr.value.clear();
|
||||
attr.value.push_slice(js_datauri.as_str());
|
||||
|
@ -287,6 +294,7 @@ pub fn walk_and_embed_assets(
|
|||
false,
|
||||
"text/html",
|
||||
opt_user_agent,
|
||||
opt_silent,
|
||||
).unwrap_or(EMPTY_STRING.clone());
|
||||
let dom = html_to_dom(&iframe_data);
|
||||
walk_and_embed_assets(
|
||||
|
@ -295,6 +303,7 @@ pub fn walk_and_embed_assets(
|
|||
opt_no_js,
|
||||
opt_no_images,
|
||||
opt_user_agent,
|
||||
opt_silent,
|
||||
);
|
||||
let mut buf: Vec<u8> = Vec::new();
|
||||
serialize(&mut buf, &dom.document, SerializeOpts::default()).unwrap();
|
||||
|
@ -324,6 +333,7 @@ pub fn walk_and_embed_assets(
|
|||
opt_no_js,
|
||||
opt_no_images,
|
||||
opt_user_agent,
|
||||
opt_silent,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
11
src/http.rs
11
src/http.rs
|
@ -36,6 +36,7 @@ pub fn retrieve_asset(
|
|||
as_dataurl: bool,
|
||||
as_mime: &str,
|
||||
opt_user_agent: &str,
|
||||
opt_silent: bool
|
||||
) -> Result<String, reqwest::Error> {
|
||||
if is_data_url(&url).unwrap() {
|
||||
Ok(url.to_string())
|
||||
|
@ -49,10 +50,12 @@ pub fn retrieve_asset(
|
|||
.send()?;
|
||||
let final_url = response.url().as_str();
|
||||
|
||||
if url == final_url {
|
||||
eprintln!("[ {} ]", &url);
|
||||
} else {
|
||||
eprintln!("[ {} -> {} ]", &url, &final_url);
|
||||
if !opt_silent {
|
||||
if url == final_url {
|
||||
eprintln!("[ {} ]", &url);
|
||||
} else {
|
||||
eprintln!("[ {} -> {} ]", &url, &final_url);
|
||||
}
|
||||
}
|
||||
|
||||
if as_dataurl {
|
||||
|
|
|
@ -21,19 +21,21 @@ fn main() {
|
|||
.index(1)
|
||||
.help("URL to download"),
|
||||
)
|
||||
.args_from_usage("-j, --no-js 'Excludes JavaScript'")
|
||||
.args_from_usage("-i, --no-images 'Removes images'")
|
||||
.args_from_usage("-j, --no-js 'Excludes JavaScript'")
|
||||
.args_from_usage("-s, --silent 'Suppress verbosity'")
|
||||
.args_from_usage("-u, --user-agent=[Iceweasel] 'Custom User-Agent string'")
|
||||
.get_matches();
|
||||
|
||||
// Process the command
|
||||
let arg_target = command.value_of("url").unwrap();
|
||||
let opt_no_js = command.is_present("no-js");
|
||||
let opt_no_images = command.is_present("no-images");
|
||||
let opt_no_js = command.is_present("no-js");
|
||||
let opt_silent = command.is_present("silent");
|
||||
let opt_user_agent = command.value_of("user-agent").unwrap_or(DEFAULT_USER_AGENT);
|
||||
|
||||
if is_valid_url(arg_target) {
|
||||
let data = retrieve_asset(&arg_target, false, "", opt_user_agent).unwrap();
|
||||
let data = retrieve_asset(&arg_target, false, "", opt_user_agent, opt_silent).unwrap();
|
||||
let dom = html_to_dom(&data);
|
||||
|
||||
walk_and_embed_assets(
|
||||
|
@ -42,6 +44,7 @@ fn main() {
|
|||
opt_no_js,
|
||||
opt_no_images,
|
||||
opt_user_agent,
|
||||
opt_silent,
|
||||
);
|
||||
|
||||
print_dom(&dom.document);
|
||||
|
|
Loading…
Reference in a new issue