admin
2021-03-26 998b6bd2a1dc25ec8350f5a691c3cd44a23d6d14
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
package com.yeshi.buwan.util.video;
 
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
 
import javax.persistence.Entity;
 
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;
import com.yeshi.buwan.util.LogUtil;
import com.yeshi.buwan.util.StringUtil;
 
@Entity
public class FengXingVideoUtil {
 
    public static final int TYPE_DIANYING = 1;
    public static final int TYPE_DIANSHIJU = 2;
    public static final int TYPE_DONGMAN = 3;
    // String url = "http://www.iqiyi.com/a_19rrk101r5.html#vfrm=2-4-0-1";
 
    // 电影
    public static final String DIANYING_ALL = "http://www.fun.tv/retrieve/c-e794b5e5bdb1.n-e5bdb1e78987.o-mf.p-e5858de8b4b9.pg-1";
 
    public static final String DIANYING_KEHUAN = "http://www.youku.com/v_olist/c_96_g_%E7%A7%91%E5%B9%BB_a__sg__mt__lg__q__s_1_r_0_u_1_pt_1_av_0_ag_0_sg__pr__h__d_1_p_1.html";
    public static final String DIANYING_XIJU = "http://www.youku.com/v_olist/c_96_g_%E5%96%9C%E5%89%A7_a__sg__mt__lg__q__s_1_r_0_u_1_pt_1_av_0_ag_0_sg__pr__h__d_1_p_1.html";
    public static final String DIANYING_AIQING = "http://www.youku.com/v_olist/c_96_g_%E7%88%B1%E6%83%85_a__sg__mt__lg__q__s_1_r_0_u_1_pt_1_av_0_ag_0_sg__pr__h__d_1_p_1.html";
    public static final String DIANYING_DONGZUO = "http://www.fun.tv/retrieve/c-e794b5e5bdb1.n-e5bdb1e78987.o-mf.pg-1.t-e58aa8e4bd9c";
    public static final String DIANYING_QIANGZHAN = "http://www.youku.com/v_olist/c_96_g_%E6%88%98%E4%BA%89_a__sg__mt__lg__q__s_1_r_0_u_1_pt_1_av_0_ag_0_sg__pr__h__d_1_p_1.html";
    public static final String DIANYING_JINGSONG = "http://www.youku.com/v_olist/c_96_g_%E6%83%8A%E6%82%9A_a__sg__mt__lg__q__s_1_r_0_u_1_pt_1_av_0_ag_0_sg__pr__h__d_1_p_1.html";
    public static final String DIANYING_KONGBU = "http://www.youku.com/v_olist/c_96_g_%E6%81%90%E6%80%96_a__sg__mt__lg__q__s_1_r_0_u_1_pt_1_av_0_ag_0_sg__pr__h__d_1_p_1.html";
    public static final String DIANYING_XUANYI = "http://www.youku.com/v_olist/c_96_g_%E6%82%AC%E7%96%91_a__sg__mt__lg__q__s_1_r_0_u_1_pt_1_av_0_ag_0_sg__pr__h__d_1_p_1.html";
    public static final String DIANYING_WUXIA = "http://www.youku.com/v_olist/c_96_g_%E6%AD%A6%E4%BE%A0_a__sg__mt__lg__q__s_1_r_0_u_1_pt_1_av_0_ag_0_sg__pr__h__d_1_p_1.html";
    public static final String DIANYING_JUQING = "http://www.youku.com/v_olist/c_96_g_%E5%89%A7%E6%83%85_a__sg__mt__lg__q__s_1_r_0_u_1_pt_1_av_0_ag_0_sg__pr__h__d_1_p_1.html";
 
    // 动漫
 
    private String getUrlByPage(int page, String type) {
 
        return type.replace(".pg-1", ".pg-" + page);
    }
 
    private VideoType getVideoType(String type) {
        VideoType videoType = new VideoType();
        int typeId = 0;
        if (type.equalsIgnoreCase(DIANYING_AIQING)) {
            typeId = 43;
        } else if (type.equalsIgnoreCase(DIANYING_DONGZUO)) {
            typeId = 44;
        } else if (type.equalsIgnoreCase(DIANYING_JINGSONG)) {
            typeId = 47;
        } else if (type.equalsIgnoreCase(DIANYING_JUQING)) {
            typeId = 55;
        } else if (type.equalsIgnoreCase(DIANYING_KEHUAN)) {
            typeId = 3;
        } else if (type.equalsIgnoreCase(DIANYING_KONGBU)) {
            typeId = 48;
        } else if (type.equalsIgnoreCase(DIANYING_XIJU)) {
            typeId = 41;
        } else if (type.equalsIgnoreCase(DIANYING_XUANYI)) {
            typeId = 49;
        }
        videoType.setId(1);
        return videoType;
    }
 
