快手去水印解析获取源标题、作者、头像、封面图以及源视频下载地址

话不多说,直接上代码Java语言,仅供个人研究学习,请不要用于商业用途,祝大家生活愉快!

import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import com.video.dewatermark.model.Video;
import com.video.dewatermark.service.VideoService;
import lombok.extern.slf4j.Slf4j;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import java.util.HashMap;

@Slf4j
public class KuaiShouService{

    public static void main(String[] args) {
        Video video = new KuaiShouService().parseUrl("http://m.chenzhongtech.com/s/mhn5haAq/");
        System.out.println(video);
    }

    public Video parseUrl(String url) {
        HashMap headers = MapUtil.newHashMap();
        headers.put("User-Agent", "Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Mobile Safari/537.36");
        String redirectUrl = HttpUtil.createGet(url).addHeaders(headers).execute().header("Location");
        Document doc = null;
        try {
            doc = Jsoup.connect(redirectUrl).headers(headers).timeout(5000).get();
        } catch (Exception e) {
            e.printStackTrace();
        }
        Elements select1 = doc.select("div[id=hide-pagedata]");
        String resultJson = select1.get(0).attr("data-pagedata");
        log.debug(resultJson);
        JSON json = JSONUtil.parse(resultJson);
        String photoId = json.getByPath("photoId").toString();

        String param = "client_key=56c3713c&photoIds=" + photoId;

        String replace = StrUtil.replace(param, "&", "") + new String(new byte[]{50, 51, 99, 97, 97, 98, 48, 48, 51, 53, 54, 99});
        String sig = SecureUtil.md5().digestHex(replace);
        HttpResponse execute = HttpUtil.createPost("http://api.gifshow.com/rest/n/photo/info?" + param + "&sig=" + sig)
                .contentType("application/x-www-form-urlencoded").contentType("kwai-android").addHeaders(headers)
                .execute();
        String body = execute.body();
        log.debug(body);
        JSON res = JSONUtil.parse(body);
        String title = JSONUtil.getByPath(res, "photos.0.caption").toString();
        String playAddr = JSONUtil.getByPath(res, "photos.0.main_mv_url").toString();
        String cover = JSONUtil.getByPath(res, "photos.0.thumbnail_url").toString();
        String author = JSONUtil.getByPath(res, "photos.0.user_name").toString();
        String avatar = JSONUtil.getByPath(res, "photos.0.headurl").toString();
        Video video = Video.builder().title(title).author(author).avatar(avatar).coverPicture(cover).playAddr(playAddr).build();
        return video;
    }
}
import lombok.*;

@Setter
@Getter
@Builder(toBuilder = true)
@ToString
public class Video {
	// 作者
	private String author;
	// 标题
	private String title;
	// 头像
	private String avatar;
	// 封面图
	private String coverPicture;
	// 播放地址
	private String playAddr;
}

 其它产品如抖音,火山,微视等去水印就不一一发代码了。

你可能感兴趣的:(Java)