|
@@ -92,6 +92,7 @@ public class EtlServiceImpl implements EtlService {
|
|
|
private final CrawlerVideoExtMapper crawlerVideoExtMapper;
|
|
|
private final CrawlerUserV3Mapper crawlerUserV3Mapper;
|
|
|
|
|
|
+
|
|
|
@Value("${download.file.path:/data/crawler/videos}")
|
|
|
private String downloadPath;
|
|
|
@Value("${aliyun.oss.video.bucket:art-pubbucket}")
|
|
@@ -120,9 +121,11 @@ public class EtlServiceImpl implements EtlService {
|
|
|
|
|
|
private Executor pool;
|
|
|
|
|
|
+ private final String defaultFilePath = "/data";
|
|
|
+
|
|
|
public EtlServiceImpl(StrategyHandlerService strategyHandlerService, AliyunOssManager aliyunOssManager,
|
|
|
- LongVideoFeign longVideoFeign, CrawlerVideoMapper crawlerVideoMapper, SlsService slsService,
|
|
|
- CrawlerVideoExtMapper crawlerVideoExtMapper, CrawlerUserV3Mapper crawlerUserV3Mapper) {
|
|
|
+ LongVideoFeign longVideoFeign, CrawlerVideoMapper crawlerVideoMapper, SlsService slsService,
|
|
|
+ CrawlerVideoExtMapper crawlerVideoExtMapper, CrawlerUserV3Mapper crawlerUserV3Mapper) {
|
|
|
this.strategyHandlerService = strategyHandlerService;
|
|
|
this.aliyunOssManager = aliyunOssManager;
|
|
|
this.longVideoFeign = longVideoFeign;
|
|
@@ -139,9 +142,9 @@ public class EtlServiceImpl implements EtlService {
|
|
|
long id = 0L;
|
|
|
try {
|
|
|
// 参数校验
|
|
|
- String errorMessage = CustomValidator.validate(param);
|
|
|
- if (!Strings.isNullOrEmpty(errorMessage)) {
|
|
|
- log.error("param validate failed. {}", errorMessage);
|
|
|
+ CustomValidator.Result result = CustomValidator.validate(param);
|
|
|
+ if (result.notSuccess()) {
|
|
|
+ log.error("param validate failed. {}", result.getMessage());
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -181,9 +184,16 @@ public class EtlServiceImpl implements EtlService {
|
|
|
log.error("etl server deal {} failed.", param, e);
|
|
|
// 回滚数据
|
|
|
if (id > 0) {
|
|
|
- crawlerVideoMapper.deleteByPrimaryKey(id);
|
|
|
+ try {
|
|
|
+ int i = crawlerVideoMapper.deleteByPrimaryKey(id);
|
|
|
+ if (i <= 0) {
|
|
|
+ log.error("delete data from db failed of {}", id);
|
|
|
+ }
|
|
|
+ } catch (Exception e1) {
|
|
|
+ log.error("delete data from db failed of {}", id, e1);
|
|
|
+ }
|
|
|
}
|
|
|
- throw new CommonException(ExceptionEnum.SYSTEM_ERROR, "etl server deal error: " + e.getMessage());
|
|
|
+ // throw new CommonException(ExceptionEnum.SYSTEM_ERROR, "etl server deal error: " + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -307,10 +317,10 @@ public class EtlServiceImpl implements EtlService {
|
|
|
String strategy = data.getStrategy();
|
|
|
String audioUrl = data.getAudioUrl();
|
|
|
|
|
|
- String videoPath = urlDownload(data.getVideoUrl(), "longvideo/crawler_local/video", title);
|
|
|
+ String videoPath = urlDownload(data.getVideoUrl(), "longvideo/crawler_local/video", title, data.getOutVideoId());
|
|
|
// 音、视频合成
|
|
|
if (!Strings.isNullOrEmpty(audioUrl)) {
|
|
|
- String audioPath = urlDownload(data.getAudioUrl(), "longvideo/crawler_local/audio", title);
|
|
|
+ String audioPath = urlDownload(data.getAudioUrl(), "longvideo/crawler_local/audio", title, data.getOutVideoId());
|
|
|
retryFunc(t -> {
|
|
|
try {
|
|
|
VideoUtils.videoSynthesis(ffmpegPath, downloadPath + File.separator + t,
|
|
@@ -347,7 +357,7 @@ public class EtlServiceImpl implements EtlService {
|
|
|
Files.deleteIfExists(Paths.get(new File(tempFilePath).getPath()));
|
|
|
|
|
|
// 视频封面下载、上传 OSS
|
|
|
- String coverPath = urlDownload(data.getCoverUrl(), "longvideo/crawler_local/image", title);
|
|
|
+ String coverPath = urlDownload(data.getCoverUrl(), "longvideo/crawler_local/image", title, data.getOutVideoId());
|
|
|
file2oss(downloadPath + File.separator + coverPath, coverPath, platform, strategy);
|
|
|
data.setCoverOssPath(coverPath);
|
|
|
tempFilePath = downloadPath + File.separator + coverPath;
|
|
@@ -357,21 +367,24 @@ public class EtlServiceImpl implements EtlService {
|
|
|
Files.deleteIfExists(Paths.get(new File(tempFilePath).getPath()));
|
|
|
}
|
|
|
|
|
|
- private String urlDownload(String fileUrl, String filePath, String title) {
|
|
|
- String titleMmd5 = MD5Util.md5(title);
|
|
|
+ private String urlDownload(String fileUrl, String filePath, String title, String outVideoId) {
|
|
|
+ String fileName = MD5Util.md5(title) + outVideoId;
|
|
|
String curDate = LocalDate.now().format(DateTimeFormatter.BASIC_ISO_DATE);
|
|
|
String videoFilePath = filePath + File.separator + env + File.separator + curDate;
|
|
|
String localFilePath = downloadPath + File.separator + videoFilePath;
|
|
|
|
|
|
File localFile = new File(localFilePath);
|
|
|
if (!localFile.exists() && (!localFile.mkdirs())) {
|
|
|
- log.warn("mkdir dir [{}] failed!", localFilePath);
|
|
|
+ log.error("mkdir dir [{}] failed!", localFilePath);
|
|
|
+
|
|
|
+ localFilePath = defaultFilePath;
|
|
|
}
|
|
|
|
|
|
+ String finalLocalFilePath = localFilePath;
|
|
|
retrySupplier(() -> {
|
|
|
try {
|
|
|
// 下载文件
|
|
|
- FileUtils.download(fileUrl, localFilePath + File.separator + titleMmd5);
|
|
|
+ FileUtils.download(fileUrl, finalLocalFilePath + File.separator + fileName);
|
|
|
return false;
|
|
|
} catch (CommonException e) {
|
|
|
if (e.getCode() == ExceptionEnum.URL_FORBIDDEN.getCode()) {
|
|
@@ -384,7 +397,7 @@ public class EtlServiceImpl implements EtlService {
|
|
|
}
|
|
|
}, "download", String.format("download file from [%s] to [%s]", fileUrl, filePath));
|
|
|
|
|
|
- return videoFilePath + File.separator + titleMmd5;
|
|
|
+ return videoFilePath + File.separator + fileName;
|
|
|
}
|
|
|
|
|
|
private void file2oss(String localFile, String ossBucketKey, String crawler, String mode) {
|