新增视频封面的记录与下载
This commit is contained in:
@@ -70,6 +70,11 @@ public class RssSyncReconciler implements Reconciler<RssSyncReconciler.Request>,
|
||||
Pattern.CASE_INSENSITIVE
|
||||
);
|
||||
|
||||
private static final Pattern VIDEO_POSTER_PATTERN = Pattern.compile(
|
||||
"<video[^>]*?poster\\s*=\\s*(['\"])(.*?)\\1[^>]*?>",
|
||||
Pattern.CASE_INSENSITIVE
|
||||
);
|
||||
|
||||
private static final Pattern MW2000_IMAGE_FILE_PATTERN = Pattern.compile(
|
||||
".*/mw2000/([^/?#]+)(?:[?#].*)?$",
|
||||
Pattern.CASE_INSENSITIVE
|
||||
@@ -238,7 +243,7 @@ public class RssSyncReconciler implements Reconciler<RssSyncReconciler.Request>,
|
||||
friendPostSpec.setLinkName(linkName);
|
||||
String description = friendPost.getSpec().getDescription();
|
||||
|
||||
// 先提取图片文件名覆盖标题,再将 HTML 描述转换为纯文本
|
||||
// 先提取图片和视频 poster 文件名覆盖标题,再将 HTML 描述转换为纯文本
|
||||
if (StringUtils.isNotEmpty(description)) {
|
||||
List<String> imageFileNames = new ArrayList<>();
|
||||
Matcher matcher = IMG_SRC_PATTERN.matcher(description);
|
||||
@@ -250,6 +255,15 @@ public class RssSyncReconciler implements Reconciler<RssSyncReconciler.Request>,
|
||||
}
|
||||
}
|
||||
|
||||
Matcher posterMatcher = VIDEO_POSTER_PATTERN.matcher(description);
|
||||
while (posterMatcher.find()) {
|
||||
String posterSrc = posterMatcher.group(2);
|
||||
String posterFileName = extractFileNameFromUrl(posterSrc);
|
||||
if (StringUtils.isNotBlank(posterFileName)) {
|
||||
imageFileNames.add(posterFileName);
|
||||
}
|
||||
}
|
||||
|
||||
if (enableWeiboImageRecordAndDownload && !imageFileNames.isEmpty()) {
|
||||
String imageFiles = String.join(",", imageFileNames);
|
||||
friendPostSpec.setImageFiles(imageFiles);
|
||||
@@ -413,6 +427,26 @@ public class RssSyncReconciler implements Reconciler<RssSyncReconciler.Request>,
|
||||
return imageReferer.trim();
|
||||
}
|
||||
|
||||
private String extractFileNameFromUrl(String url) {
|
||||
if (StringUtils.isBlank(url)) {
|
||||
return null;
|
||||
}
|
||||
String sanitizedUrl = url.trim();
|
||||
int queryIndex = sanitizedUrl.indexOf('?');
|
||||
if (queryIndex >= 0) {
|
||||
sanitizedUrl = sanitizedUrl.substring(0, queryIndex);
|
||||
}
|
||||
int fragmentIndex = sanitizedUrl.indexOf('#');
|
||||
if (fragmentIndex >= 0) {
|
||||
sanitizedUrl = sanitizedUrl.substring(0, fragmentIndex);
|
||||
}
|
||||
int lastSlashIndex = sanitizedUrl.lastIndexOf('/');
|
||||
if (lastSlashIndex < 0 || lastSlashIndex == sanitizedUrl.length() - 1) {
|
||||
return null;
|
||||
}
|
||||
return sanitizedUrl.substring(lastSlashIndex + 1);
|
||||
}
|
||||
|
||||
static int pageNullSafe(Integer page) {
|
||||
return ObjectUtils.defaultIfNull(page, 1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user