找回密码
 立即注册
查看: 481|回复: 1

[C/C++] 自用小红书去水印_rust开源_带成品

[复制链接]
发表于 2023-9-26 12:46:29 | 显示全部楼层 |阅读模式
xx.png

游客,如果您要查看本帖隐藏内容请回复


[C++] 纯文本查看 复制代码
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: &[u8] = &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;
            }
        }
    }
}





上一篇:golang-南华期货js解密.链接websocket
下一篇:蓝奏云直链提取+短链生成+源码
回复

使用道具 举报

发表于 2023-10-20 00:36:50 | 显示全部楼层
666666666666
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|27CaT资源论坛

GMT+8, 2024-11-22 13:37

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表