|
@@ -1,5 +1,8 @@
|
|
|
package com.tzld.piaoquan.longarticle.utils.other;
|
|
|
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
+import com.tzld.piaoquan.longarticle.utils.ConfigUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
|
import org.apache.http.HttpResponse;
|
|
|
import org.apache.http.client.methods.HttpGet;
|
|
@@ -13,6 +16,7 @@ import java.net.URL;
|
|
|
import java.util.Objects;
|
|
|
import java.util.UUID;
|
|
|
|
|
|
+@Slf4j
|
|
|
public class VideoDownloader {
|
|
|
|
|
|
private static final String PROXY_HOST = "l901.kdltps.com";
|
|
@@ -39,7 +43,6 @@ public class VideoDownloader {
|
|
|
|
|
|
public static boolean download(String path, String videoUrl, String platform) {
|
|
|
try {
|
|
|
-
|
|
|
int retries = 0;
|
|
|
long fileSize = 0;
|
|
|
|
|
@@ -94,10 +97,10 @@ public class VideoDownloader {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- System.out.println("下载失败,已达到最大重试次数:" + MAX_RETRIES);
|
|
|
+ log.error("下载失败,已达到最大重试次数:" + MAX_RETRIES);
|
|
|
return false;
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ log.error("download error", e);
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
@@ -106,14 +109,14 @@ public class VideoDownloader {
|
|
|
String index = String.format("%s-%s-%s", platform, videoId, UUID.randomUUID());
|
|
|
String md5Hash = DigestUtils.md5Hex(index);
|
|
|
String fileName = String.format("%s.mp4", md5Hash);
|
|
|
- return String.join(File.separator, "/Users/shimeng/Desktop/download", fileName); // 返回文件路径和封面路径
|
|
|
+ return String.join(File.separator, ConfigUtil.getConfig("download.path"), fileName); // 返回文件路径和封面路径
|
|
|
}
|
|
|
|
|
|
private static String generateCoverPath(String platform, String videoId) {
|
|
|
String index = String.format("%s-%s-%s", platform, videoId, UUID.randomUUID());
|
|
|
String md5Hash = DigestUtils.md5Hex(index);
|
|
|
String coverName = String.format("%s.png", md5Hash);
|
|
|
- return String.join(File.separator, "/Users/shimeng/Desktop/download", coverName); // 返回文件路径和封面路径
|
|
|
+ return String.join(File.separator, ConfigUtil.getConfig("download.path"), coverName); // 返回文件路径和封面路径
|
|
|
}
|
|
|
|
|
|
}
|