KKSU
2024-08-22 7a372033d44ba48383d9d1bc97e5d583b26a266f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
//package cc.mrbird.febs.mall.test;
//
//import com.alibaba.fastjson.JSONArray;
//import com.alibaba.fastjson.JSONObject;
//import okhttp3.OkHttpClient;
//import okhttp3.Request;
//import okhttp3.Response;
//
//import java.io.IOException;
//import java.util.regex.Matcher;
//import java.util.regex.Pattern;
//
//public class DYDelMark {
//    public static void main(String[] args) {
//        String content = "https://v.douyin.com/iLwxgYHE/";
//        JSONObject douYData = extractDouYinData(content);
//        if (douYData != null) {
//            System.out.println(douYData);
//        } else {
//            System.out.println(1);
//        }
//    }
//    private static JSONObject extractDouYinData(String content) {
//        String url = extractUrl(content);
//
//        if (url != null) {
//            if (content.contains("douyin.com")) {
//                if (content.contains("live.douyin.com")) {
//                    System.out.println("直播");
//                    return null;
//                } else {
//                    String dyUrlOrId = processContent(content);
//                    String videoId = isNumeric(dyUrlOrId) ? dyUrlOrId : extractVideoId(dyUrlOrId);
//                    if (videoId!=null){
//                        JSONArray dyData = serverGetDy(videoId);
//
//                        if (dyData != null && dyData.size() > 0) {
//                            JSONObject jsonData = dyData.getJSONObject(0);
//                            return buildDouYinData(jsonData);
//                        }
//                    }
//                }
//            }
//        }
//        return null;
//    }
//    private static JSONObject buildDouYinData(JSONObject jsonData) {
//        JSONObject douYData = new JSONObject();
//        douYData.put("desc", jsonData.getString("desc"));
//
//        JSONObject author = jsonData.getJSONObject("author");
//        douYData.put("nickname", author.getString("nickname"));
//
//        JSONObject videoJson = jsonData.getJSONObject("video");
//        JSONObject coverJson = videoJson.getJSONObject("cover");
//        String coverUrl = coverJson.getJSONArray("url_list").getString(0);
//        douYData.put("coverUrl", coverUrl);
//
//        if (jsonData.getJSONArray("images") != null) {
//            JSONArray images = jsonData.getJSONArray("images");
//            JSONArray imageArray = new JSONArray();
//
//            for (int i = 0; i < images.size(); i++) {
//                JSONObject image = images.getJSONObject(i);
//                JSONArray urlList = image.getJSONArray("url_list");
//                imageArray.add(urlList.get(0));
//            }
//
//            douYData.put("type", 2);
//            douYData.put("data", imageArray);
//        } else {
//            JSONObject playAddr = videoJson.getJSONObject("play_addr");
//            String uri = playAddr.getString("uri");
//            String videoUrl = "https://www.iesdouyin.com/aweme/v1/play/?video_id=" + uri + "&ratio=1080p&line=0";
//            douYData.put("type", 1);
//            douYData.put("data", videoUrl);
//        }
//
//        return douYData;
//    }
//    public static String processContent(String content) {
//        String douyinUrl = extractMatch(content, "v\\.douyin\\.com/[a-zA-Z0-9]+");
//        if (douyinUrl != null) {
//            return "https://" + douyinUrl;
//        }
//        String digit = extractMatch(content, "\\d{19}");
//        return digit;
//    }
//    private static String extractMatch(String content, String regex) {
//        Pattern pattern = Pattern.compile(regex);
//        Matcher matcher = pattern.matcher(content);
//        return matcher.find() ? matcher.group(0) : null;
//    }
//    public static boolean isNumeric(String str) {
//        return str.matches("\\d+");
//    }
//    private static String extractUrl(String text) {
//        // 匹配网址的正则表达式
//        String regex = "https?://\\S+";
//        Pattern pattern = Pattern.compile(regex);
//        Matcher matcher = pattern.matcher(text);
//
//        // 查找匹配的链接
//        if (matcher.find()) {
//            return matcher.group();
//        }
//
//        return null;
//    }
//    public static String extractVideoId(String link) {
//        String redirectLink = getRedirectUrl(link);
//        Pattern patternVideo = Pattern.compile("/video/(\\d+)");
//        Pattern patternNote = Pattern.compile("/note/(\\d+)");
//
//        Matcher matcherVideo = patternVideo.matcher(redirectLink);
//        Matcher matcherNote = patternNote.matcher(redirectLink);
//
//        if (matcherVideo.find()) {
//            return matcherVideo.group(1);
//        } else if (matcherNote.find()) {
//            return matcherNote.group(1);
//        } else {
//            return null;
//        }
//    }
//    public static String getRedirectUrl(String url) {
//        OkHttpClient client = new OkHttpClient();
//        try {
//            Request request = new Request.Builder()
//                    .url(url)
//                    .get()
//                    .build();
//            Response response = client.newCall(request).execute();
//            return response.request().url().toString();
//
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//
//        return null;
//    }
//    private static JSONArray serverGetDy(String itemIds){
//        OkHttpClient client = new OkHttpClient().newBuilder().build();
//        Request Request = new Request.Builder()
//                //不知道这个a_bogus是啥 可能是个算法 随便填写或空即可
//                .url("https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?reflow_source=reflow_page&item_ids="+itemIds+"&a_bogus=sdfds")
//                .addHeader("content-type", "application/x-www-form-urlencoded")
//                .get()
//                .build();
//        try {
//            Response response = client.newCall(Request).execute();
//            JSONObject jsonObject= JSONObject.parseObject(response.body().string());
//            if (jsonObject.getInteger("status_code").equals(0)){
//                return jsonObject.getJSONArray("item_list");
//            }
//            return null;
//        } catch (IOException e) {
//            e.printStackTrace();
//            return null;
//        }
//    }
//}