admin
2021-04-30 cd4a4617fd33b0e25185ab2012a536821420fd80
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
package com.yeshi.buwan.util;
 
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
 
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.GetMethod;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
 
import com.yeshi.buwan.domain.AdminInfo;
import com.yeshi.buwan.domain.VideoDetailInfo;
import com.yeshi.buwan.domain.VideoInfo;
import com.yeshi.buwan.domain.VideoResource;
import com.yeshi.buwan.domain.VideoType;
import com.yeshi.buwan.domain.VideoUrl;
 
public class MangGuoUtil {
    public static final int TYPE_ZONGYI = 1;
    public static final int TYPE_DIANSHIJU = 2;
    public static final int TYPE_DIANYING = 3;
    public static final String DIANYING_DONGZUO = "http://list.hunantv.com/3/47-----0-----1---.html";
    public static final String DIANYING_MAOXIAN = "http://list.hunantv.com/3/48-----0-----1---.html";
    public static final String DIANYING_XIJU = "http://list.hunantv.com/3/49-----0-----1---.html";
    public static final String DIANYING_AIQING = "http://list.hunantv.com/3/50-----0-----1---.html";
    public static final String DIANYING_ZHANZHENG = "http://list.hunantv.com/3/51-----0-----1---.html";
    public static final String DIANYING_KONGBU = "http://list.hunantv.com/3/52-----0-----1---.html";
    public static final String DIANYING_FANZUI = "http://list.hunantv.com/3/53-----0-----1---.html";
    public static final String DIANYING_XUANYI = "http://list.hunantv.com/3/54-----0-----1---.html";
    public static final String DIANYING_JINGSONG = "http://list.hunantv.com/3/55-----0-----1---.html";
    public static final String DIANYING_WUXIA = "http://list.hunantv.com/3/56-----0-----1---.html";
    public static final String DIANYING_KEHUAN = "http://list.hunantv.com/3/57-----0-----1---.html";
    public static final String DIANYING_GEWU = "http://list.hunantv.com/3/59-----0-----1---.html";
    public static final String DIANYING_DONGHUA = "http://list.hunantv.com/3/60-----0-----1---.html";
    public static final String DIANYING_QIHUAN = "http://list.hunantv.com/3/61-----0-----1---.html";
    public static final String DIANYING_JUQING = "http://list.hunantv.com/3/63-----0-----1---.html";
    public static final String DIANYING_LUNLI = "http://list.hunantv.com/3/64-----0-----1---.html";
    public static final String DIANYING_QINCHUN = "http://list.hunantv.com/3/126-----0-----1---.html";
    public static final String DIANYING_JILU = "http://list.hunantv.com/3/65-----0-----1---.html";
    public static final String DIANYING_LISHI = "http://list.hunantv.com/3/66-----0-----1---.html";
    public static final String DIANYING_ZHUANJI = "http://list.hunantv.com/3/67-----0-----1---.html";
    public static final String DIANYING_QITA = "http://list.hunantv.com/3/127-----0-----1---.html";
 
    public static String getUrlByPage(String type, int page) {
        return type.replace("1---.html", page + "---.html");
    }
 
    public static VideoType getDianYingVideoType(String type) {
        VideoType vt = new VideoType(1);
        if (type.equalsIgnoreCase(DIANYING_AIQING)) {
            vt.setId(43);
        } else if (type.equalsIgnoreCase(DIANYING_DONGHUA)) {
            vt.setId(127);
        } else if (type.equalsIgnoreCase(DIANYING_DONGZUO)) {
            vt.setId(44);
        } else if (type.equalsIgnoreCase(DIANYING_FANZUI)) {
            vt.setId(46);
        } else if (type.equalsIgnoreCase(DIANYING_GEWU)) {
            vt.setId(1);
        } else if (type.equalsIgnoreCase(DIANYING_JILU)) {
            vt.setId(1);
        } else if (type.equalsIgnoreCase(DIANYING_JINGSONG)) {
            vt.setId(47);
        } else if (type.equalsIgnoreCase(DIANYING_JUQING)) {
            vt.setId(55);
        } else if (type.equalsIgnoreCase(DIANYING_KEHUAN)) {
            vt.setId(3);
        } else if (type.equalsIgnoreCase(DIANYING_KONGBU)) {
            vt.setId(48);
        } else if (type.equalsIgnoreCase(DIANYING_LISHI)) {
            vt.setId(1);
        } else if (type.equalsIgnoreCase(DIANYING_MAOXIAN)) {
            vt.setId(1);
        } else if (type.equalsIgnoreCase(DIANYING_QIHUAN)) {
            vt.setId(1);
        } else if (type.equalsIgnoreCase(DIANYING_QITA)) {
            vt.setId(1);
        } else if (type.equalsIgnoreCase(DIANYING_WUXIA)) {
            vt.setId(1);
        } else if (type.equalsIgnoreCase(DIANYING_XIJU)) {
            vt.setId(41);
        } else if (type.equalsIgnoreCase(DIANYING_XUANYI)) {
            vt.setId(49);
        } else if (type.equalsIgnoreCase(DIANYING_ZHUANJI)) {
            vt.setId(1);
        }
        return vt;
    }
 
