package com.newvideo.util;
|
|
import java.io.IOException;
|
import java.io.UnsupportedEncodingException;
|
import java.net.URLEncoder;
|
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 com.newvideo.domain.AdminInfo;
|
import com.newvideo.domain.VideoDetailInfo;
|
import com.newvideo.domain.VideoInfo;
|
import com.newvideo.domain.VideoResource;
|
import com.newvideo.domain.VideoType;
|
import com.newvideo.domain.VideoUrl;
|
import com.newvideo.service.imp.VideoManager;
|
|
import net.sf.json.JSONArray;
|
import net.sf.json.JSONObject;
|
|
public class Le123Util {
|
private static String get(String url) {
|
|
HttpClient client = new HttpClient();
|
GetMethod method = new GetMethod(url);
|
try {
|
client.executeMethod(method);
|
String responseBodyAsString = method.getResponseBodyAsString();
|
return responseBodyAsString;
|
} catch (HttpException e) {
|
e.printStackTrace();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
return "";
|
}
|
|
public static void updateLatestMovie() {
|
String result = get(
|
"http://api.le123.com/kuaikan/apilistnew_json.so?orderby=1&vt=2&city=CN_22_758_2&code=346e5b9d1bd97036&uuid=a8d4236d-c05b-3aac-8cab-8eb139242db9&version=1.6.9&pagesize=18&pageindex=1&platform=Le123Plat0021&plattype=aphone");
|
JSONObject object =JSONObject.fromObject(result);
|
JSONArray array = object.optJSONArray("data");
|
List<VideoInfo> vlist = new ArrayList<VideoInfo>();
|
for (int i = 0; i < array.size(); i++) {
|
JSONObject obj = array.optJSONObject(i);
|
String aid = obj.optString("aid");
|
String pic = obj.optString("poster");
|
String name = obj.optString("name");
|
String cloudCode = getCloudCode(aid);
|
if (!StringUtil.isNullOrEmpty(cloudCode)) {
|
VideoInfo info = new VideoInfo();
|
info.setCanSave(true);
|
info.setAdmin(new AdminInfo("1"));
|
info.setCreatetime(System.currentTimeMillis());
|
info.setFinish("1");
|
info.setIntroduction("");
|
info.setName(name);
|
info.setOrderby("0");
|
info.setPicture(pic);
|
info.setQulity("高清");
|
info.setScore("9.0");
|
info.setShare("0");
|
info.setShow("1");
|
info.setTag("");
|
info.setThirdType("0");
|
info.setTotalNumber("0");
|
info.setVideoType(new VideoType(1));
|
info.setWatchCount("0");
|
info.setYear("2014");
|
|
List<VideoDetailInfo> detailList = new ArrayList<VideoDetailInfo>();
|
|
AdminInfo admin = new AdminInfo();
|
admin.setId("1");
|
VideoDetailInfo detail1 = new VideoDetailInfo();
|
|
detail1.setAdmin(admin);
|
detail1.setBeizhu("系统添加");
|
detail1.setName(info.getName());
|
detail1.setCreatetime(System.currentTimeMillis() + "");
|
|
VideoResource vr = new VideoResource();
|
vr.setId("1");// 乐视
|
List<VideoUrl> urlList = new ArrayList<VideoUrl>();
|
VideoUrl detailUrl = new VideoUrl();
|
detailUrl.setAdmin(admin);
|
detailUrl.setCreatetime(System.currentTimeMillis() + "");
|
detailUrl.setBeizhu("系统添加");
|
detailUrl.setUrl("http://cloud.letv.com?vid=http://www.le123.com?cloudcode=" + cloudCode);
|
detailUrl.setResource(vr);
|
detailUrl.setInvalid("0");
|
urlList.add(detailUrl);
|
detail1.setUrls(urlList);
|
detailList.add(detail1);
|
info.setVideoDetailList(detailList);
|
|
try {
|
List<VideoInfo> list = DouBanUtil.startSearch(info.getName());
|
if (list != null && list.size() > 0) {
|
for (VideoInfo v : list) {
|
if (v.getName().startsWith(info.getName())) {
|
info.setPicture(v.getPicture());
|
info.setIntroduction(v.getIntroduction());
|
info.setMainActor(v.getMainActor());
|
info.setScore(v.getScore());
|
info.setTag("评分:" + (StringUtil.isNullOrEmpty(v.getScore()) ? "9.0" : v.getScore()));
|
break;
|
}
|
|
}
|
|
}
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
vlist.add(info);
|
}
|
}
|
VideoManager videoManager = new VideoManager();
|
videoManager.addVideoInfo(vlist);
|
}
|
|
public static String getCloudCode(String aid) {
|
String result = get("http://api.le123.com/kuaikan/apiwebsitepaging_json.so?definition=1&aid=" + aid
|
+ "&city=CN_22_758_2&code=346e5b9d1bd97036&site=nets&uuid=a8d4236d-c05b-3aac-8cab-8eb139242db9&version=1.6.9&pagesize=100&pageindex=1&platform=Le123Plat0021&plattype=aphone");
|
try {
|
JSONObject obj = JSONArray.fromObject(result).optJSONObject(0);
|
if (obj.optString("sitename").equalsIgnoreCase("网络")) {
|
JSONArray array = obj.optJSONArray("videoList");
|
if (array != null && array.size() > 0) {
|
JSONObject ob = array.optJSONObject(0);
|
return ob.optString("cloudId");
|
}
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return "";
|
}
|
|
public static String search(String key) {
|
try {
|
String result = get("http://api.le123.com/kuaikan/apisearch_json.so?vt=2&wd="
|
+ URLEncoder.encode(key, "utf-8")
|
+ "&city=CN_22_758_2&code=346e5b9d1bd97036&uuid=a8d4236d-c05b-3aac-8cab-8eb139242db9&version=1.6.9&pagesize=10&pageindex=1&platform=Le123Plat0021&plattype=aphone");
|
JSONArray array =JSONObject.fromObject(result).optJSONArray("data");
|
if (array != null && array.size() > 0) {
|
for (int i = 0; i < array.size(); i++) {
|
JSONObject obj = array.optJSONObject(i);
|
if (obj.optString("name").equalsIgnoreCase(key)) {
|
String aid = obj.optString("aid");
|
return getCloudCode(aid);
|
} else {
|
LogUtil.i("-------key:" + key + "Name:" + obj.optString("name"));
|
}
|
}
|
}
|
} catch (UnsupportedEncodingException e) {
|
e.printStackTrace();
|
}
|
return "";
|
}
|
|
}
|