自用小红书去水印_rust开源_带成品
**** Hidden Message *****
use std::io;
use std::io::copy;
use std::io::Read;
use std::fs;
use std::fs::File;
use regex::Regex;
use reqwest;
use reqwest::Client;
use libwebp::WebPDecodeRGBA;
use image::{ImageBuffer, DynamicImage, Rgba};
fn main() {
loop {
let mut url = String::new();
println!("请输入链接:");
io::stdin().read_line(&mut url).expect("读取输入时出错");
url = url.trim().to_string();
if !url.starts_with("http") {
println!("链接输入错误,应以\"http\"开头");
continue;
}
let client = Client::new();
let mut response = client
.get(&url)
.header("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9 ")
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 UBrowser/6.2.4098.3 Safari/537.36")
// 这里填你自己的小红书cookie
.header("cookie", "")
.send()
.unwrap();
let body = response.text().unwrap();
let title_re = Regex::new(r#"<title>(.*?)<"#).unwrap();
let title = title_re.captures(&body).and_then(|caps| caps.get(1)).map(|m| m.as_str());
let videos_re = Regex::new(r#","(http.*?mp4)""#).unwrap();
let video = videos_re.captures(&body).and_then(|caps| caps.get(1)).map(|m| m.as_str());
let images_re = Regex::new(r#"CRD_WM_WEBP","url":"(.*?)""#).unwrap();
let images: Vec<&str> = images_re.captures_iter(&body).map(|caps| caps.get(1).unwrap().as_str()).collect();
if let Some(title) = title {
let mut dir_name = format!("{}", title);
dir_name.retain(|c| c.is_alphanumeric() || c == '_' || c == '-');
let _ = fs::create_dir_all(&dir_name);
if let Some(video_url) = video {
let video_filename = format!("{}/{}.mp4", dir_name, title);
let v_url = video_url.replace(r"\u002F", "/");
let mut resp = reqwest::get(&v_url).unwrap();
let mut video_file = File::create(video_filename.clone()).unwrap();
copy(&mut resp, &mut video_file).unwrap();
println!("{}.mp4 ok", title);
continue;
}
let mut image_counter = 0;
for image in &images {
let image_url = image.replace(r"\u002F", "/");
let mut resp = reqwest::get(&image_url).unwrap();
let mut buffer: Vec<u8> = Vec::new();
resp.read_to_end(&mut buffer).unwrap();
let data: & = &buffer;
let (width, height, buf) = WebPDecodeRGBA(data).unwrap();
let image_buffer: ImageBuffer<Rgba<u8>, Vec<u8>> = ImageBuffer::from_vec(width, height, buf.to_vec()).unwrap();
let image = DynamicImage::ImageRgba8(image_buffer);
let image_filename = format!("{}/{}.jpg", dir_name, image_counter);
image.save(image_filename.clone()).unwrap();
println!("{}.jpg ok", image_counter);
image_counter += 1;
}
}
}
}
666666666666
页:
[1]