Quellcode durchsuchen

调整优化 file 模块

reghao vor 3 Wochen
Ursprung
Commit
acedbeb7f6

+ 4 - 4
file/file-api/src/main/java/cn/reghao/file/api/dto/VideoMeta.java

@@ -18,12 +18,12 @@ public class VideoMeta implements Serializable {
     private String audioCodec;
     private Long abitRate;
     private String formatName;
-    private String urlType;
-    private String url;
-    private String quality;
     private Integer width;
     private Integer height;
     // 单位秒
-    private Integer duration;
+    private Double duration;
+    private String urlType;
+    private String url;
+    private String quality;
     private Long size;
 }

+ 22 - 43
file/file-service/src/main/java/cn/reghao/tnb/file/app/service/OpenApiClient.java

@@ -2,9 +2,6 @@ package cn.reghao.tnb.file.app.service;
 
 import cn.reghao.jutil.jdk.converter.DateTimeConverter;
 import cn.reghao.jutil.jdk.io.FileSplitter;
-import cn.reghao.jutil.jdk.media.FFmpegWrapper;
-import cn.reghao.jutil.jdk.media.model.MediaProps;
-import cn.reghao.jutil.jdk.media.model.VideoProps;
 import cn.reghao.jutil.jdk.serializer.JsonConverter;
 import cn.reghao.jutil.jdk.web.result.WebResult;
 import cn.reghao.oss.api.dto.ServerInfo;