    public static List<VideoDetailInfo> getZongYiByHtml(String url,
            VideoInfo info) {
        List<VideoDetailInfo> detailList = new ArrayList<>();
        Document doc = Jsoup.parse(get(url));
        Element els = null;
        try {
            els = doc.getElementsContainingOwnText("正片播放").get(0);
        } catch (Exception e) {
            return null;
        }
        els = Jsoup.parse(get(els.attr("href")))
                .getElementsByAttributeValue("class", "clearfix ullist-ele")
                .get(0);
        if (els == null)
            return null;
        Elements deEls = els.getElementsByTag("li");
        for (int i = 0; i < deEls.size(); i++) {
            VideoDetailInfo detailInfo = new VideoDetailInfo();
            Element e = deEls.get(i);
            String tag = e.getElementsByAttributeValue("class", "a-pic-t1")
                    .get(0).text().replace("第", "").replace("期", "");
            detailInfo.setTag(tag);
            detailInfo.setName(info.getName());
 
            String introduction = e
                    .getElementsByAttributeValue("class", "a-pic-t2").get(0)
                    .text();
            detailInfo.setIntroduction(introduction);
 
            detailInfo.setAdmin(new AdminInfo("1"));
            detailInfo.setCreatetime(System.currentTimeMillis() + "");
            List<VideoUrl> list = new ArrayList<>();
            VideoUrl videoUrl = new VideoUrl();
            videoUrl.setAdmin(new AdminInfo("1"));
            videoUrl.setBaseUrl(url);
            videoUrl.setCreatetime(System.currentTimeMillis() + "");
            videoUrl.setInvalid("0");
            videoUrl.setResource(new VideoResource("3"));
            String vurl = e.getElementsByTag("a").get(0).attr("href");
            videoUrl.setUrl(vurl);
            list.add(videoUrl);
            detailInfo.setUrls(list);
            detailList.add(detailInfo);
            if (detailList.size() > 100)
                break;
        }
        return detailList;
    }
 
    public static List<VideoDetailInfo> getDianShiJuByHtml(String url,
            VideoInfo info) {
        List<VideoDetailInfo> detailList = new ArrayList<>();
        Document doc = Jsoup.parse(get(url));
        Element els = doc.getElementById("tvplay-box");
        Elements deEls = els.getElementsByTag("li");
        for (int i = 0; i < deEls.size(); i++) {
            VideoDetailInfo detailInfo = new VideoDetailInfo();
            Element e = deEls.get(i);
            String tag = e.getElementsByAttributeValue("class", "a-pic-t1")
                    .get(0).text();
 
            detailInfo.setTag(tag);
            detailInfo.setName(info.getName());
 
            String introduction = e
                    .getElementsByAttributeValue("class", "a-pic-t2").get(0)
                    .text();
            detailInfo.setIntroduction(introduction);
 
            detailInfo.setAdmin(new AdminInfo("1"));
            detailInfo.setCreatetime(System.currentTimeMillis() + "");
            List<VideoUrl> list = new ArrayList<>();
            VideoUrl videoUrl = new VideoUrl();
            videoUrl.setAdmin(new AdminInfo("1"));
            videoUrl.setBaseUrl(url);
            videoUrl.setCreatetime(System.currentTimeMillis() + "");
            videoUrl.setInvalid("0");
            videoUrl.setResource(new VideoResource("3"));
            String vurl = "http://www.hunantv.com"
                    + e.getElementsByTag("a").get(0).attr("href");
            videoUrl.setUrl(vurl);
            list.add(videoUrl);
            detailInfo.setUrls(list);
            detailList.add(detailInfo);
        }
        return detailList;
    }
 
    public static VideoType getVideoType(String url) {
        return null;
    }
 
