123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- package com.tzld.piaoquan.longarticle.utils;
- import cn.hutool.http.HttpRequest;
- import cn.hutool.http.HttpResponse;
- import cn.hutool.json.JSONUtil;
- import cn.hutool.json.JSONObject;
- import java.util.ArrayList;
- import java.util.List;
- public class DouyinSearch {
- public static List<JSONObject> douyinSearch(String keyword, String sensitiveWords, String traceId) {
- String url = "http://8.217.190.241:8888/crawler/dou_yin/top_hub_content";
- JSONObject payload = new JSONObject();
- payload.put("keyword", keyword);
- payload.put("category", "全部");
- payload.put("period", "近90天");
- payload.put("content_modal", "视频");
- payload.put("cursor", "");
- HttpResponse response = HttpRequest.post(url)
- .header("Content-Type", "application/json")
- .body(payload.toString())
- .execute();
- List<JSONObject> resultList = new ArrayList<>();
- try {
- JSONObject jsonResponse = JSONUtil.parseObj(response.body());
- List<JSONObject> dtList = jsonResponse.getByPath("data.data", List.class);
- for (JSONObject obj : dtList) {
- try {
- String title = obj.getStr("video_desc");
- String videoId = obj.getStr("video_id");
- int duration = obj.getInt("duration");
- if (sensitiveFlag(sensitiveWords, title) && duration < 30000) {
- JSONObject res = douyinDetail(videoId);
- if (res != null) {
- resultList.add(res);
- }
- }
- } catch (Exception e) {
- System.out.println(e.getMessage());
- // 处理异常
- }
- }
- return resultList;
- } catch (Exception e) {
- return new ArrayList<>();
- }
- }
- public static JSONObject douyinDetail(String videoId) {
- String url = "http://8.217.190.241:8888/crawler/dou_yin/detail";
- JSONObject payload = new JSONObject();
- payload.put("content_id", videoId);
- HttpResponse response = HttpRequest.post(url)
- .header("Content-Type", "application/json")
- .body(payload.toString())
- .execute();
- JSONObject videoInfo = JSONUtil.parseObj(response.body()).getByPath("data.data", JSONObject.class);
- if ("note".equals(videoInfo.getStr("content_type"))) {
- return null;
- } else {
- return videoInfo;
- }
- }
- private static boolean sensitiveFlag(String sensitiveWords, String title) {
- // 实现敏感词检查逻辑
- return true; // 示例
- }
- public static void main(String[] args) {
- System.out.println(douyinSearch("美女", "", ""));
- }
- }
|