    public List<VideoInfo> getDianYingList(int page, String type) throws IOException {
        LogUtil.i(getUrlByPage(page, type));
        Document doc = Jsoup.connect(getUrlByPage(page, type)).get();
        Element root = doc.getElementsByAttributeValue("class", "mod-wrap-in mod-vd-lay-c6 fix").get(0);
        Elements elements = root.getElementsByAttributeValueContaining("class", "mod-vd-i");
 
        List<VideoInfo> videoList = new ArrayList<VideoInfo>();
        for (int i = elements.size() - 1; i >= 0; i--) {
            try {
                AdminInfo admin = new AdminInfo();
                admin.setId("1");
                VideoResource vr = new VideoResource("5");
 
                VideoInfo info = new VideoInfo();
                info.setCreatetime(System.currentTimeMillis());
                info.setVideoType(getVideoType(type));
                info.setAdmin(admin);
                info.setOrderby("0");
                info.setWatchCount("0");
                info.setQulity("高清");
                info.setShow("1");
 
                info.setNowNumber("1");
                info.setFinish("1");
 
                info.setPicture(elements.get(i).getElementsByAttributeValue("class", "pic").get(0)
                        .getElementsByTag("img").attr("_lazysrc"));
 
                String mainUrl = "http://www.fun.tv" + elements.get(i).getElementsByAttributeValue("class", "info")
                        .get(0).getElementsByTag("a").get(0).attr("href");
                info.setBaseurl(mainUrl);
                String name = elements.get(i).getElementsByAttributeValue("class", "info").get(0).getElementsByTag("a")
                        .get(0).text();
                info.setName(name);
                try {
                    info.setScore(elements.get(i).getElementsByAttributeValue("class", "score").get(0).text());
                } catch (Exception e) {
                    info.setScore("0");
                }
                doc = Jsoup.connect(mainUrl).timeout(20000).get();
                Element baseInfo = doc.getElementsByAttributeValue("class", "datum").get(0);
 
                // 主演
                Elements actors = baseInfo.getElementsByTag("p").get(1).getElementsByTag("span");
                String actor = "";
                for (Element ac : actors) {
                    actor += ac.text() + " ";
                }
                info.setMainActor(actor.replace("/", ""));
 
                // 电影的类型
                Elements types = baseInfo.getElementsByTag("p").get(2).getElementsByTag("span");
                String beizhu = "";
                for (Element ty : types) {
                    beizhu += ty.text() + " ";
                }
                info.setBeizhu(actor.replace("/", ""));
                try {
                    info.setIntroduction(baseInfo.getElementsByTag("p").get(3).getElementsByTag("span").get(1).text());
                } catch (Exception e) {
                    info.setIntroduction(baseInfo.getElementsByTag("p").get(3).getElementsByTag("span").get(0).text());
                }
                info.setYear("2014");
 
                VideoDetailInfo detail = new VideoDetailInfo();
                detail.setAdmin(admin);
                detail.setBeizhu("系统添加");
                detail.setCreatetime(System.currentTimeMillis() + "");
                detail.setName(info.getName());
 
                VideoUrl videoUrl = new VideoUrl();
                videoUrl.setAdmin(admin);
                videoUrl.setCreatetime(System.currentTimeMillis() + "");
                videoUrl.setResource(vr);
                videoUrl.setUrl(mainUrl);
                List<VideoUrl> urlList = new ArrayList<VideoUrl>();
                urlList.add(videoUrl);
                detail.setUrls(urlList);
                List<VideoDetailInfo> detailList = new ArrayList<VideoDetailInfo>();
                detailList.add(detail);
 
                info.setVideoDetailList(detailList);
                videoList.add(info);
                LogUtil.i("视频解析完毕:" + info.getName());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return videoList;
    }
 
    private String getNumberFromString(String str) {
 
        str = str.trim();
        String str2 = "";
        if (str != null && !"".equals(str)) {
            for (int i = 0; i < str.length(); i++) {
                if (str.charAt(i) >= 48 && str.charAt(i) <= 57) {
                    str2 += str.charAt(i);
                }
            }
        }
        if (StringUtil.isNullOrEmpty(str2))
            return "0";
        else
            return str2;
    }
 
    /**
     * 爱奇艺电视剧
     * 
     * @param info
     * @param url
     * @return
     */
    public VideoInfo getDianShiJuDetail(VideoInfo info, String url) {
        try {
            info.setBaseurl(url);
            Document doc = Jsoup.connect(url).get();
            Elements fenshus = doc.getElementsByAttributeValue("class", "fenshu-r");
            if (fenshus == null || fenshus.size() == 0) {
                fenshus = doc.getElementsByAttributeValue("class", "sub-font");
            }
 
            if (fenshus.size() > 0) {
                LogUtil.i("分数:" + fenshus.get(0).text());
                info.setScore(fenshus.get(0).text());
            } else {
                LogUtil.i("分数:9.0");
                info.setScore("9.0");
            }
            // fenshu-r-分数
 
            Elements actors = doc.getElementsByAttributeValue("class", "li-large");
            Elements actorList = null;
            if (actors == null || actors.size() == 0) {
                actors = doc.getElementsByAttributeValue("class", "role-album");
                if (actors != null)
                    actorList = actors.get(0).getElementsByTag("a");
            } else {
                actorList = actors.get(1).getElementsByTag("a");
            }
            String actor = "";
            for (Element es : actorList)
                actor += es.text() + " ";
            LogUtil.i("主演:" + actor);
            info.setMainActor(actor);
            // bigPic-b-jtxt--简介
            Elements inList = doc.getElementsByAttributeValue("class", "bigPic-b-jtxt");
            Element introduction;
            if (inList == null || inList.size() == 0) {
                introduction = doc.getElementsByAttributeValue("data-moreorless", "moreinfo").get(0);
            } else {
                introduction = inList.get(0);
            }
            // data-moreorless
            info.setIntroduction(introduction.text());
            LogUtil.i("简介:" + introduction.text());
            // wrapper-piclist --分级
            Element ul = doc.getElementsByAttributeValue("class", "wrapper-piclist").get(0);
            Elements lis = ul.getElementsByTag("li");
 
            List<VideoDetailInfo> detailList = new ArrayList<VideoDetailInfo>();
            int i = 1;
            for (Element elt : lis) {
                AdminInfo admin = new AdminInfo();
                admin.setId("1");
                VideoDetailInfo detail = new VideoDetailInfo();
                Element urlElement = elt.getElementsByTag("div").get(0).getElementsByTag("a").get(0);
                detail.setAdmin(admin);
                detail.setBeizhu("系统添加");
                detail.setIntroduction(urlElement.attr("title"));
                detail.setName(info.getName());
                detail.setTag("" + (i++));
                detail.setCreatetime(System.currentTimeMillis() + "");
                VideoResource vr = new VideoResource();
                vr.setId("8");// 爱奇艺
                List<VideoUrl> urlList = new ArrayList<VideoUrl>();
                VideoUrl detailUrl = new VideoUrl();
                detailUrl.setAdmin(admin);
                detailUrl.setCreatetime(System.currentTimeMillis() + "");
                detailUrl.setBeizhu("系统添加");
                detailUrl.setUrl(urlElement.attr("href"));
                detailUrl.setResource(vr);
                urlList.add(detailUrl);
                detail.setUrls(urlList);
                LogUtil.i("单集链接:" + urlElement.attr("href"));
                LogUtil.i("单集的简介:" + urlElement.attr("title"));
 
                detailList.add(detail);
            }
            info.setVideoDetailList(detailList);
            return info;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
 
    //
 
    /**
     * 爱奇艺电影
     * 
     * @param info
     * @param url
     * @return
     */
    public VideoInfo getDianYingDetail(VideoInfo info, String url) {
        try {
            info.setBaseurl(url);
            Document doc = Jsoup.connect(url).get();
            Elements fenshus = doc.getElementsByAttributeValue("class", "fenshu-r");
            if (fenshus == null || fenshus.size() == 0) {
                fenshus = doc.getElementsByAttributeValue("class", "sub-font");
            }
 
            info.setScore("9.0");
 
            // fenshu-r-分数
 
            Element actors = doc.getElementById("datainfo-actor-list");
            Elements actorList = actors.getElementsByTag("a");
 
            if (actorList != null && actorList.size() != 0) {
                String actor = "";
                for (Element es : actorList)
                    actor += es.text() + " ";
                LogUtil.i("主演:" + actor);
                info.setMainActor(actor);
            }
            // 简介
            Element introduction = doc.getElementById("datainfo-desc-text");
            if (introduction != null) {
                info.setIntroduction(introduction.attr("data-desc-origin"));
                LogUtil.i("简介:" + introduction.attr("data-desc-origin"));
            }
 
            List<VideoDetailInfo> detailList = new ArrayList<VideoDetailInfo>();
 
            AdminInfo admin = new AdminInfo();
            admin.setId("1");
            VideoDetailInfo detail = new VideoDetailInfo();
 
            detail.setAdmin(admin);
            detail.setBeizhu("系统添加");
            detail.setName(info.getName());
            detail.setTag("1");
 
            VideoResource vr = new VideoResource();
            vr.setId("8");// 爱奇艺
            List<VideoUrl> urlList = new ArrayList<VideoUrl>();
            VideoUrl detailUrl = new VideoUrl();
            detailUrl.setAdmin(admin);
            detailUrl.setCreatetime(System.currentTimeMillis() + "");
            detailUrl.setBeizhu("系统添加");
            detailUrl.setUrl(url);
            detailUrl.setResource(vr);
            urlList.add(detailUrl);
            detail.setUrls(urlList);
 
            detailList.add(detail);
 
            info.setVideoDetailList(detailList);
            return info;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
 
    /**
     * 爱奇艺动漫
     * 
     * @param info
     * @param url
     * @return
     */
    public VideoInfo getDongManDetail(VideoInfo info, String url) {
        try {
            info.setBaseurl(url);
            Document doc = Jsoup.connect(url).get();
            Elements fenshus = doc.getElementsByAttributeValue("class", "fenshu-r");
            if (fenshus == null || fenshus.size() == 0) {
                fenshus = doc.getElementsByAttributeValue("class", "sub-font");
            }
 
            if (fenshus.size() > 0) {
                LogUtil.i("分数:" + fenshus.get(0).text());
                info.setScore(fenshus.get(0).text());
            } else {
                LogUtil.i("分数:9.0");
                info.setScore("9.0");
            }
            // fenshu-r-分数
            // bigPic-b-jtxt--简介
            Elements inList = doc.getElementsByAttributeValue("class", "bigPic-b-jtxt");
            Element introduction;
            try {
                if (inList == null || inList.size() == 0) {
                    introduction = doc.getElementsByAttributeValue("data-moreorless", "moreinfo").get(0);
                } else {
                    introduction = inList.get(0);
                }
                // data-moreorless
                info.setIntroduction(introduction.text());
                LogUtil.i("简介:" + introduction.text());
            } catch (Exception e) {
                LogUtil.i("没有简介");
            }
 
            // wrapper-piclist --分级
            Element ul = doc.getElementsByAttributeValue("class", "wrapper-piclist").get(0);
            Elements lis = ul.getElementsByTag("li");
 
            AdminInfo admin = new AdminInfo();
            admin.setId("1");
 
            List<VideoDetailInfo> detailList = new ArrayList<VideoDetailInfo>();
            int i = 1;
            for (Element elt : lis) {
 
                VideoDetailInfo detail = new VideoDetailInfo();
                Element urlElement = elt.getElementsByTag("div").get(0).getElementsByTag("a").get(0);
                detail.setAdmin(admin);
                detail.setBeizhu("系统添加");
                detail.setIntroduction(urlElement.attr("title"));
                detail.setName(info.getName());
                detail.setTag("" + (i++));
 
                VideoResource vr = new VideoResource();
                vr.setId("8");// 爱奇艺
                List<VideoUrl> urlList = new ArrayList<VideoUrl>();
                VideoUrl detailUrl = new VideoUrl();
                detailUrl.setAdmin(admin);
                detailUrl.setCreatetime(System.currentTimeMillis() + "");
                detailUrl.setBeizhu("系统添加");
                detailUrl.setUrl(urlElement.attr("href"));
                detailUrl.setResource(vr);
                urlList.add(detailUrl);
                detail.setUrls(urlList);
                LogUtil.i("单集链接:" + urlElement.attr("href"));
                LogUtil.i("单集的简介:" + urlElement.attr("title"));
 
                detailList.add(detail);
            }
            info.setVideoDetailList(detailList);
            return info;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
 
    public String get(String url) {
        HttpClient client = new HttpClient();
        GetMethod method = new GetMethod(url);
        try {
            client.executeMethod(method);
            String responseBodyAsString = method.getResponseBodyAsString();
            LogUtil.i(responseBodyAsString);
            return responseBodyAsString;
        } catch (HttpException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
}