    public static List<VideoInfo> getDianYingList(String url, int page) {
        VideoType videoType = getDianYingVideoType(url);
        Document doc = Jsoup.parse(get(url));
        Element root = doc.getElementsByAttributeValue("class",
                "clearfix ullist-ele").get(0);
        Elements roots = root.getElementsByTag("li");
        List<VideoInfo> list = new ArrayList<>();
        for (int i = 0; i < roots.size(); i++) {
 
            AdminInfo admin = new AdminInfo("1");
            VideoInfo info = new VideoInfo();
            info.setAdmin(admin);
            Element e = roots.get(i);
            e = e.getElementsByAttributeValue("class", "img-box").get(0);
            String picture = e.getElementsByTag("img").attr("data-original");
            String tag = "";
            String[] scores = new String[] { "9.0", "8.9", "9.3", "9.6" };
            tag = "评分:" + scores[(int) ((Math.random()) * (scores.length))];
            String baseUrl = e.getElementsByTag("a").get(0).attr("href");
            String name = e.getElementsByTag("a").get(0).attr("title");
            info.setName(name);
            info.setBaseurl(baseUrl);
            info.setTag(tag);
            info.setPicture(picture);
            info.setAdmin(new AdminInfo("1"));
            info.setCreatetime(System.currentTimeMillis());
            info.setOrderby("2");
            info.setQulity("高清");
            info.setCanSave(true);
            info.setShare("0");
            info.setShow("1");
            info.setThirdType("0");
            info.setWatchCount("0");
            info.setYear("2015");
            info.setVideoType(videoType);
            List<VideoDetailInfo> detailList = new ArrayList<>();
            List<VideoUrl> urlList = new ArrayList<>();
            VideoUrl videoUrl = new VideoUrl();
            videoUrl.setAdmin(admin);
            videoUrl.setBaseUrl(baseUrl);
            videoUrl.setCreatetime(System.currentTimeMillis() + "");
            videoUrl.setInvalid("0");
            videoUrl.setResource(new VideoResource("3"));
            videoUrl.setUrl(baseUrl);
            urlList.add(videoUrl);
 
            VideoDetailInfo detailInfo = new VideoDetailInfo();
            detailInfo.setAdmin(admin);
            detailInfo.setCreatetime(System.currentTimeMillis() + "");
            detailInfo.setName(name);
            detailInfo.setUrls(urlList);
            detailList.add(detailInfo);
            info.setVideoDetailList(detailList);
            if (info.getVideoDetailList() != null
                    && info.getVideoDetailList().size() > 0)
                list.add(info);
        }
        return list;
    }
 
    public static List<VideoInfo> getVideoInfo(String url, int type) {
        Document doc = Jsoup.parse(get(url));
        Element root = doc.getElementsByAttributeValue("class",
                "clearfix ullist-ele").get(0);
        Elements roots = root.getElementsByTag("li");
        List<VideoInfo> list = new ArrayList<>();
        for (int i = 0; i < roots.size(); i++) {
            VideoInfo info = new VideoInfo();
            Element e = roots.get(i);
            e = e.getElementsByAttributeValue("class", "img-box").get(0);
            String picture = e.getElementsByTag("img").attr("src");
            String tag = e.getElementsByAttributeValue("class", "a-pic-t3")
                    .get(0).text();
            tag = tag.replace("更新到", "").replace("期", "");
            String baseUrl = e.getElementsByTag("a").get(0).attr("href");
            String name = e.getElementsByTag("a").get(0).attr("title");
 
            info.setName(name);
            info.setBaseurl(baseUrl);
            info.setTag(tag);
            info.setPicture(picture);
            info.setAdmin(new AdminInfo("1"));
            info.setCreatetime(System.currentTimeMillis());
            info.setOrderby("2");
            info.setQulity("高清");
            info.setShare("0");
            info.setShow("1");
            if (type == TYPE_DIANSHIJU) {
                info.setVideoType(new VideoType(2));
                try {
                    List<VideoDetailInfo> detailList = getDianShiJuByHtml(
                            baseUrl, info);
                    if (detailList != null && detailList.size() > 0) {
                        info.setVideoDetailList(detailList);
                    }
                } catch (Exception ee) {
                    ee.printStackTrace();
                }
            } else if (type == TYPE_ZONGYI) {
                try {
                    info.setVideoType(new VideoType(18));
                    List<VideoDetailInfo> detailList = getZongYiByHtml(baseUrl,
                            info);
                    if (detailList != null && detailList.size() > 0) {
                        info.setVideoDetailList(detailList);
                    }
                } catch (Exception ee) {
                    ee.printStackTrace();
                }
            }
            info.setThirdType("0");
            info.setWatchCount("0");
            info.setYear("2015");
            if (info.getVideoDetailList() != null
                    && info.getVideoDetailList().size() > 0)
                list.add(info);
        }
        return list;
    }
 
    private static String get(String url) {
 
        HttpClient client = new HttpClient();
        client.getParams().setContentCharset("UTF-8");
        GetMethod method = new GetMethod(url);
        try {
            method.addRequestHeader("Content-Type", "text/html;charset=UTF-8");
            method.setRequestHeader("Content-Type", "text/html;charset=UTF-8");
            client.executeMethod(method);
            String responseBodyAsString = method.getResponseBodyAsString();
            // LogUtil.i(responseBodyAsString);
            return responseBodyAsString;
        } catch (HttpException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
}