|
@@ -34,6 +34,7 @@ import com.tzld.crawler.etl.common.enums.ExceptionEnum;
|
|
import com.tzld.crawler.etl.common.exception.CommonException;
|
|
import com.tzld.crawler.etl.common.exception.CommonException;
|
|
import com.tzld.crawler.etl.dao.mapper.CrawlerVideoMapper;
|
|
import com.tzld.crawler.etl.dao.mapper.CrawlerVideoMapper;
|
|
import com.tzld.crawler.etl.model.dto.StrategyDataDto;
|
|
import com.tzld.crawler.etl.model.dto.StrategyDataDto;
|
|
|
|
+import com.tzld.crawler.etl.model.dto.VideoInfoDto;
|
|
import com.tzld.crawler.etl.model.param.CrawlerVideoSendParam;
|
|
import com.tzld.crawler.etl.model.param.CrawlerVideoSendParam;
|
|
import com.tzld.crawler.etl.model.po.CrawlerVideo;
|
|
import com.tzld.crawler.etl.model.po.CrawlerVideo;
|
|
import com.tzld.crawler.etl.model.vo.CrawlerVideoVO;
|
|
import com.tzld.crawler.etl.model.vo.CrawlerVideoVO;
|
|
@@ -45,6 +46,7 @@ import com.tzld.crawler.etl.service.strategy.StrategyHandlerService;
|
|
import com.tzld.crawler.etl.util.FeishuUtils;
|
|
import com.tzld.crawler.etl.util.FeishuUtils;
|
|
import com.tzld.crawler.etl.util.FileUtils;
|
|
import com.tzld.crawler.etl.util.FileUtils;
|
|
import com.tzld.crawler.etl.util.MD5Util;
|
|
import com.tzld.crawler.etl.util.MD5Util;
|
|
|
|
+import com.tzld.crawler.etl.util.VideoUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
@@ -95,6 +97,8 @@ public class EtlServiceImpl implements EtlService {
|
|
private Map<String, String> feishuRangeMap;
|
|
private Map<String, String> feishuRangeMap;
|
|
@Value("${admin.cms.url:https://testadmin.piaoquantv.com/cms/post-detail/%d/info}")
|
|
@Value("${admin.cms.url:https://testadmin.piaoquantv.com/cms/post-detail/%d/info}")
|
|
private String adminCmsUrl;
|
|
private String adminCmsUrl;
|
|
|
|
+ @Value("${ffprobe.path:ffprobe}")
|
|
|
|
+ private String ffprobePath;
|
|
|
|
|
|
private Executor pool;
|
|
private Executor pool;
|
|
|
|
|
|
@@ -110,8 +114,6 @@ public class EtlServiceImpl implements EtlService {
|
|
@Override
|
|
@Override
|
|
public void deal(CrawlerVideoVO param) {
|
|
public void deal(CrawlerVideoVO param) {
|
|
String title = param.getVideoTitle();
|
|
String title = param.getVideoTitle();
|
|
- String videoUrl = param.getVideoUrl();
|
|
|
|
- String coverUrl = param.getCoverUrl();
|
|
|
|
String platform = param.getPlatform();
|
|
String platform = param.getPlatform();
|
|
String strategy = param.getStrategy();
|
|
String strategy = param.getStrategy();
|
|
try {
|
|
try {
|
|
@@ -125,18 +127,16 @@ public class EtlServiceImpl implements EtlService {
|
|
}
|
|
}
|
|
|
|
|
|
// 2.视频文件下载、上传 OSS、清理视频信息
|
|
// 2.视频文件下载、上传 OSS、清理视频信息
|
|
- String videoPath = url2oss(videoUrl, "longvideo/crawler_local/data", title, platform, strategy);
|
|
|
|
-
|
|
|
|
// 3.视频封面下载、上传 OSS、清理视频信息
|
|
// 3.视频封面下载、上传 OSS、清理视频信息
|
|
- String coverPath = url2oss(coverUrl, "longvideo/crawler_local/image", title, platform, strategy);
|
|
|
|
|
|
+ processVideo(data);
|
|
|
|
|
|
// 4.视频发布
|
|
// 4.视频发布
|
|
CrawlerVideoSendParam request = new CrawlerVideoSendParam();
|
|
CrawlerVideoSendParam request = new CrawlerVideoSendParam();
|
|
request.setLoginUid(data.getUserId());
|
|
request.setLoginUid(data.getUserId());
|
|
request.setAppType(888888);
|
|
request.setAppType(888888);
|
|
request.setTitle(title);
|
|
request.setTitle(title);
|
|
- request.setVideoPath(videoPath);
|
|
|
|
- request.setCoverImgPath(coverPath);
|
|
|
|
|
|
+ request.setVideoPath(data.getVideoOssPath());
|
|
|
|
+ request.setCoverImgPath(data.getCoverOssPath());
|
|
request.setTotalTime(data.getDuration());
|
|
request.setTotalTime(data.getDuration());
|
|
request.setVersionCode(1);
|
|
request.setVersionCode(1);
|
|
request.setViewStatus(1);
|
|
request.setViewStatus(1);
|
|
@@ -234,6 +234,40 @@ public class EtlServiceImpl implements EtlService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void processVideo(StrategyDataDto data) throws IOException {
|
|
|
|
+ String title = data.getVideoTitle();
|
|
|
|
+ String platform = data.getPlatform();
|
|
|
|
+ String strategy = data.getStrategy();
|
|
|
|
+
|
|
|
|
+ // 视频文件下载、上传 OSS
|
|
|
|
+ String videoPath = url2oss(data.getVideoUrl(), "longvideo/crawler_local/data", title, platform, strategy);
|
|
|
|
+ data.setVideoOssPath(videoPath);
|
|
|
|
+ String tempFilePath = downloadPath + File.separator + videoPath;
|
|
|
|
+ if (data.getDuration() == null || data.getDuration() <= 0
|
|
|
|
+ || data.getWidth() == null || data.getWidth() <= 0
|
|
|
|
+ || data.getHeight() == null || data.getHeight() <= 0) {
|
|
|
|
+ VideoInfoDto videoInfo = VideoUtils.getVideoInfo(tempFilePath, ffprobePath);
|
|
|
|
+ if (videoInfo != null) {
|
|
|
|
+ data.setDuration(videoInfo.getDuration());
|
|
|
|
+ data.setWidth(videoInfo.getWidth());
|
|
|
|
+ data.setHeight(videoInfo.getHeight());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 文件清理
|
|
|
|
+ log.info("begin delete: {}", tempFilePath);
|
|
|
|
+ Files.deleteIfExists(Paths.get(new File(tempFilePath).getPath()));
|
|
|
|
+
|
|
|
|
+ // 视频封面下载、上传 OSS
|
|
|
|
+ String coverPath = url2oss(data.getCoverUrl(), "longvideo/crawler_local/image", title, platform, strategy);
|
|
|
|
+ data.setCoverOssPath(coverPath);
|
|
|
|
+ tempFilePath = downloadPath + File.separator + videoPath;
|
|
|
|
+
|
|
|
|
+ // 文件清理
|
|
|
|
+ log.info("begin delete: {}", tempFilePath);
|
|
|
|
+ Files.deleteIfExists(Paths.get(new File(tempFilePath).getPath()));
|
|
|
|
+ }
|
|
|
|
+
|
|
private String url2oss(String fileUrl, String filePath, String title, String crawler, String mode) throws IOException {
|
|
private String url2oss(String fileUrl, String filePath, String title, String crawler, String mode) throws IOException {
|
|
String titleMmd5 = MD5Util.md5(title);
|
|
String titleMmd5 = MD5Util.md5(title);
|
|
String curDate = LocalDate.now().format(DateTimeFormatter.BASIC_ISO_DATE);
|
|
String curDate = LocalDate.now().format(DateTimeFormatter.BASIC_ISO_DATE);
|
|
@@ -268,10 +302,6 @@ public class EtlServiceImpl implements EtlService {
|
|
log.info("begin upload: {}/{} to oss key: {}/{}", localFilePath, titleMmd5, videoFilePath, titleMmd5);
|
|
log.info("begin upload: {}/{} to oss key: {}/{}", localFilePath, titleMmd5, videoFilePath, titleMmd5);
|
|
aliyunOssManager.putObject(ossBucket, videoFilePath + File.separator + titleMmd5, Files.newInputStream(Paths.get(localFilePath + File.separator + titleMmd5)));
|
|
aliyunOssManager.putObject(ossBucket, videoFilePath + File.separator + titleMmd5, Files.newInputStream(Paths.get(localFilePath + File.separator + titleMmd5)));
|
|
|
|
|
|
- // 文件清理
|
|
|
|
- log.info("begin delete: {}/{}", localFilePath, titleMmd5);
|
|
|
|
- Files.deleteIfExists(Paths.get(new File(localFilePath + File.separator + titleMmd5).getPath()));
|
|
|
|
-
|
|
|
|
return videoFilePath + File.separator + titleMmd5;
|
|
return videoFilePath + File.separator + titleMmd5;
|
|
}
|
|
}
|
|
|
|
|