Bläddra i källkod

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

xueyiming 1 månad sedan
förälder
incheckning
230384cd5d

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

@@ -301,6 +301,7 @@ public class CrawlerVideoServiceImpl {
             String coverPath = VideoDownloader.downloadCover(outVideoId, platform, crawlerVideo.getCoverUrl());
             if (StringUtils.isNotEmpty(videoPath)) {
                 String videoOssPath = OSSUploader.uploadToOSS(videoPath, "video");
+                log.info("OSSUploader.uploadToOSS videoPath={}", videoPath);
                 int uploadOssCount = 0;
                 while (StringUtils.isEmpty(videoOssPath) && uploadOssCount < 3) {
                     log.info("OSSUploader.uploadToOSS videoPath={}", videoPath);

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

@@ -102,26 +102,21 @@ public class VideoDownloader {
             int responseCode = connection.getResponseCode();
             if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_PARTIAL) {
                 long expectedSize = connection.getContentLengthLong();
-                try (InputStream inputStream = connection.getInputStream();
-                     OutputStream outputStream = Files.newOutputStream(file.toPath())) {
-                    byte[] buffer = new byte[1024 * 1024];
-                    long lastReadTime = System.currentTimeMillis();
-                    int bytesRead;
-                    while ((bytesRead = inputStream.read(buffer)) != -1) {
-                        outputStream.write(buffer, 0, bytesRead);
-                        lastReadTime = System.currentTimeMillis();
-                        // 检查是否长时间没有读取到新数据
-                        if (System.currentTimeMillis() - lastReadTime > READ_TIMEOUT_SECONDS * 1000) {
-                            log.error("No data read for a long time, aborting download.");
-                            break;
-                        }
-                    }
+                InputStream inputStream = connection.getInputStream();
+                OutputStream outputStream = Files.newOutputStream(file.toPath());
+                byte[] buffer = new byte[1024 * 1024];
+                int bytesRead;
+                log.info("download start path={} expectedSize={}", path, expectedSize);
+                long size = 0;
+                while ((bytesRead = inputStream.read(buffer)) != -1) {
+                    size += bytesRead;
+                    outputStream.write(buffer, 0, bytesRead);
                 }
-                if (file.length() != expectedSize) {
+                log.info("download end path={}", path);
+                if (file.length() != 0) {
                     return 0;
                 }
             }
-
             return responseCode;
         } catch (Exception e) {
             log.error("download error", e);