本帖最后由 三木猿 于 2020-9-14 09:57 编辑
上一条帖子进行了简单的分析
去抖音水印简单分析教程
https://www.52pojie.cn/thread-1262959-1-1.html
有什么不对的地方请大佬们指教
[XML] 纯文本查看 复制代码
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.11.2</version>
</dependency>
[Java] 纯文本查看 复制代码
import cn.hutool.core.map.MapUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;import org.jsoup.Connection;
import org.jsoup.Jsoup;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
/**
* [url=home.php?mod=space&uid=686208]@AuThor[/url] 三木猿
* [url=home.php?mod=space&uid=1248337]@version[/url] 1.0
* @Title:
* [url=home.php?mod=space&uid=686237]@date[/url] 2020/9/7 10:43
*/
public class test2 {
public static void main(String[] args) throws Exception {
String url = "https://v.douyin.com/JB9Fveb/";
final String videoPath = "https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=";
Connection con = Jsoup.connect(url);
con.header("User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 12_1_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/16D57 Version/12.0 Safari/604.1");
Connection.Response resp = con.method(Connection.Method.GET).execute();
String strUrl = resp.url().toString();
String itemId = strUrl.substring(strUrl.indexOf("video/"), strUrl.lastIndexOf("/")).replace("video/", "");
String videoUrl = videoPath + itemId;
String jsonStr = Jsoup.connect(videoUrl).ignoreContentType(true).execute().body();
JSONObject json =new JSONObject(jsonStr);
String videoAddress = json.getJSONArray("item_list").getJSONObject(0).getJSONObject("video").getJSONObject("play_addr").getJSONArray("url_list").get(0).toString();
HashMap headers = MapUtil.newHashMap();
headers.put("User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 12_1_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/16D57 Version/12.0 Safari/604.1");
String finalVideoAddress = HttpUtil.createGet(videoAddress).addHeaders(headers).execute().header("Location");
downloadVideo(finalVideoAddress);
}
private static void downloadVideo(String videoAddress) throws Exception {
int byteRead;
URL url = new URL(videoAddress);
//获取链接
URLConnection conn = url.openConnection();
//输入流
InputStream inStream = conn.getInputStream();
//封装一个保存文件的路径对象
File fileSavePath = new File("d:\\SanMu\\1.mp4");
//注:如果保存文件夹不存在,那么则创建该文件夹
File fileParent = fileSavePath.getParentFile();
if (!fileParent.exists()) {
fileParent.mkdirs();
}
//写入文件
FileOutputStream fs = new FileOutputStream(fileSavePath);
byte[] buffer = new byte[1024];
while ((byteRead = inStream.read(buffer)) != -1) {
fs.write(buffer, 0, byteRead);
}
inStream.close();
fs.close();
System.out.println("\n-----视频保存路径-----\n" + fileSavePath.getAbsolutePath());
}
}
|