|
|
@@ -9,20 +9,11 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
|
|
|
-import javax.script.Invocable;
|
|
|
-import javax.script.ScriptEngine;
|
|
|
-import javax.script.ScriptEngineManager;
|
|
|
-import javax.script.ScriptException;
|
|
|
-import java.io.FileReader;
|
|
|
+import java.io.IOException;
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
import java.net.URLDecoder;
|
|
|
import java.net.URLEncoder;
|
|
|
-import java.nio.charset.StandardCharsets;
|
|
|
-import java.util.*;
|
|
|
-import java.util.regex.Matcher;
|
|
|
-import java.util.regex.Pattern;
|
|
|
-
|
|
|
-import static org.apache.ibatis.ognl.DynamicSubscript.mid;
|
|
|
+import java.util.HashMap;
|
|
|
|
|
|
@Slf4j
|
|
|
@SpringBootTest
|
|
|
@@ -187,7 +178,7 @@ public class 抖音测试工具类 {
|
|
|
HashMap<String, String> hashMap = new HashMap<>();
|
|
|
hashMap.put("User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 18_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.5 Mobile/15E148 Safari/604.1 Edg/148.0.0.0");
|
|
|
String done = OkHttpClientUtils.doGet(url, null, hashMap);
|
|
|
- String roomId = DouYinUtils.getRegexString(done, "roomId=\"(.*?)\"", 1);
|
|
|
+ String roomId = DouYinUtils.getRegexString(done, "roomId[^\\d]*(\\d{15,})", 1);
|
|
|
if (StringUtils.isEmpty(roomId)) {
|
|
|
throw new RuntimeException("未找到房间号");
|
|
|
}
|
|
|
@@ -227,4 +218,37 @@ public class 抖音测试工具类 {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void 获取抖音弹幕() {
|
|
|
+ String liveId = "561090451047";
|
|
|
+ try {
|
|
|
+
|
|
|
+ // 设置工作目录
|
|
|
+ String workDir = "C:\\Users\\Administrator\\Downloads\\DouyinLiveWebFetcher-main";
|
|
|
+
|
|
|
+ // 构建命令
|
|
|
+ String command = "cmd /c start cmd /k \"python main.py --live_id=" + liveId + "\"";
|
|
|
+
|
|
|
+ System.out.println("执行命令: " + command);
|
|
|
+
|
|
|
+ // 使用 ProcessBuilder 执行命令
|
|
|
+ ProcessBuilder processBuilder = new ProcessBuilder("cmd", "/c", command);
|
|
|
+ processBuilder.directory(new java.io.File(workDir));
|
|
|
+ // 合并错误流和输出流
|
|
|
+ processBuilder.redirectErrorStream(true);
|
|
|
+
|
|
|
+ // 启动进程
|
|
|
+ Process process = processBuilder.start();
|
|
|
+ // 等待进程自然结束
|
|
|
+ int exitCode = process.waitFor();
|
|
|
+ System.out.println("进程退出码: " + exitCode);
|
|
|
+
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|