Explorar o código

Merge branch 'dev-xym-log' of Server/long-article-manage into master

xueyiming hai 2 meses
pai
achega
4ff42dc0da

+ 8 - 2
long-article-server/src/main/java/com/tzld/piaoquan/longarticle/service/local/impl/CrawlerVideoServiceImpl.java

@@ -114,6 +114,7 @@ public class CrawlerVideoServiceImpl {
             return true;
         }
         boolean pushRes = pushOss(matchVideo.getContentId());
+        log.info("uploadCrawlerVideo pushRes={} contentId={}", pushRes, matchVideo.getContentId());
         if (pushRes) {
             AuditContentRequest auditContentRequest = new AuditContentRequest();
             auditContentRequest.setContentId(matchVideo.getContentId());
@@ -302,6 +303,7 @@ public class CrawlerVideoServiceImpl {
                 String videoOssPath = OSSUploader.uploadToOSS(videoPath, "video");
                 int uploadOssCount = 0;
                 while (StringUtils.isEmpty(videoOssPath) && uploadOssCount < 3) {
+                    log.info("OSSUploader.uploadToOSS videoPath={}", videoPath);
                     videoOssPath = OSSUploader.uploadToOSS(videoPath, "video");
                     uploadOssCount++;
                 }
@@ -317,8 +319,12 @@ public class CrawlerVideoServiceImpl {
                     crawlerVideoMapper.updateByPrimaryKeySelective(udpateCrawlerVideo);
                     count++;
                     try {
-                        Files.delete(Paths.get(videoPath));
-                        Files.delete(Paths.get(coverPath));
+                        if (StringUtils.isNotEmpty(videoOssPath)) {
+                            Files.delete(Paths.get(videoPath));
+                        }
+                        if (StringUtils.isNotEmpty(coverPath)) {
+                            Files.delete(Paths.get(coverPath));
+                        }
                     } catch (Exception e) {
                         log.error("pushOss del file error", e);
                     }

+ 3 - 1
long-article-server/src/main/java/com/tzld/piaoquan/longarticle/service/local/impl/MatchVideoServiceImpl.java

@@ -90,7 +90,7 @@ public class MatchVideoServiceImpl {
     // 定义一个阻塞队列
     private static final ArrayBlockingQueue<MatchVideo> uploadCrawlerVideoQueue = new ArrayBlockingQueue<>(1000000);
     // 定义一个线程池,设置消费线程的数量
-    private static final ThreadPoolExecutor uploadCrawlerVideoPoolExecutor = (ThreadPoolExecutor) Executors.newFixedThreadPool(5);
+    private static final ThreadPoolExecutor uploadCrawlerVideoPoolExecutor = (ThreadPoolExecutor) Executors.newFixedThreadPool(10);
 
     @Transactional
     public void addMatchVideo(MatchContent matchContent) {
@@ -460,7 +460,9 @@ public class MatchVideoServiceImpl {
                 boolean res = crawlerVideoService.uploadCrawlerVideo(matchVideo);
                 if (res) {
                     successMatchVideo(matchVideo);
+                    log.info("uploadCrawlerVideo success contentId={}", matchVideo.getContentId());
                 } else {
+                    log.info("uploadCrawlerVideo fail contentId={}", matchVideo.getContentId());
                     //上传失败记录
                     String countKey = String.format(UPLOAD_CRAWLER_FAIL_COUNT_KEY, matchVideo.getContentId());
                     Integer count = (Integer) redisTemplate.opsForValue().get(countKey);

+ 9 - 5
long-article-server/src/main/java/com/tzld/piaoquan/longarticle/utils/other/VideoDownloader.java

@@ -34,12 +34,15 @@ public class VideoDownloader {
     public static String downloadVideo(String outVideoId, String platform, String videoUrl) {
         int retries = 0;
         while (retries < MAX_RETRIES) {
-            String path = generateVideoPath(platform, outVideoId);
-            int download = download(path, videoUrl, platform);
-            if (download == 0) {
-                return path;
+            log.info("downloadVideo outVideoId={} retries={}", outVideoId, retries);
+            int download = -1;
+            if (StringUtils.isNotEmpty(videoUrl)) {
+                String path = generateVideoPath(platform, outVideoId);
+                download = download(path, videoUrl, platform);
+                if (download == 0) {
+                    return path;
+                }
             }
-
             //百度重新获取链接
             if ((download == 403 || StringUtils.isEmpty(videoUrl)) && Objects.equals(platform, "baidu_search")) {
                 JSONObject videoDetail = HkspSearch.getVideoDetail(outVideoId);
@@ -71,6 +74,7 @@ public class VideoDownloader {
 
     public static int download(String path, String videoUrl, String platform) {
         try {
+            log.info("download video path={}", path);
             if (StringUtils.isEmpty(videoUrl)) {
                 return -1;
             }