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 dao = new BaseDao(); List 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 dao = new BaseDao(); List 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 dao = new BaseDao(); List 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 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 ""; } }