Browse Source

feat: 视频理解支持videoId字段

jihuaqiang 1 tháng trước cách đây
mục cha
commit
fb461c92ee

+ 5 - 0
content-understanding-core/src/main/java/com/tzld/piaoquan/content/understanding/model/param/ActionParam.java

@@ -20,4 +20,9 @@ public class ActionParam {
      * prompt
      */
     private String prompt;
+
+    /**
+     * 视频ID
+     */
+    private Long videoId;
 }

+ 12 - 1
content-understanding-core/src/main/java/com/tzld/piaoquan/content/understanding/service/ContentService.java

@@ -58,5 +58,16 @@ public interface ContentService {
      */
     boolean remainVideoUnderstandingHandler(Long videoId);
 
-
+    /**
+     * 获取视频URL
+     * <p>
+     * 有多码率文件使用多码率文件(多码率文件目前不会被冻结/冷归档/深度冷归档和删除)
+     * 没有多码率文件使用转码文件,转码文件被冻结/冷归档/深度冷归档,则需要解冻
+     * 没有转码文件使用原文件,原文件被冻结/冷归档/深度冷归档,则需要解冻
+     * 没有原文件则失败
+     *
+     * @param videoId 视频ID
+     * @return 视频URL,如果视频不存在或正在解冻则返回null
+     */
+    String getVideoUrl(Long videoId);
 }

+ 15 - 26
content-understanding-core/src/main/java/com/tzld/piaoquan/content/understanding/service/impl/ContentServiceImpl.java

@@ -406,10 +406,11 @@ public class ContentServiceImpl implements ContentService {
      * 没有转码文件使用原文件,原文件被冻结/冷归档/深度冷归档,则需要解冻
      * 没有原文件则失败
      *
-     * @param videoId
-     * @return
+     * @param videoId 视频ID
+     * @return 视频URL,如果视频不存在或正在解冻则返回null
      */
-    private String getVideoUrl(Long videoId) {
+    @Override
+    public String getVideoUrl(Long videoId) {
         //获取多码率
         String videoUrl = null;
         boolean isM3u8 = false;
@@ -431,7 +432,7 @@ public class ContentServiceImpl implements ContentService {
         if (Objects.isNull(videoUrl) && !isM3u8) {
             WxVideo wxVideo = wxVideoMapper.selectByPrimaryKey(videoId);
             if (Objects.isNull(wxVideo)) {
-                XxlJobLogger.log("table = {} videoId = {} wxVideo is null", topReturnTable, videoId);
+                log.error("videoId = {} wxVideo is null", videoId);
                 return null;
             }
             String transedVideoPath = wxVideo.getTransedVideoPath();
@@ -459,22 +460,15 @@ public class ContentServiceImpl implements ContentService {
                             }
                             //解冻
                             aliyunOssManager.restoreObject(TRANSCODE_BUCKET, transedVideoPath, EXPIRE_DAYS);
-//                            Map<String, Object> messageMap = new HashMap<>();
-//                            messageMap.put("videoId", videoId);
+                            // 发送延迟消息
                             VideoUnderstandingMessageDTO messageDTO = new VideoUnderstandingMessageDTO();
                             messageDTO.setVideoId(videoId);
-                            Duration duration;
-                            if (isCodeArchive) {
-                                duration = Duration.ofHours(1);
-                            } else {
-                                duration = Duration.ofHours(12);
-                            }
-
+                            Duration duration = isCodeArchive ? Duration.ofHours(1) : Duration.ofHours(12);
                             try {
                                 MessageId messageId = oldVersionRemainVideoUnderstandingProducer.syncSendDelayMessage(messageDTO, duration);
                                 log.info("syncSendDelayMessage messageId = {}", messageId);
                             } catch (Exception e) {
-                                log.error("syncSendDelayMessage error messageDTO = {}", e, messageDTO);
+                                log.error("syncSendDelayMessage error messageDTO = {}", messageDTO, e);
                             }
                             return null;
                         } else {
@@ -488,7 +482,7 @@ public class ContentServiceImpl implements ContentService {
         if (Objects.isNull(videoUrl)) {
             WxVideo wxVideo = wxVideoMapper.selectByPrimaryKey(videoId);
             if (Objects.isNull(wxVideo)) {
-                XxlJobLogger.log("table = {} videoId = {} wxVideo is null", topReturnTable, videoId);
+                log.error("videoId = {} wxVideo is null", videoId);
                 return null;
             }
             String videoPath = wxVideo.getVideoPath();
@@ -497,7 +491,7 @@ public class ContentServiceImpl implements ContentService {
                 if (Objects.nonNull(objectMetadata)) {
                     videoUrl = UrlUtil.processUrl(Constant.VIDEO_CDN_HTTP_DOMAIN, videoPath);
                     boolean isCodeArchive = Objects.equals(objectMetadata.getObjectStorageClass(), StorageClass.ColdArchive);
-                    boolean isDeepColdArchive = Objects.equals(objectMetadata.getObjectStorageClass(), StorageClass.ColdArchive);
+                    boolean isDeepColdArchive = Objects.equals(objectMetadata.getObjectStorageClass(), StorageClass.DeepColdArchive);
                     if (isCodeArchive || isDeepColdArchive) {
                         try {
                             //throw NPE 未解冻 true 解冻完成 false 解冻中
@@ -513,20 +507,15 @@ public class ContentServiceImpl implements ContentService {
                         }
                         //解冻
                         aliyunOssManager.restoreObject(TRANSCODE_BUCKET, videoPath, EXPIRE_DAYS);
-//                        Map<String, Object> messageMap = new HashMap<>();
-//                        messageMap.put("videoId", videoId);
+                        // 发送延迟消息
                         VideoUnderstandingMessageDTO messageDTO = new VideoUnderstandingMessageDTO();
                         messageDTO.setVideoId(videoId);
-                        Duration duration;
-                        if (isCodeArchive) {
-                            duration = Duration.ofHours(1);
-                        } else {
-                            duration = Duration.ofHours(12);
-                        }
+                        Duration duration = isCodeArchive ? Duration.ofHours(1) : Duration.ofHours(12);
                         try {
-                            oldVersionRemainVideoUnderstandingProducer.syncSendDelayMessage(messageDTO, duration);
+                            MessageId messageId = oldVersionRemainVideoUnderstandingProducer.syncSendDelayMessage(messageDTO, duration);
+                            log.info("syncSendDelayMessage messageId = {}", messageId);
                         } catch (Exception e) {
-                            log.error("syncSendDelayMessage error messageDTO = {}", e, messageDTO);
+                            log.error("syncSendDelayMessage error messageDTO = {}", messageDTO, e);
                         }
                         return null;
                     } else {

+ 15 - 1
content-understanding-core/src/main/java/com/tzld/piaoquan/content/understanding/service/impl/GeminiGenerateContentAction.java

@@ -9,6 +9,7 @@ import com.tzld.piaoquan.content.understanding.common.exception.StopRetryExcepti
 import com.tzld.piaoquan.content.understanding.model.param.ActionParam;
 import com.tzld.piaoquan.content.understanding.model.param.GeminiParam;
 import com.tzld.piaoquan.content.understanding.service.Action;
+import com.tzld.piaoquan.content.understanding.service.ContentService;
 import com.tzld.piaoquan.content.understanding.util.HttpClientUtil;
 import com.tzld.piaoquan.content.understanding.util.HttpPoolClient;
 import com.tzld.piaoquan.content.understanding.util.RedisUtil;
@@ -46,6 +47,9 @@ public class GeminiGenerateContentAction implements Action {
     @Autowired
     private RedisUtil redisUtil;
 
+    @Autowired
+    private ContentService contentService;
+
     private static final String GEMINI_API_KEY_INDEX = "gemini:apikey:list.index";
 
     @Override
@@ -63,13 +67,23 @@ public class GeminiGenerateContentAction implements Action {
             useLocalApiKey = false;
             size = 0;
         }
+
+        // 检查是否有videoId,如果有则尝试获取videoUrl
+        String mediaUrl = param.getInput();
+        if (Objects.nonNull(param.getVideoId())) {
+            String videoUrl = contentService.getVideoUrl(param.getVideoId());
+            if (Objects.nonNull(videoUrl)) {
+                mediaUrl = videoUrl;
+            }
+        }
+
         GeminiParam geminiParam = new GeminiParam();
         geminiParam.setType(type);
         geminiParam.setPrompt(param.getPrompt());
         if (Objects.equals(ContentTypeEnum.COVER.getValue(), type) || Objects.equals(ContentTypeEnum.VIDEO.getValue(), type)
                 || Objects.equals(ContentTypeEnum.AUDIO.getValue(), type) || Objects.equals(ContentTypeEnum.SRT.getValue(), type)
                 || Objects.equals(ContentTypeEnum.VTT.getValue(), type)) {
-            geminiParam.setMediaUrl(param.getInput());
+            geminiParam.setMediaUrl(mediaUrl);
         }
         geminiParam.setApiKey(apiKey);
         geminiParam.setModel(MODEL);