feat:微博视频保存
This commit is contained in:
parent
e60b827baa
commit
2cbce1a574
|
|
@ -3,6 +3,8 @@
|
||||||
refresh=5
|
refresh=5
|
||||||
## 保存微博图片
|
## 保存微博图片
|
||||||
saveWeiBoImages=true
|
saveWeiBoImages=true
|
||||||
|
## 保存微博视频
|
||||||
|
saveWeiBoVideo=true
|
||||||
## 上传图片到AList
|
## 上传图片到AList
|
||||||
uploadAList=false
|
uploadAList=false
|
||||||
## AList Url
|
## AList Url
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ public interface AppConstant {
|
||||||
*/
|
*/
|
||||||
String RSS_CONFIG_PATH = System.getProperty("user.dir") + "/config/data.json";
|
String RSS_CONFIG_PATH = System.getProperty("user.dir") + "/config/data.json";
|
||||||
String IMAGES_PATH = System.getProperty("user.dir") + "/images/";
|
String IMAGES_PATH = System.getProperty("user.dir") + "/images/";
|
||||||
|
String VIDEO_PATH = System.getProperty("user.dir") + "/video/";
|
||||||
|
|
||||||
String SET_SYSTEM = "system";
|
String SET_SYSTEM = "system";
|
||||||
String SET_MAIL = "mail";
|
String SET_MAIL = "mail";
|
||||||
|
|
@ -36,6 +37,11 @@ public interface AppConstant {
|
||||||
*/
|
*/
|
||||||
String SAVE_WEIBO_IMAGES = "saveWeiBoImages";
|
String SAVE_WEIBO_IMAGES = "saveWeiBoImages";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存微博视频
|
||||||
|
*/
|
||||||
|
String SAVE_WEIBO_VIDEO = "saveWeiBoVideo";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传图片到AList
|
* 上传图片到AList
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,19 @@ public class HtmlUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static HttpResponse getWeiBoVideoHttpRequest(String url) {
|
||||||
|
try {
|
||||||
|
HttpRequest request = HttpRequest.get(url)
|
||||||
|
.header(Header.REFERER, "https://weibo.com/")
|
||||||
|
.header(Header.USER_AGENT, USER_AGENT)
|
||||||
|
.timeout(20000);
|
||||||
|
return request.executeAsync();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("获取视频数据异常:", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据正则获取html中的内容
|
* 根据正则获取html中的内容
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,9 @@ public class FileMonitor {
|
||||||
"## 配置订阅频率\n" +
|
"## 配置订阅频率\n" +
|
||||||
"refresh = 5\n" +
|
"refresh = 5\n" +
|
||||||
"## 保存微博图片\n" +
|
"## 保存微博图片\n" +
|
||||||
"saveWeiBoImages=false\n" +
|
"saveWeiBoImages=false" +
|
||||||
|
"## 保存微博视频\n" +
|
||||||
|
"saveWeiBoVideo=true\n" +
|
||||||
"## 上传图片到AList\n" +
|
"## 上传图片到AList\n" +
|
||||||
"uploadAList=false\n" +
|
"uploadAList=false\n" +
|
||||||
"## AList Url\n" +
|
"## AList Url\n" +
|
||||||
|
|
|
||||||
|
|
@ -114,18 +114,16 @@ public class RssJob {
|
||||||
private void saveWeiBoImagesOrUpdateAList(List<RssEntity> list) {
|
private void saveWeiBoImagesOrUpdateAList(List<RssEntity> list) {
|
||||||
Setting setting = new Setting(CONFIG_PATH, CharsetUtil.CHARSET_UTF_8, true);
|
Setting setting = new Setting(CONFIG_PATH, CharsetUtil.CHARSET_UTF_8, true);
|
||||||
Setting systemSetting = setting.getSetting(SET_SYSTEM);
|
Setting systemSetting = setting.getSetting(SET_SYSTEM);
|
||||||
Boolean saveImages = Boolean.valueOf(systemSetting.get(SAVE_WEIBO_IMAGES));
|
boolean saveImages = Boolean.parseBoolean(systemSetting.get(SAVE_WEIBO_IMAGES));
|
||||||
Boolean uploadAList = Boolean.valueOf(systemSetting.get(UPLOAD_ALIST));
|
boolean saveVideo = Boolean.valueOf(systemSetting.get(SAVE_WEIBO_VIDEO));
|
||||||
|
boolean uploadAList = Boolean.valueOf(systemSetting.get(UPLOAD_ALIST));
|
||||||
if (saveImages) {
|
if (saveImages) {
|
||||||
// 保存图片
|
// 保存图片
|
||||||
list.forEach(obj -> {
|
list.forEach(obj -> {
|
||||||
List<String> imgList = HtmlUtils.extractImageUrls(obj.getDescription());
|
List<String> imgList = HtmlUtils.extractImageUrls(obj.getDescription());
|
||||||
imgList.forEach(imgObj -> {
|
imgList.forEach(imgObj -> {
|
||||||
if (imgObj.contains("sinaimg") && !imgObj.contains("timeline_card") && !imgObj.contains("qixi2018")) {
|
if (imgObj.contains("sinaimg") && !imgObj.contains("timeline_card") && !imgObj.contains("qixi2018")) {
|
||||||
int lastSlashIndex = imgObj.lastIndexOf('/');
|
String fileName = HtmlUtils.getFileName(imgObj);
|
||||||
// 如果找到了斜杠,就从斜杠后面截取字符串
|
|
||||||
String fileName = imgObj.substring(lastSlashIndex + 1);
|
|
||||||
//log.info("微博图片文件名:{}", fileName);
|
|
||||||
HttpResponse weiBoImagesHttpRequest = HtmlUtils.getWeiBoImagesHttpRequest(fileName);
|
HttpResponse weiBoImagesHttpRequest = HtmlUtils.getWeiBoImagesHttpRequest(fileName);
|
||||||
byte[] bytes = weiBoImagesHttpRequest.bodyBytes();
|
byte[] bytes = weiBoImagesHttpRequest.bodyBytes();
|
||||||
FileUtil.writeBytes(bytes, new File(IMAGES_PATH + fileName));
|
FileUtil.writeBytes(bytes, new File(IMAGES_PATH + fileName));
|
||||||
|
|
@ -136,6 +134,23 @@ public class RssJob {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if(saveVideo){
|
||||||
|
// 保存视频
|
||||||
|
list.forEach(obj -> {
|
||||||
|
List<String> videoList = HtmlUtils.extractVideoUrls(obj.getDescription());
|
||||||
|
if(CollUtil.isNotEmpty(videoList)){
|
||||||
|
videoList.forEach(videoObj -> {
|
||||||
|
String fileName = HtmlUtils.getFileName(videoObj);
|
||||||
|
HttpResponse weiBoImagesHttpRequest = HtmlUtils.getWeiBoVideoHttpRequest(videoObj);
|
||||||
|
byte[] bytes = weiBoImagesHttpRequest.bodyBytes();
|
||||||
|
FileUtil.writeBytes(bytes, new File(VIDEO_PATH + fileName));
|
||||||
|
if (uploadAList) {
|
||||||
|
AListUtils.uploadFile(bytes, fileName);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue