|
@@ -56,9 +56,13 @@ public class AdminVideoApiController extends CertifyApiController {
|
|
|
private AdminVideoService adminVideoService;
|
|
private AdminVideoService adminVideoService;
|
|
|
|
|
|
|
|
@Value(value = "${ffmpeg.path}")
|
|
@Value(value = "${ffmpeg.path}")
|
|
|
- public String ffmpegPath = null;
|
|
|
|
|
|
|
+ private String ffmpegPath = null;
|
|
|
@Value(value = "${ffprobe.path}")
|
|
@Value(value = "${ffprobe.path}")
|
|
|
- public String ffprobePath = null;
|
|
|
|
|
|
|
+ private String ffprobePath = null;
|
|
|
|
|
+ @Value(value = "${video.path}")
|
|
|
|
|
+ private String videoPath = null;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|
|
|
// 上传视频只做MP4格式的
|
|
// 上传视频只做MP4格式的
|
|
|
@RequestMapping(value = "/upload", method = RequestMethod.POST)
|
|
@RequestMapping(value = "/upload", method = RequestMethod.POST)
|
|
@@ -68,7 +72,7 @@ public class AdminVideoApiController extends CertifyApiController {
|
|
|
AttachmentType attachmentType = AttachmentType.getField(sign);
|
|
AttachmentType attachmentType = AttachmentType.getField(sign);
|
|
|
if (attachmentType == AttachmentType.VIDEO) {
|
|
if (attachmentType == AttachmentType.VIDEO) {
|
|
|
// 先将视频存在本地文件中
|
|
// 先将视频存在本地文件中
|
|
|
- String filename = handleVideoFiles(res, req);
|
|
|
|
|
|
|
+ String filename = handleVideoFiles(res, req, videoPath);
|
|
|
res.setData(filename);
|
|
res.setData(filename);
|
|
|
} else if (attachmentType == AttachmentType.VIDEO_COVER) {
|
|
} else if (attachmentType == AttachmentType.VIDEO_COVER) {
|
|
|
String picturebase = req.getParameter("picturebase");
|
|
String picturebase = req.getParameter("picturebase");
|
|
@@ -86,13 +90,13 @@ public class AdminVideoApiController extends CertifyApiController {
|
|
|
return res;
|
|
return res;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private String createFileName() {
|
|
|
|
|
|
|
+ private String createFileName(String local) {
|
|
|
// 年月日
|
|
// 年月日
|
|
|
Calendar now = Calendar.getInstance();
|
|
Calendar now = Calendar.getInstance();
|
|
|
int year = now.get(Calendar.YEAR);
|
|
int year = now.get(Calendar.YEAR);
|
|
|
int month = now.get(Calendar.MONTH) + 1;
|
|
int month = now.get(Calendar.MONTH) + 1;
|
|
|
int day = now.get(Calendar.DAY_OF_MONTH);
|
|
int day = now.get(Calendar.DAY_OF_MONTH);
|
|
|
- String dir = "/" + year + "/" + month + "/" + day;
|
|
|
|
|
|
|
+ String dir = "/" + local + "/" + year + "/" + month + "/" + day;
|
|
|
return dir;
|
|
return dir;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -126,12 +130,23 @@ public class AdminVideoApiController extends CertifyApiController {
|
|
|
VideoFields.getFieldDesc(bindingResult.getFieldError().getField())));
|
|
VideoFields.getFieldDesc(bindingResult.getFieldError().getField())));
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
+ if(StringUtils.isBlank(video.getName())){
|
|
|
|
|
+ result.getError().add(
|
|
|
|
|
+ buildError( "视频名称不能是空", "视频名称不能是空"));
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+ //名称重名限制
|
|
|
|
|
+ if(adminVideoService.nameCheck(video.getName().trim()) > 0){
|
|
|
|
|
+ result.getError().add(
|
|
|
|
|
+ buildError(ErrorConstants.PARAM_ERROR, "", "视频名称重复不能新增"));
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
String filename = video.getUrl();
|
|
String filename = video.getUrl();
|
|
|
|
|
|
|
|
// 生成保存到数据库的url
|
|
// 生成保存到数据库的url
|
|
|
String output = System.nanoTime() + ".mp4";
|
|
String output = System.nanoTime() + ".mp4";
|
|
|
- video.setUrl(createFileName() + "/" + output);
|
|
|
|
|
|
|
+ video.setUrl(createFileName(videoPath) + "/" + output);
|
|
|
|
|
|
|
|
video.setTranscoding(1);
|
|
video.setTranscoding(1);
|
|
|
// 保存到数据库
|
|
// 保存到数据库
|
|
@@ -164,13 +179,32 @@ public class AdminVideoApiController extends CertifyApiController {
|
|
|
buildError(ErrorConstants.PARAM_ERROR, "", "视频id不存在"));
|
|
buildError(ErrorConstants.PARAM_ERROR, "", "视频id不存在"));
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
+ if(null != video.getName() && "".equals(video.getName().trim())){
|
|
|
|
|
+ result.getError().add(
|
|
|
|
|
+ buildError( "视频名称不能是空", "视频名称不能是空"));
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+ //如果是删除视频
|
|
|
|
|
+ if(null != video.getStatus() && video.getStatus() == 3){
|
|
|
|
|
+ if(oldVideo.getStatus() == 1){
|
|
|
|
|
+ result.getError().add(
|
|
|
|
|
+ buildError( "视频已经发布不能删除", "视频已经发布不能删除"));
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }else{
|
|
|
|
|
+ deleteFtpVideo(oldVideo.getUrl());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
if (StringUtils.isNotBlank(video.getUrl()) && !video.getUrl().equals(oldVideo.getUrl())) { // 如果修改了视频
|
|
if (StringUtils.isNotBlank(video.getUrl()) && !video.getUrl().equals(oldVideo.getUrl())) { // 如果修改了视频
|
|
|
video.setTranscoding(1);
|
|
video.setTranscoding(1);
|
|
|
// 压缩视频并将视频
|
|
// 压缩视频并将视频
|
|
|
String filename = video.getUrl();
|
|
String filename = video.getUrl();
|
|
|
String output = System.nanoTime() + ".mp4";
|
|
String output = System.nanoTime() + ".mp4";
|
|
|
- video.setUrl(createFileName() + "/" + output);
|
|
|
|
|
|
|
+ video.setUrl(createFileName(videoPath) + "/" + output);
|
|
|
videoChange(filename, output, video.getUrl());
|
|
videoChange(filename, output, video.getUrl());
|
|
|
|
|
+
|
|
|
|
|
+ //删除原来远程的视频
|
|
|
|
|
+ deleteFtpVideo(oldVideo.getUrl());
|
|
|
|
|
+
|
|
|
}else{
|
|
}else{
|
|
|
video.setUrl(null);
|
|
video.setUrl(null);
|
|
|
}
|
|
}
|
|
@@ -179,7 +213,10 @@ public class AdminVideoApiController extends CertifyApiController {
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+ private Boolean deleteFtpVideo(String url){
|
|
|
|
|
+ FtpUtils ftp = new FtpUtils();
|
|
|
|
|
+ return ftp.deleteFile("",url);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// 将文件转码
|
|
// 将文件转码
|
|
|
private String videoChange(String input, String output, String url) throws IOException,
|
|
private String videoChange(String input, String output, String url) throws IOException,
|