admin
2021-01-04 aa6ef62aef83e277d4171df1d9f0803f91738216
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
package com.newvideo.util.video;
 
import java.io.IOException;
import java.util.Iterator;
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.select.Elements;
 
import com.newvideo.dao.BaseDao;
import com.newvideo.domain.LeShiMovieVip;
import com.newvideo.util.StringUtil;
 
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
 
public class LeShiVipUtil {
    private static String get(String url) {
        HttpClient client = new HttpClient();
        GetMethod get = new GetMethod(url);
        try {
            client.executeMethod(get);
            String result = get.getResponseBodyAsString();
            return result;
 
        } catch (HttpException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return "";
    }
 
    public static LeShiMovieVip getVIPInfoFromLocal(String url) {
        String newUrl = url.replace("?leshivip=1", "");
        BaseDao<LeShiMovieVip> dao = new BaseDao<LeShiMovieVip>();
        List<LeShiMovieVip> list = dao.list("from LeShiMovieVip vp where vp.url=?", new String[] { newUrl });
        if (list != null && list.size() > 0)
            return list.get(0);
        return null;
    }
 
    public static LeShiMovieVip getVIPInfo(String url) {
        BaseDao<LeShiMovieVip> dao = new BaseDao<LeShiMovieVip>();
        List<LeShiMovieVip> list = dao.list("from LeShiMovieVip v where v.url=?", new String[] { url });
        if (list != null && list.size() > 0)
            return list.get(0);
        LeShiMovieVip vip = new LeShiMovieVip();
        org.jsoup.nodes.Document doc = null;
        try {
            doc = Jsoup.connect(url).timeout(20000).get();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Elements els = doc.getElementsByTag("script");
        for (int i = 0; i < els.size(); i++) {
            if (els.get(i).toString().contains("var __INFO__ =")) {
                String info = els.get(i).toString();
                int endIndex = info.indexOf("};");
                int startIndex = info.indexOf("var __INFO__ =");
                info = info.substring(startIndex, endIndex) + "}";
                info = info.replace("var __INFO__ =", "");
                String vid = info.split("vid:")[1];
                endIndex = vid.indexOf(",");
                String mmsid = info.split("mmsid:")[1];
                endIndex = mmsid.indexOf(",");
                vip.setMid(mmsid.substring(0, endIndex).trim());
                vip.setVid(vid.substring(0, endIndex).trim());
                vip.setCreatetime(System.currentTimeMillis() + "");
                vip.setUrl(url);
                break;
            }
        }
        return vip;
    }
 
    public static void addVipInfo(LeShiMovieVip vip) {
        BaseDao<LeShiMovieVip> dao = new BaseDao<LeShiMovieVip>();
        List<LeShiMovieVip> list = dao.list("from LeShiMovieVip v where v.url=?", new String[] { vip.getUrl() });
        if (list == null || list.size() == 0) {
            dao.create(vip);
        }
    }
 
    public static String getFirstRequestUrl(LeShiMovieVip vip) {
        String time = System.currentTimeMillis() / 1000 + "";
 
        return "http://dynamic.app.m.letv.com/android/dynamic.php?mod=minfo&ctl=videofile&act=index&mmsid="
                + vip.getMid() + "&playid=2&tss=no&tm=" + time + "&key="
                + StringUtil.Md5(vip.getMid() + "," + time + ",bh65OzqYYYmHRQ")
                + "&pcode=010110041&version=5.9.8&levelType=1&vid=" + vip.getVid();
    }
 
    public static String parseFirstResponse(String result) {
        JSONObject root = JSONObject.fromObject(result);
        if (root != null) {
            JSONObject data = root.optJSONObject("body");
            if (data != null) {
                data = data.optJSONObject("videofile");
                if (data != null) {
                    data = data.optJSONObject("infos");
                    if (data != null) {
 
                        if (data.optJSONObject("mp4_1000") != null) {
                            return data.optJSONObject("mp4_1000").optString("mainUrl");
                        } else if (data.optJSONObject("mp4_1300") != null) {
                            return data.optJSONObject("mp4_1300").optString("mainUrl");
                        } else if (data.optJSONObject("mp4_350") != null) {
                            return data.optJSONObject("mp4_350").optString("mainUrl");
                        } else if (data.optJSONObject("mp4_180") != null) {
                            return data.optJSONObject("mp4_180").optString("mainUrl");
                        } else {
                            Iterator<String> its = data.keys();
                            if (its.hasNext()) {
                                String key = its.next();
                                return data.optJSONObject(key).optString("mainUrl");
                            }
                        }
 
                    }
 
                }
            }
        }
        return "";
    }
 
    public static String parseSecondResponse(String result) {
        JSONObject root =JSONObject.fromObject(result);
        if (root != null) {
            JSONArray array = root.optJSONArray("nodelist");
            if (array.size() > 0)
                return array.optJSONObject(0).optString("location");
        }
        return "";
    }
}