|
|
@@ -1,9 +1,14 @@
|
|
|
package cn.reghao.dfs.store.task;
|
|
|
|
|
|
+import cn.reghao.dfs.store.db.mapper.ImageFileMapper;
|
|
|
+import cn.reghao.dfs.store.db.mapper.ImageUrlMapper;
|
|
|
import cn.reghao.dfs.store.db.mapper.VideoUrlMapper;
|
|
|
import cn.reghao.dfs.store.db.repository.ObjectRepository;
|
|
|
+import cn.reghao.dfs.store.model.po.ImageFile;
|
|
|
import cn.reghao.dfs.store.model.po.VideoUrl;
|
|
|
+import cn.reghao.dfs.store.model.vo.ImageObject;
|
|
|
import cn.reghao.jutil.media.FFmpegWrapper;
|
|
|
+import cn.reghao.jutil.media.ImageOps;
|
|
|
import cn.reghao.jutil.media.model.AudioProps;
|
|
|
import cn.reghao.jutil.media.model.MediaProps;
|
|
|
import cn.reghao.jutil.media.model.VideoProps;
|
|
|
@@ -13,63 +18,84 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
+import java.io.File;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author reghao
|
|
|
* @date 2023-08-29 18:03:39
|
|
|
*/
|
|
|
@Slf4j
|
|
|
-//@Service
|
|
|
+@Service
|
|
|
@Deprecated
|
|
|
public class VideoUrlUpdater {
|
|
|
- //@Autowired
|
|
|
- VideoUrlMapper videoUrlMapper;
|
|
|
- //@Autowired
|
|
|
+ @Autowired
|
|
|
+ ImageFileMapper imageFileMapper;
|
|
|
+ @Autowired
|
|
|
+ ImageUrlMapper imageUrlMapper;
|
|
|
+ @Autowired
|
|
|
ObjectRepository objectRepository;
|
|
|
|
|
|
//@PostConstruct
|
|
|
public void update() {
|
|
|
log.info("开始更新 VideoUrl...");
|
|
|
|
|
|
- List<VideoUrl> list = videoUrlMapper.findAll();
|
|
|
- for (VideoUrl videoUrl : list) {
|
|
|
- String objectId = videoUrl.getObjectId();
|
|
|
- ObjectMeta objectMeta = objectRepository.getObjectMetaById(objectId);
|
|
|
- String objectName = objectMeta.getObjectName();
|
|
|
- String absolutePath = objectMeta.getAbsolutePath();
|
|
|
+ List<ImageObject> list = imageFileMapper.findAll1();
|
|
|
+ Set<String> ids = list.stream().map(ImageObject::getImageFileId).collect(Collectors.toSet());
|
|
|
|
|
|
- MediaProps mediaProps = FFmpegWrapper.getMediaProps(absolutePath);
|
|
|
- if (mediaProps == null) {
|
|
|
- log.info("{} 的 FFmpeg 媒体信息为 null", objectName);
|
|
|
- continue;
|
|
|
+ List<ImageObject> list1 = imageUrlMapper.findAll1();
|
|
|
+ //Set<String> ids = list1.stream().map(ImageObject::getImageFileId).collect(Collectors.toSet());
|
|
|
+
|
|
|
+ List<ImageObject> notExist = new ArrayList<>();
|
|
|
+ list1.forEach(imageObject -> {
|
|
|
+ if (!ids.contains(imageObject.getImageFileId())) {
|
|
|
+ notExist.add(imageObject);
|
|
|
}
|
|
|
+ });
|
|
|
|
|
|
- VideoProps videoProps = mediaProps.getVideoProps();
|
|
|
- if (videoProps == null) {
|
|
|
- log.info("{} 的 FFmpeg 视频信息为 null", objectName);
|
|
|
+ List<ImageFile> imageFiles = new ArrayList<>();
|
|
|
+ /*for (ImageObject imageObject : notExist) {
|
|
|
+ String imageFileId = imageObject.getImageFileId();
|
|
|
+ String objectId = imageObject.getObjectId();
|
|
|
+ ObjectMeta objectMeta = objectRepository.getObjectMetaById(objectId);
|
|
|
+ if (objectMeta == null) {
|
|
|
+ log.error("object {} not exist", objectId);
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- String videoCodec = mediaProps.getVideoProps().getCodecName();
|
|
|
- String audioCodec = null;
|
|
|
- AudioProps audioProps1 = mediaProps.getAudioProps();
|
|
|
- if (audioProps1 != null) {
|
|
|
- audioCodec = audioProps1.getCodecName();
|
|
|
+ String absolutePath = objectMeta.getAbsolutePath();
|
|
|
+ File file = new File(absolutePath);
|
|
|
+ if (!file.exists()) {
|
|
|
+ log.error("file {} not exist", absolutePath);
|
|
|
+ continue;
|
|
|
}
|
|
|
|
|
|
- String qualityStr = videoUrl.getQualityStr();
|
|
|
- String qualityStr1 = qualityStr.replace("p", "");
|
|
|
- int quality = Integer.parseInt(qualityStr1);
|
|
|
-
|
|
|
- videoUrl.setVideoCodec(videoCodec);
|
|
|
- videoUrl.setAudioCodec(audioCodec);
|
|
|
- videoUrl.setQuality(quality);
|
|
|
- videoUrlMapper.update(videoUrl);
|
|
|
+ try {
|
|
|
+ ImageOps.Size size = ImageOps.info(file);
|
|
|
+ int width = size.getWidth();
|
|
|
+ int height = size.getHeight();
|
|
|
+ ImageFile imageFile = new ImageFile(imageFileId, width, height);
|
|
|
+ imageFiles.add(imageFile);
|
|
|
|
|
|
- log.info("{} 的 VideoUrl 已更新", objectName);
|
|
|
+ if (imageFiles.size() > 10_000) {
|
|
|
+ imageFileMapper.saveAll(imageFiles);
|
|
|
+ log.info("持久化 {} 个 ImageFile", imageFiles.size());
|
|
|
+ imageFiles.clear();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ if (imageFiles.size() > 0) {
|
|
|
+ imageFileMapper.saveAll(imageFiles);
|
|
|
+ log.info("持久化 {} 个 ImageFile", imageFiles.size());
|
|
|
+ imageFiles.clear();
|
|
|
+ }*/
|
|
|
+
|
|
|
log.info("VideoUrl 更新完成...");
|
|
|
}
|
|
|
}
|