import java.util.regex.Pattern;
/**
-
快手去水印
-
@author taishan
-
@version 1.0
-
@date 2020/8/4
-
@since JDK1.8
*/
@Slf4j
public class KuaiShou {
//视频保存目录
private static final String videoSavePath=“d:/快手视频/”;
//分享链接(手动修改)
private static String targetPath = “奇怪,刚刚和妈妈的衣架子交心攀谈后,怎么感觉头上有一圈星星呢~ http://v.kuaishou.com/s/mhn5haAq 复制此链接,打开【快手App】直接观看!”;
public static void main(String[] args) {
parseUrl(filterUrl(targetPath));
}
/**
-
方法描述: 解析下载视频
-
@param url
-
@author tarzan
-
@date 2020年08月04日 10:33:40
*/
public static void ksParseUrl(String url) {
HashMap<String, String> 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”);
String body= HttpUtil.createGet(redirectUrl).addHeaders(headers).execute().body();
Document doc= Jsoup.parse(body);
Elements videoElement = doc.select(“script[type=text/javascript]”);
String videoInfo = videoElement.get(3).data().replaceAll(“window.pageData= “,””);
JSONObject json =JSONObject.parseObject(videoInfo);
String title = json.getJSONObject(“video”).getString(“caption”);
String videoUrl=json.getJSONObject(“video”).getString(“srcNoMark”);
videoUrl=videoUrl.substring(0,videoUrl.indexOf(“?”));
log.debug(videoUrl);
log.debug(title);
downVideo(videoUrl,title,“快手视频”);
}
/**
-
方法描述: 下载视频到本地
-
@param httpUrl
-
@param saveFile
-
@author tarzan
-
@date 2020年08月04日 10:34:09
*/
public static void downVideo(String httpUrl, String saveFile) {
int byteRead;
try {
URL url = new URL(httpUrl);
//获取链接
URLConnection conn = url.openConnection();
//输入流
InputStream inStream = conn.getInputStream();
//封装一个保存文件的路径对象
File fileSavePath = new File(saveFile);
//注:如果保存文件夹不存在,那么则创建该文件夹
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());
} catch (FileNotFoundException e) {
log.error(e.getMessage());
} catch (IOException e) {
log.error(e.getMessage());
}
}
/**
总结
我们总是喜欢瞻仰大厂的大神们,但实际上大神也不过凡人,与菜鸟程序员相比,也就多花了几分心思,如果你再不努力,差距也只会越来越大。实际上,作为程序员,丰富自己的知识储备,提升自己的知识深度和广度是很有必要的。
Mybatis源码解析

1804892953)(image-https://i-blog.csdnimg.cn/blog_migrate/38e5a57660282b55905517d7d28f61b1.png)(title-必看视频!获取2024年最新Java开发全套学习资料 备注Java)]
imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)