hanimers/src/main.rs

79 lines
2.5 KiB
Rust
Raw Normal View History

2021-02-02 16:52:15 +00:00
mod commands;
mod structs;
2022-04-30 11:30:36 +00:00
mod unescape;
2021-02-02 16:52:15 +00:00
mod utils;
2022-04-30 11:30:36 +00:00
use clap::{Arg, Command};
2021-02-02 16:52:15 +00:00
extern crate tokio;
fn main() {
2022-04-30 11:30:36 +00:00
let matches = Command::new("hanimers")
2021-02-02 16:52:15 +00:00
.about("hanime.tv downloader in rust")
2021-02-04 04:43:14 +00:00
.version(env!("CARGO_PKG_VERSION"))
2022-04-30 11:30:36 +00:00
.subcommand_required(true)
2021-02-02 16:52:15 +00:00
.subcommand(
2022-04-30 11:30:36 +00:00
Command::new("search")
2021-02-02 16:52:15 +00:00
.arg(
2022-04-30 11:30:36 +00:00
Arg::new("tags")
2021-02-02 16:52:15 +00:00
.long("tags")
2022-04-30 11:30:36 +00:00
.short('t')
2021-02-02 16:52:15 +00:00
.takes_value(true)
2022-04-30 11:30:36 +00:00
.use_value_delimiter(true)
.ignore_case(true)
.possible_values(commands::AVALIABLE_TAGS)
2021-02-02 16:52:15 +00:00
).arg(
2022-04-30 11:30:36 +00:00
Arg::new("broad")
2021-02-02 16:52:15 +00:00
.long("broad")
2022-04-30 11:30:36 +00:00
.short('b')
2021-02-02 16:52:15 +00:00
.help("More results, but less accurate. Videos will match if they contain any selected tag rather than all selected tags.")
).arg(
2022-04-30 11:30:36 +00:00
Arg::new("query")
2021-02-02 16:52:15 +00:00
.takes_value(true)
2022-04-30 11:30:36 +00:00
.multiple_values(true)
2021-02-02 16:52:15 +00:00
.help("Search query")
)
)
.subcommand(
2022-04-30 11:30:36 +00:00
Command::new("view")
.visible_aliases(&["info", "show"])
2021-02-02 16:52:15 +00:00
.arg(
2022-04-30 11:30:36 +00:00
Arg::new("id")
2021-02-02 16:52:15 +00:00
.takes_value(true)
2022-04-30 11:30:36 +00:00
.multiple_values(true)
2021-02-02 16:52:15 +00:00
.required(true)
)
)
.subcommand(
2022-04-30 11:30:36 +00:00
Command::new("download")
.visible_alias("dl")
2021-02-02 16:52:15 +00:00
.arg(
2022-04-30 11:30:36 +00:00
Arg::new("print")
2021-02-02 16:52:15 +00:00
.long("print")
2022-04-30 11:30:36 +00:00
.short('p')
2021-02-02 16:52:15 +00:00
.help("Print the URL to download only")
).arg(
2022-04-30 11:30:36 +00:00
Arg::new("resolution")
2021-02-02 16:52:15 +00:00
.long("resolution")
2022-04-30 11:30:36 +00:00
.short('r')
2021-02-02 16:52:15 +00:00
.help("Set preferred resolution")
.takes_value(true)
).arg(
2022-04-30 11:30:36 +00:00
Arg::new("id")
2021-02-02 16:52:15 +00:00
.takes_value(true)
2022-04-30 11:30:36 +00:00
.multiple_values(true)
2021-02-02 16:52:15 +00:00
.required(true)
)
)
.get_matches();
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap();
match matches.subcommand() {
2022-04-30 11:30:36 +00:00
Some(("search", sub_m)) => runtime.block_on(commands::search(sub_m)),
Some(("view", sub_m)) => runtime.block_on(commands::view(sub_m)),
Some(("download", sub_m)) => runtime.block_on(commands::download(sub_m)),
_ => unreachable!("subcommand_required do your job please"),
2021-02-02 16:52:15 +00:00
};
}