use clap::{value_t, App, Arg};
use regex::Regex;
use std::process;
fn main() {
let matches = App::new("ph-dl")
.version("1.1.0")
.author("Miika Launiainen <miika.launiainen@gmail.com>")
.about("Get highest quality direct link to download PH videos, or download them automatically.")
.arg(
Arg::with_name("url")
.help("URL to the video")
.required(true),
)
.arg(
Arg::with_name("download")
.short("d")
.long("download")
.help("Download the video automatically"),
)
.get_matches();
let url = value_t!(matches.value_of("url"), String).unwrap();
let url = if !check_for_ph_url(&url) {
let re = Regex::new(r"ph.*").unwrap();
if !re.is_match(&url) {
eprint!("URL error");
process::exit(1);
}
format!("https://www.pornhub.com/view_video.php?viewkey={}", url)
} else {
url
};
let download = matches.is_present("download");
ph_dl::find_video(url, download);
}
fn check_for_ph_url(url: &String) -> bool {
let re = Regex::new(r"http.://(www\.)?pornhub\.com/").unwrap();
re.is_match(url)
}