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 "";
|
}
|
}
|