@@ -65,7 +62,6 @@ public class OpenApiClient {
     }
 
     private HttpRequest getPostRequest(String path, String jsonBody) {
-        //String path = "/api/open/content/vod/publish";
         String timestamp = String.valueOf(System.currentTimeMillis());
         String nonce = UUID.randomUUID().toString();
         String method = "POST";
@@ -98,6 +94,10 @@ public class OpenApiClient {
             String body = response.body();
             Type type = new TypeToken<WebResult<ServerInfo>>(){}.getType();
             WebResult<ServerInfo> webResult = JsonConverter.jsonToObject(body, type);
+            if (webResult.getCode() != 0) {
+                throw new RuntimeException("request failed: " + webResult.getMsg());
+            }
+
             return webResult.getData();
         } else {
             throw new RuntimeException("Status Code: " + response.statusCode() + ", Response: " + response.body());
@@ -123,6 +123,10 @@ public class OpenApiClient {
         String body = response.body();
         Type type = new TypeToken<WebResult<UploadPrepareRet>>(){}.getType();
         WebResult<UploadPrepareRet> webResult = JsonConverter.jsonToObject(body, type);
+        if (webResult.getCode() != 0) {
+            throw new RuntimeException("request failed: " + webResult.getMsg());
+        }
+
         UploadPrepareRet uploadPrepareRet = webResult.getData();
         return uploadPrepareRet;
     }
@@ -146,6 +150,9 @@ public class OpenApiClient {
         String body = response.body();
         Type type1 = new TypeToken<WebResult<UploadFileRet>>(){}.getType();
         WebResult<UploadFileRet> webResult1 = JsonConverter.jsonToObject(body, type1);
+        if (webResult1.getCode() != 0) {
+            throw new RuntimeException("request failed: " + webResult1.getMsg());
+        }
         UploadFileRet uploadFileRet = webResult1.getData();
         return uploadFileRet;
     }
@@ -227,9 +234,11 @@ public class OpenApiClient {
             String body = httpResponse.body();
             Type type = new TypeToken<WebResult<UploadFileRet>>(){}.getType();
             WebResult<UploadFileRet>  webResult = JsonConverter.jsonToObject(body, type);
-            if (webResult.getCode() == 0 ) {
-                return webResult.getData();
+            if (webResult.getCode() != 0) {
+                throw new RuntimeException("request failed: " + webResult.getMsg());
             }
+
+            return webResult.getData();
         }
         return null;
     }
@@ -264,11 +273,11 @@ public class OpenApiClient {
         String body = response.body();
         Type type1 = new TypeToken<WebResult<UploadFileRet>>(){}.getType();
         WebResult<UploadFileRet> webResult1 = JsonConverter.jsonToObject(body, type1);
-        if (webResult1.getCode() == 0) {
-            return webResult1.getData();
+        if (webResult1.getCode() != 0) {
+            throw new RuntimeException("request failed: " + webResult1.getMsg());
         }
 
-        return null;
+        return webResult1.getData();
     }
 
     private String postRequest(String path, Map<String, Object> body) {
@@ -336,8 +345,8 @@ public class OpenApiClient {
         map1.put("coverFileId", coverFileId);
         map1.put("title", title);
         map1.put("description", videoFile.getName());
-        map1.put("categoryPid", 11);
-        map1.put("categoryId", 12);
+        map1.put("categoryPid", 1);
+        map1.put("categoryId", 2);
         map1.put("tags", List.of("tnb"));
         map1.put("scope", 2);
 
@@ -359,7 +368,7 @@ public class OpenApiClient {
         UploadFileRet uploadFileRet1 = uploadSingleFile(serverInfo1.getOssUrl(), serverInfo1.getToken(), Path.of(coverFile.getPath()));
         String  coverFileId = uploadFileRet1.getUploadId();
 
-        String path = "/api/open/content/vod/update_cover";
+        String path = "/api/open/content/vod/update/cover";
         Map<String, Object> map = new HashMap<>();
         map.put("videoId", videoId);
         map.put("coverFileId", coverFileId);
@@ -377,7 +386,7 @@ public class OpenApiClient {
         UploadFileRet uploadFileRet2 = uploadFilePart(101, serverInfo2.getOssUrl(), serverInfo2.getToken(), Path.of(videoFile.getPath()));
         String videoFileId = uploadFileRet2.getUploadId();
 
-        String path = "/api/open/content/vod/update_video";
+        String path = "/api/open/content/vod/update/file";
         Map<String, Object> map = new HashMap<>();
         map.put("videoId", videoId);
         map.put("videoFileId", videoFileId);
@@ -389,34 +398,4 @@ public class OpenApiClient {
             throw new RuntimeException("post failed: " + webResult.getMsg());
         }
     }
-
-    public static void main(String[] args) throws Exception {
-        long userId = 11011L;
-        String baseUrl = "https://reghao.cn";
-        String accessKey = "AK7E622DA20E9B48";
-        String secretKey = "SK89E908C80C8747E19B1ED68C7A6CA25D";
-        OpenApiClient openApiClient = new OpenApiClient(baseUrl, accessKey, secretKey);
-
-        File avatarFile = new File("/home/reghao/Downloads/1/avatar.jpg");
-        //openApiClient.updateAvatar(avatarFile);
-
-        File coverFile = new File("/home/reghao/Downloads/1/cover.jpg");
-        coverFile = new File("/home/reghao/Downloads/v2-cb256237a256669399845935ff1d0e06_r.jpg");
-        for (int i = 0; i < 1000; i++) {
-            //openApiClient.updateVideoCover("6KMyx0WvmD", coverFile);
-            //Thread.sleep(1000);
-        }
-
-        File videoFile = new File("/home/reghao/Downloads/26.mkv");
-        //biliOpenApiClient.updateVideoFile("", videoFile);
-
-        MediaProps mediaProps = FFmpegWrapper.getMediaProps(videoFile.getAbsolutePath());
-        VideoProps videoProps = mediaProps.getVideoProps();
-        if (videoProps != null) {
-            double duration = videoProps.getDuration();
-            System.out.println();
-        }
-
-        //biliOpenApiClient.publishVideoPost(coverFile, videoFile);
-    }
 }

+ 2 - 2
file/file-service/src/main/java/cn/reghao/tnb/file/app/zdisk/model/po/CamRecord.java

@@ -19,9 +19,9 @@ public class CamRecord extends BaseObject<Integer> {
     private Long recordId;
     private String videoFileId;
     private LocalDateTime startAt;
-    private Integer duration;
+    private Double duration;
 
-    public CamRecord(long camId, long recordId, String videoFileId, int duration, LocalDateTime startAt) {
+    public CamRecord(long camId, long recordId, String videoFileId, double duration, LocalDateTime startAt) {
         this.camId = camId;
         this.recordId = recordId;
         this.videoFileId = videoFileId;

+ 1 - 1
file/file-service/src/main/java/cn/reghao/tnb/file/app/zdisk/service/CamRecordService.java

@@ -74,7 +74,7 @@ public class CamRecordService {
             int videoChannelCode = camRecordDto.getVideoChannelCode();
             String videoFileId = camRecordDto.getVideoFileId();
             VideoMeta videoMeta = ossService.getVideoMeta(videoFileId);
-            int duration = videoMeta.getDuration();
+            double duration = videoMeta.getDuration();
             long recordId = idService.getLongId();
             long startAt = camRecordDto.getStartAt();
             LocalDateTime startAt1 = DateTimeConverter.localDateTime(startAt);