admin
2021-04-16 6e365a48a83e628759df3a5f25b3db97009c9f26
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
package com.yeshi.buwan.util;
 
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;
 
@Entity
public class YouKuVideoUtil {
    public static String TYPE_DIANYING = "DIANYING";
    public static String TYPE_DIANSHIJU = "DIANSHIJU";
    public static String TYPE_DONGMAN = "DONGMAN";
    public static String TYPE_GAOXIAO = "GAOXIAO";
 
    public static String GAOXIAO_EGAODUANPIAN = "http://www.youku.com/v_showlist/c94g235d1s2p##.html";
    public static String GAOXIAO_GAOXIAOZIPAI = "http://www.youku.com/v_showlist/c94g236d1s2p##.html";
    public static String GAOXIAO_GAOXIAODONGWU = "http://www.youku.com/v_showlist/c94g238d1s2p##.html";
 
    public static VideoType getGaoXiaoType(String type) {
        if (type.equalsIgnoreCase(GAOXIAO_EGAODUANPIAN)) {
            return new VideoType(127);
        } else if (type.equalsIgnoreCase(GAOXIAO_GAOXIAODONGWU)) {
            return new VideoType(130);
        } else if (type.equalsIgnoreCase(GAOXIAO_GAOXIAOZIPAI)) {
            return new VideoType(126);
        }
        return null;
    }
 
    public static String getUrl(int page, String baseUrl) {
        return baseUrl.replace("##", page + "");
    }
 
    public static List<VideoInfo> getVideoList(String type, String detailType,
            int page) {
        if (type.equalsIgnoreCase(TYPE_GAOXIAO)) {
            return getGaoXiaoList(page, detailType);
        }
        return null;
    }
 
    public static List<VideoInfo> getGaoXiaoList(int page, String baseUrl) {
        List<VideoInfo> videoList = new ArrayList<VideoInfo>();
        VideoType vt = getGaoXiaoType(baseUrl);
        String bUrl = getUrl(page, baseUrl);
        Document doc=null;
        try {
            doc = Jsoup.connect(bUrl).timeout(20 * 1000).get();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Element root = doc.getElementById("getVideoList");
        Element content = root.getElementsByAttributeValue("class",
                "yk-row yk-v-90u").get(0);
        Elements array = content
                .getElementsByAttributeValue("class", "yk-col4");
        for (int i = array.size() - 1; i >= 0; i--) {
            VideoInfo info = new VideoInfo();
            Element els = array.get(i);
            String picture = els
                    .getElementsByAttributeValue("class", "v-thumb").get(0)
                    .getElementsByTag("img").attr("src");
            String time = els.getElementsByAttributeValue("class", "v-thumb")
                    .get(0).getElementsByAttributeValue("class", "v-time")
                    .get(0).text();
 
            String link = els.getElementsByAttributeValue("class", "v-link")
                    .get(0).getElementsByTag("a").get(0).attr("href");
 
            String name = els
                    .getElementsByAttributeValue("class", "v-meta-title")
                    .get(0).getElementsByTag("a").get(0).attr("title");
 
            info.setAdmin(new AdminInfo("1"));
            info.setBaseurl(link);
            info.setCanSave(true);
            info.setCreatetime(System.currentTimeMillis() );
            info.setName(name);
            info.setPicture(picture);
            info.setTag(time);
            info.setShare("0");
            info.setShow("1");
            info.setThirdType("0");
            info.setUpdatetime(System.currentTimeMillis() + "");
            info.setVideoType(vt);
            info.setWatchCount(0 + "");
 
            info.setYear("2016");
            info.setMonth("3");
            info.setDay("24");
 
            List<VideoDetailInfo> detailList = new ArrayList<VideoDetailInfo>();
 
            VideoDetailInfo vd = new VideoDetailInfo();
            vd.setAdmin(new AdminInfo("1"));
            vd.setCreatetime(System.currentTimeMillis() + "");
            vd.setName(name);
            vd.setVideo(info);
            List<VideoUrl> urlList = new ArrayList<VideoUrl>();
            VideoUrl vu = new VideoUrl();
            vu.setAdmin(new AdminInfo("1"));
            vu.setBaseUrl(link);
            vu.setCreatetime(System.currentTimeMillis() + "");
            vu.setInvalid("0");
            vu.setResource(new VideoResource("9"));
            vu.setUrl(link);
            urlList.add(vu);
            vd.setUrls(urlList);
            detailList.add(vd);
            info.setVideoDetailList(detailList);
            videoList.add(info);
        }
        return videoList;
    }
 
    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 "";
    }
}