package com.newvideo.util.video;
|
|
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.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.util.LogUtil;
|
import com.newvideo.util.StringUtil;
|
|
@Entity
|
public class FengXingVideoUtil {
|
|
public static final int TYPE_DIANYING = 1;
|
public static final int TYPE_DIANSHIJU = 2;
|
public static final int TYPE_DONGMAN = 3;
|
// String url = "http://www.iqiyi.com/a_19rrk101r5.html#vfrm=2-4-0-1";
|
|
// 电影
|
public static final String DIANYING_ALL = "http://www.fun.tv/retrieve/c-e794b5e5bdb1.n-e5bdb1e78987.o-mf.p-e5858de8b4b9.pg-1";
|
|
public static final String DIANYING_KEHUAN = "http://www.youku.com/v_olist/c_96_g_%E7%A7%91%E5%B9%BB_a__sg__mt__lg__q__s_1_r_0_u_1_pt_1_av_0_ag_0_sg__pr__h__d_1_p_1.html";
|
public static final String DIANYING_XIJU = "http://www.youku.com/v_olist/c_96_g_%E5%96%9C%E5%89%A7_a__sg__mt__lg__q__s_1_r_0_u_1_pt_1_av_0_ag_0_sg__pr__h__d_1_p_1.html";
|
public static final String DIANYING_AIQING = "http://www.youku.com/v_olist/c_96_g_%E7%88%B1%E6%83%85_a__sg__mt__lg__q__s_1_r_0_u_1_pt_1_av_0_ag_0_sg__pr__h__d_1_p_1.html";
|
public static final String DIANYING_DONGZUO = "http://www.fun.tv/retrieve/c-e794b5e5bdb1.n-e5bdb1e78987.o-mf.pg-1.t-e58aa8e4bd9c";
|
public static final String DIANYING_QIANGZHAN = "http://www.youku.com/v_olist/c_96_g_%E6%88%98%E4%BA%89_a__sg__mt__lg__q__s_1_r_0_u_1_pt_1_av_0_ag_0_sg__pr__h__d_1_p_1.html";
|
public static final String DIANYING_JINGSONG = "http://www.youku.com/v_olist/c_96_g_%E6%83%8A%E6%82%9A_a__sg__mt__lg__q__s_1_r_0_u_1_pt_1_av_0_ag_0_sg__pr__h__d_1_p_1.html";
|
public static final String DIANYING_KONGBU = "http://www.youku.com/v_olist/c_96_g_%E6%81%90%E6%80%96_a__sg__mt__lg__q__s_1_r_0_u_1_pt_1_av_0_ag_0_sg__pr__h__d_1_p_1.html";
|
public static final String DIANYING_XUANYI = "http://www.youku.com/v_olist/c_96_g_%E6%82%AC%E7%96%91_a__sg__mt__lg__q__s_1_r_0_u_1_pt_1_av_0_ag_0_sg__pr__h__d_1_p_1.html";
|
public static final String DIANYING_WUXIA = "http://www.youku.com/v_olist/c_96_g_%E6%AD%A6%E4%BE%A0_a__sg__mt__lg__q__s_1_r_0_u_1_pt_1_av_0_ag_0_sg__pr__h__d_1_p_1.html";
|
public static final String DIANYING_JUQING = "http://www.youku.com/v_olist/c_96_g_%E5%89%A7%E6%83%85_a__sg__mt__lg__q__s_1_r_0_u_1_pt_1_av_0_ag_0_sg__pr__h__d_1_p_1.html";
|
|
// 动漫
|
|
private String getUrlByPage(int page, String type) {
|
|
return type.replace(".pg-1", ".pg-" + page);
|
}
|
|
private VideoType getVideoType(String type) {
|
VideoType videoType = new VideoType();
|
int typeId = 0;
|
if (type.equalsIgnoreCase(DIANYING_AIQING)) {
|
typeId = 43;
|
} else if (type.equalsIgnoreCase(DIANYING_DONGZUO)) {
|
typeId = 44;
|
} else if (type.equalsIgnoreCase(DIANYING_JINGSONG)) {
|
typeId = 47;
|
} else if (type.equalsIgnoreCase(DIANYING_JUQING)) {
|
typeId = 55;
|
} else if (type.equalsIgnoreCase(DIANYING_KEHUAN)) {
|
typeId = 3;
|
} else if (type.equalsIgnoreCase(DIANYING_KONGBU)) {
|
typeId = 48;
|
} else if (type.equalsIgnoreCase(DIANYING_XIJU)) {
|
typeId = 41;
|
} else if (type.equalsIgnoreCase(DIANYING_XUANYI)) {
|
typeId = 49;
|
}
|
videoType.setId(1);
|
return videoType;
|
}
|
|
public List<VideoInfo> getDianYingList(int page, String type) throws IOException {
|
LogUtil.i(getUrlByPage(page, type));
|
Document doc = Jsoup.connect(getUrlByPage(page, type)).get();
|
Element root = doc.getElementsByAttributeValue("class", "mod-wrap-in mod-vd-lay-c6 fix").get(0);
|
Elements elements = root.getElementsByAttributeValueContaining("class", "mod-vd-i");
|
|
List<VideoInfo> videoList = new ArrayList<VideoInfo>();
|
for (int i = elements.size() - 1; i >= 0; i--) {
|
try {
|
AdminInfo admin = new AdminInfo();
|
admin.setId("1");
|
VideoResource vr = new VideoResource("5");
|
|
VideoInfo info = new VideoInfo();
|
info.setCreatetime(System.currentTimeMillis());
|
info.setVideoType(getVideoType(type));
|
info.setAdmin(admin);
|
info.setOrderby("0");
|
info.setWatchCount("0");
|
info.setQulity("高清");
|
info.setShow("1");
|
|
info.setNowNumber("1");
|
info.setFinish("1");
|
|
info.setPicture(elements.get(i).getElementsByAttributeValue("class", "pic").get(0)
|
.getElementsByTag("img").attr("_lazysrc"));
|
|
String mainUrl = "http://www.fun.tv" + elements.get(i).getElementsByAttributeValue("class", "info")
|
.get(0).getElementsByTag("a").get(0).attr("href");
|
info.setBaseurl(mainUrl);
|
String name = elements.get(i).getElementsByAttributeValue("class", "info").get(0).getElementsByTag("a")
|
.get(0).text();
|
info.setName(name);
|
try {
|
info.setScore(elements.get(i).getElementsByAttributeValue("class", "score").get(0).text());
|
} catch (Exception e) {
|
info.setScore("0");
|
}
|
doc = Jsoup.connect(mainUrl).timeout(20000).get();
|
Element baseInfo = doc.getElementsByAttributeValue("class", "datum").get(0);
|
|
// 主演
|
Elements actors = baseInfo.getElementsByTag("p").get(1).getElementsByTag("span");
|
String actor = "";
|
for (Element ac : actors) {
|
actor += ac.text() + " ";
|
}
|
info.setMainActor(actor.replace("/", ""));
|
|
// 电影的类型
|
Elements types = baseInfo.getElementsByTag("p").get(2).getElementsByTag("span");
|
String beizhu = "";
|
for (Element ty : types) {
|
beizhu += ty.text() + " ";
|
}
|
info.setBeizhu(actor.replace("/", ""));
|
try {
|
info.setIntroduction(baseInfo.getElementsByTag("p").get(3).getElementsByTag("span").get(1).text());
|
} catch (Exception e) {
|
info.setIntroduction(baseInfo.getElementsByTag("p").get(3).getElementsByTag("span").get(0).text());
|
}
|
info.setYear("2014");
|
|
VideoDetailInfo detail = new VideoDetailInfo();
|
detail.setAdmin(admin);
|
detail.setBeizhu("系统添加");
|
detail.setCreatetime(System.currentTimeMillis() + "");
|
detail.setName(info.getName());
|
|
VideoUrl videoUrl = new VideoUrl();
|
videoUrl.setAdmin(admin);
|
videoUrl.setCreatetime(System.currentTimeMillis() + "");
|
videoUrl.setResource(vr);
|
videoUrl.setUrl(mainUrl);
|
List<VideoUrl> urlList = new ArrayList<VideoUrl>();
|
urlList.add(videoUrl);
|
detail.setUrls(urlList);
|
List<VideoDetailInfo> detailList = new ArrayList<VideoDetailInfo>();
|
detailList.add(detail);
|
|
info.setVideoDetailList(detailList);
|
videoList.add(info);
|
LogUtil.i("视频解析完毕:" + info.getName());
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
return videoList;
|
}
|
|
private String getNumberFromString(String str) {
|
|
str = str.trim();
|
String str2 = "";
|
if (str != null && !"".equals(str)) {
|
for (int i = 0; i < str.length(); i++) {
|
if (str.charAt(i) >= 48 && str.charAt(i) <= 57) {
|
str2 += str.charAt(i);
|
}
|
}
|
}
|
if (StringUtil.isNullOrEmpty(str2))
|
return "0";
|
else
|
return str2;
|
}
|
|
/**
|
* 爱奇艺电视剧
|
*
|
* @param info
|
* @param url
|
* @return
|
*/
|
public VideoInfo getDianShiJuDetail(VideoInfo info, String url) {
|
try {
|
info.setBaseurl(url);
|
Document doc = Jsoup.connect(url).get();
|
Elements fenshus = doc.getElementsByAttributeValue("class", "fenshu-r");
|
if (fenshus == null || fenshus.size() == 0) {
|
fenshus = doc.getElementsByAttributeValue("class", "sub-font");
|
}
|
|
if (fenshus.size() > 0) {
|
LogUtil.i("分数:" + fenshus.get(0).text());
|
info.setScore(fenshus.get(0).text());
|
} else {
|
LogUtil.i("分数:9.0");
|
info.setScore("9.0");
|
}
|
// fenshu-r-分数
|
|
Elements actors = doc.getElementsByAttributeValue("class", "li-large");
|
Elements actorList = null;
|
if (actors == null || actors.size() == 0) {
|
actors = doc.getElementsByAttributeValue("class", "role-album");
|
if (actors != null)
|
actorList = actors.get(0).getElementsByTag("a");
|
} else {
|
actorList = actors.get(1).getElementsByTag("a");
|
}
|
String actor = "";
|
for (Element es : actorList)
|
actor += es.text() + " ";
|
LogUtil.i("主演:" + actor);
|
info.setMainActor(actor);
|
// bigPic-b-jtxt--简介
|
Elements inList = doc.getElementsByAttributeValue("class", "bigPic-b-jtxt");
|
Element introduction;
|
if (inList == null || inList.size() == 0) {
|
introduction = doc.getElementsByAttributeValue("data-moreorless", "moreinfo").get(0);
|
} else {
|
introduction = inList.get(0);
|
}
|
// data-moreorless
|
info.setIntroduction(introduction.text());
|
LogUtil.i("简介:" + introduction.text());
|
// wrapper-piclist --分级
|
Element ul = doc.getElementsByAttributeValue("class", "wrapper-piclist").get(0);
|
Elements lis = ul.getElementsByTag("li");
|
|
List<VideoDetailInfo> detailList = new ArrayList<VideoDetailInfo>();
|
int i = 1;
|
for (Element elt : lis) {
|
AdminInfo admin = new AdminInfo();
|
admin.setId("1");
|
VideoDetailInfo detail = new VideoDetailInfo();
|
Element urlElement = elt.getElementsByTag("div").get(0).getElementsByTag("a").get(0);
|
detail.setAdmin(admin);
|
detail.setBeizhu("系统添加");
|
detail.setIntroduction(urlElement.attr("title"));
|
detail.setName(info.getName());
|
detail.setTag("" + (i++));
|
detail.setCreatetime(System.currentTimeMillis() + "");
|
VideoResource vr = new VideoResource();
|
vr.setId("8");// 爱奇艺
|
List<VideoUrl> urlList = new ArrayList<VideoUrl>();
|
VideoUrl detailUrl = new VideoUrl();
|
detailUrl.setAdmin(admin);
|
detailUrl.setCreatetime(System.currentTimeMillis() + "");
|
detailUrl.setBeizhu("系统添加");
|
detailUrl.setUrl(urlElement.attr("href"));
|
detailUrl.setResource(vr);
|
urlList.add(detailUrl);
|
detail.setUrls(urlList);
|
LogUtil.i("单集链接:" + urlElement.attr("href"));
|
LogUtil.i("单集的简介:" + urlElement.attr("title"));
|
|
detailList.add(detail);
|
}
|
info.setVideoDetailList(detailList);
|
return info;
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return null;
|
}
|
|
//
|
|
/**
|
* 爱奇艺电影
|
*
|
* @param info
|
* @param url
|
* @return
|
*/
|
public VideoInfo getDianYingDetail(VideoInfo info, String url) {
|
try {
|
info.setBaseurl(url);
|
Document doc = Jsoup.connect(url).get();
|
Elements fenshus = doc.getElementsByAttributeValue("class", "fenshu-r");
|
if (fenshus == null || fenshus.size() == 0) {
|
fenshus = doc.getElementsByAttributeValue("class", "sub-font");
|
}
|
|
info.setScore("9.0");
|
|
// fenshu-r-分数
|
|
Element actors = doc.getElementById("datainfo-actor-list");
|
Elements actorList = actors.getElementsByTag("a");
|
|
if (actorList != null && actorList.size() != 0) {
|
String actor = "";
|
for (Element es : actorList)
|
actor += es.text() + " ";
|
LogUtil.i("主演:" + actor);
|
info.setMainActor(actor);
|
}
|
// 简介
|
Element introduction = doc.getElementById("datainfo-desc-text");
|
if (introduction != null) {
|
info.setIntroduction(introduction.attr("data-desc-origin"));
|
LogUtil.i("简介:" + introduction.attr("data-desc-origin"));
|
}
|
|
List<VideoDetailInfo> detailList = new ArrayList<VideoDetailInfo>();
|
|
AdminInfo admin = new AdminInfo();
|
admin.setId("1");
|
VideoDetailInfo detail = new VideoDetailInfo();
|
|
detail.setAdmin(admin);
|
detail.setBeizhu("系统添加");
|
detail.setName(info.getName());
|
detail.setTag("1");
|
|
VideoResource vr = new VideoResource();
|
vr.setId("8");// 爱奇艺
|
List<VideoUrl> urlList = new ArrayList<VideoUrl>();
|
VideoUrl detailUrl = new VideoUrl();
|
detailUrl.setAdmin(admin);
|
detailUrl.setCreatetime(System.currentTimeMillis() + "");
|
detailUrl.setBeizhu("系统添加");
|
detailUrl.setUrl(url);
|
detailUrl.setResource(vr);
|
urlList.add(detailUrl);
|
detail.setUrls(urlList);
|
|
detailList.add(detail);
|
|
info.setVideoDetailList(detailList);
|
return info;
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return null;
|
}
|
|
/**
|
* 爱奇艺动漫
|
*
|
* @param info
|
* @param url
|
* @return
|
*/
|
public VideoInfo getDongManDetail(VideoInfo info, String url) {
|
try {
|
info.setBaseurl(url);
|
Document doc = Jsoup.connect(url).get();
|
Elements fenshus = doc.getElementsByAttributeValue("class", "fenshu-r");
|
if (fenshus == null || fenshus.size() == 0) {
|
fenshus = doc.getElementsByAttributeValue("class", "sub-font");
|
}
|
|
if (fenshus.size() > 0) {
|
LogUtil.i("分数:" + fenshus.get(0).text());
|
info.setScore(fenshus.get(0).text());
|
} else {
|
LogUtil.i("分数:9.0");
|
info.setScore("9.0");
|
}
|
// fenshu-r-分数
|
// bigPic-b-jtxt--简介
|
Elements inList = doc.getElementsByAttributeValue("class", "bigPic-b-jtxt");
|
Element introduction;
|
try {
|
if (inList == null || inList.size() == 0) {
|
introduction = doc.getElementsByAttributeValue("data-moreorless", "moreinfo").get(0);
|
} else {
|
introduction = inList.get(0);
|
}
|
// data-moreorless
|
info.setIntroduction(introduction.text());
|
LogUtil.i("简介:" + introduction.text());
|
} catch (Exception e) {
|
LogUtil.i("没有简介");
|
}
|
|
// wrapper-piclist --分级
|
Element ul = doc.getElementsByAttributeValue("class", "wrapper-piclist").get(0);
|
Elements lis = ul.getElementsByTag("li");
|
|
AdminInfo admin = new AdminInfo();
|
admin.setId("1");
|
|
List<VideoDetailInfo> detailList = new ArrayList<VideoDetailInfo>();
|
int i = 1;
|
for (Element elt : lis) {
|
|
VideoDetailInfo detail = new VideoDetailInfo();
|
Element urlElement = elt.getElementsByTag("div").get(0).getElementsByTag("a").get(0);
|
detail.setAdmin(admin);
|
detail.setBeizhu("系统添加");
|
detail.setIntroduction(urlElement.attr("title"));
|
detail.setName(info.getName());
|
detail.setTag("" + (i++));
|
|
VideoResource vr = new VideoResource();
|
vr.setId("8");// 爱奇艺
|
List<VideoUrl> urlList = new ArrayList<VideoUrl>();
|
VideoUrl detailUrl = new VideoUrl();
|
detailUrl.setAdmin(admin);
|
detailUrl.setCreatetime(System.currentTimeMillis() + "");
|
detailUrl.setBeizhu("系统添加");
|
detailUrl.setUrl(urlElement.attr("href"));
|
detailUrl.setResource(vr);
|
urlList.add(detailUrl);
|
detail.setUrls(urlList);
|
LogUtil.i("单集链接:" + urlElement.attr("href"));
|
LogUtil.i("单集的简介:" + urlElement.attr("title"));
|
|
detailList.add(detail);
|
}
|
info.setVideoDetailList(detailList);
|
return info;
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return null;
|
}
|
|
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 "";
|
}
|
}
|