Browse Source

更新 getVideoUrls RPC 接口

reghao 2 years ago
parent
commit
d8ab1b8901

+ 1 - 1
dfs-store/src/main/java/cn/reghao/dfs/store/controller/ObjectUploadController.java

@@ -30,7 +30,7 @@ public class ObjectUploadController {
     private final FileStoreService fileStoreService;
     private final ObjectNameService objectNameService;
     private final PutObjectService putObjectService;
-    private FileProcessor fileProcessor;
+    private final FileProcessor fileProcessor;
 
     public ObjectUploadController(FileStoreService fileStoreService, ObjectNameService objectNameService,
                                   PutObjectService putObjectService, FileProcessor fileProcessor) {

+ 1 - 1
dfs-store/src/main/java/cn/reghao/dfs/store/db/mapper/VideoUrlMapper.java

@@ -15,7 +15,7 @@ import java.util.List;
  */
 @Mapper
 public interface VideoUrlMapper extends BaseMapper<VideoUrl> {
-    List<VideoUrlDto> findVideoUrls(@Param("videoFileId") String videoFileId, @Param("urlType") String urlType);
+    List<VideoUrlDto> findVideoUrls(String videoFileId);
     List<VideoUrl> findVideoUrlByPage(Page page);
     List<VideoUrl> findByVideoFileId(String videoFileId);
 }

+ 2 - 2
dfs-store/src/main/java/cn/reghao/dfs/store/rpc/MediaUrlServiceImpl.java

@@ -37,7 +37,7 @@ public class MediaUrlServiceImpl implements MediaUrlService {
     }
 
     @Override
-    public List<VideoUrlDto> getVideoUrls(String videoFileId, String urlType) {
-        return videoUrlMapper.findVideoUrls(videoFileId, urlType);
+    public List<VideoUrlDto> getVideoUrls(String videoFileId) {
+        return videoUrlMapper.findVideoUrls(videoFileId);
     }
 }

+ 30 - 0
dfs-store/src/main/java/cn/reghao/dfs/store/service/FileType.java

@@ -0,0 +1,30 @@
+package cn.reghao.dfs.store.service;
+
+import cn.reghao.jutil.jdk.shell.Shell;
+
+/**
+ * @author reghao
+ * @date 2023-06-12 22:47:06
+ */
+public class FileType {
+    public static String getMediaType(String src) {
+        String cmd = String.format("/bin/file -b --mime-type \"%s\"", src);
+        return Shell.execWithResult(cmd);
+    }
+
+    public static int getFileType(String contentType) {
+        int fileType = 1005;
+        if (contentType == null) {
+            return fileType;
+        } else if (contentType.startsWith("image")) {
+            fileType = 1001;
+        } else if (contentType.startsWith("video")) {
+            fileType = 1002;
+        } else if (contentType.startsWith("audio")) {
+            fileType = 1003;
+        } else if (contentType.startsWith("text")) {
+            fileType = 1004;
+        }
+        return fileType;
+    }
+}

+ 4 - 25
dfs-store/src/main/java/cn/reghao/dfs/store/service/PutObjectService.java

@@ -49,8 +49,8 @@ public class PutObjectService {
             String savedPath = savedFile.getAbsolutePath();
             long size = savedFile.length();
             String objectId = UUID.randomUUID().toString().replace("-", "");
-            String contentType = getMediaType(savedPath);
-            int fileType = getFileType(contentType);
+            String contentType = FileType.getMediaType(savedPath);
+            int fileType = FileType.getFileType(contentType);
 
             boolean diskFile = objectProp.isDiskFile();
             int acl = objectProp.getAcl();
@@ -79,8 +79,8 @@ public class PutObjectService {
 
                 String objectId = "";
                 String savedPath = savedFile.getAbsolutePath();
-                String contentType = getMediaType(savedPath);
-                int fileType = getFileType(contentType);
+                String contentType = FileType.getMediaType(savedPath);
+                int fileType = FileType.getFileType(contentType);
             }
         } catch (Exception e) {
             e.printStackTrace();
@@ -95,25 +95,4 @@ public class PutObjectService {
         FileMeta fileMeta1 = new FileMeta(objectName, objectId, filename, fileMeta, diskFile, acl);
         objectRepository.saveFileMeta(fileMeta1);
     }
-
-    private String getMediaType(String src) {
-        String cmd = String.format("/bin/file -b --mime-type \"%s\"", src);
-        return Shell.execWithResult(cmd);
-    }
-
-    private Integer getFileType(String contentType) {
-        int fileType = 1005;
-        if (contentType == null) {
-            return fileType;
-        } else if (contentType.startsWith("image")) {
-            fileType = 1001;
-        } else if (contentType.startsWith("video")) {
-            fileType = 1002;
-        } else if (contentType.startsWith("audio")) {
-            fileType = 1003;
-        } else if (contentType.startsWith("text")) {
-            fileType = 1004;
-        }
-        return fileType;
-    }
 }

+ 9 - 2
dfs-store/src/main/java/cn/reghao/dfs/store/task/VideoFileProcessor.java

@@ -1,5 +1,6 @@
 package cn.reghao.dfs.store.task;
 
+import cn.reghao.dfs.store.service.FileType;
 import cn.reghao.dfs.store.util.media.po.AudioProps;
 import cn.reghao.dfs.store.util.media.po.VideoProps;
 import cn.reghao.oss.api.dto.VideoUrlType;
@@ -62,7 +63,7 @@ public class VideoFileProcessor {
 
         AudioProps audioProps = mediaProps.getAudioProps();
         if (audioProps == null) {
-            log.info("{} 的 FFmpeg 频信息为 null", objectName);
+            log.info("{} 的 FFmpeg 频信息为 null", objectName);
             return;
         }
 
@@ -70,7 +71,13 @@ public class VideoFileProcessor {
         String videoCodec = mediaProps.getVideoProps().getCodecName();
         if ("aac".equals(audioCodec) && "h264".equals(videoCodec)) {
             MediaResolution mediaResolution = MediaQuality.getQuality(width, height);
-            VideoUrl videoUrl = new VideoUrl(videoFileId, objectName, VideoUrlType.mp4.name(), url, mediaResolution);
+            String urlType = VideoUrlType.mp4.name();
+            String mediaType = FileType.getMediaType(absolutePath);
+            if (mediaType.endsWith("flv")) {
+                urlType = VideoUrlType.flv.name();
+            }
+
+            VideoUrl videoUrl = new VideoUrl(videoFileId, objectName, urlType, url, mediaResolution);
             videoUrlMapper.save(videoUrl);
             return;
         }

+ 1 - 1
dfs-store/src/main/resources/mapper/VideoUrlMapper.xml

@@ -12,7 +12,7 @@
     <select id="findVideoUrls" resultType="cn.reghao.oss.api.dto.VideoUrlDto">
         select url_type as type,url,width,height,quality
         from video_url
-        where video_file_id=#{videoFileId} and url_type=#{urlType}
+        where video_file_id=#{videoFileId}
     </select>
     <select id="findByVideoFileId" resultType="cn.reghao.dfs.store.model.po.VideoUrl">
         select *

+ 1 - 1
oss-api/src/main/java/cn/reghao/oss/api/iface/MediaUrlService.java

@@ -13,5 +13,5 @@ import java.util.List;
 public interface MediaUrlService {
     ImageUrl getImageUrl(String imageFileId);
     VideoInfo getVideoInfo(String videoFileId);
-    List<VideoUrlDto> getVideoUrls(String videoFileId, String urlType);
+    List<VideoUrlDto> getVideoUrls(String videoFileId);
 }

+ 1 - 1
zzz/build.sh

@@ -4,4 +4,4 @@
 #!/bin/bash
 
 cd /home/reghao/code/java/dfs/dfs-store/
-mvn clean package -Dmaven.test.skip
+mvn clean package -Dmaven.test.skip -Ptest

+ 3 - 3
zzz/deploy.sh

@@ -4,10 +4,10 @@
 #!/bin/bash
 
 cd /home/reghao/code/java/dfs/oss-common/
-mvn clean deploy -Dmaven.test.skip &
+mvn clean deploy -Dmaven.test.skip
 
 cd /home/reghao/code/java/dfs/oss-api/
-mvn clean deploy -Dmaven.test.skip &
+mvn clean deploy -Dmaven.test.skip
 
 cd /home/reghao/code/java/dfs/oss-sdk/
-mvn clean deploy -Dmaven.test.skip &
+mvn clean deploy -Dmaven.test.skip

+ 3 - 3
zzz/install.sh

@@ -4,10 +4,10 @@
 #!/bin/bash
 
 cd /home/reghao/code/java/dfs/oss-common/
-mvn clean install -Dmaven.test.skip &
+mvn clean install -Dmaven.test.skip
 
 cd /home/reghao/code/java/dfs/oss-api/
-mvn clean install -Dmaven.test.skip &
+mvn clean install -Dmaven.test.skip
 
 cd /home/reghao/code/java/dfs/oss-sdk/
-mvn clean install -Dmaven.test.skip &
+mvn clean install -Dmaven.test.skip