package com.yeshi.buwan.util.video;
|
|
import com.yeshi.buwan.dao.VideoInfoDao;
|
import com.yeshi.buwan.domain.ResourceVideo;
|
import com.yeshi.buwan.domain.VideoDetailInfo;
|
import com.yeshi.buwan.domain.VideoInfo;
|
import com.yeshi.buwan.domain.VideoResource;
|
import com.yeshi.buwan.domain.entity.PlayUrl;
|
import com.yeshi.buwan.iqiyi.util.IqiyiUtil;
|
import com.yeshi.buwan.iqiyi.util.IqiyiUtil2;
|
import com.yeshi.buwan.service.imp.VideoInfoService;
|
import com.yeshi.buwan.service.imp.juhe.*;
|
import com.yeshi.buwan.sohu.SoHuUtil;
|
import com.yeshi.buwan.util.StringUtil;
|
import org.hibernate.HibernateException;
|
import org.hibernate.Session;
|
import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.orm.hibernate4.HibernateCallback;
|
import org.springframework.stereotype.Component;
|
|
import javax.annotation.Resource;
|
import java.util.List;
|
|
@Component
|
public class VideoDetailUtil {
|
@Resource
|
private IqiyiUtil iqiyiUtil;
|
|
@Resource
|
private IqiyiUtil2 iqiyiUtil2;
|
|
@Resource
|
private SoHuUtil soHuUtil;
|
|
@Resource
|
private IqiyiService iqiyiService;
|
|
@Resource
|
private Iqiyi2Service iqiyi2Service;
|
|
@Resource
|
private SoHuService soHuService;
|
|
@Resource
|
private VideoInfoDao videoInfoDao;
|
|
@Resource
|
private FunTVService funTVService;
|
|
@Resource
|
private PPTVService pptvService;
|
|
@Resource
|
private VideoInfoService videoInfoService;
|
|
@SuppressWarnings("unchecked")
|
// @Cacheable(value = "homeCache", key = "'getVideoInfo'+'-'+#videoid+'-'+#resourceId+'-'+#cacheMD5")
|
public VideoInfo getVideoInfo(final String videoid, final String resourceId, final List<Long> reList,
|
String cacheMD5) {
|
|
return (VideoInfo) videoInfoDao.excute(new HibernateCallback<VideoInfo>() {
|
public VideoInfo doInHibernate(Session session) throws HibernateException {
|
|
VideoInfo video = null;
|
VideoResource resource = null;
|
try {
|
if (!StringUtil.isNullOrEmpty(resourceId)) {
|
|
// À´Ô´ÏÞÖÆÅжÏ
|
boolean isCan = false;
|
for (long re : reList)
|
if (resourceId.equalsIgnoreCase(re + "")) {
|
isCan = true;
|
}
|
if (!isCan)
|
return null;
|
|
List<ResourceVideo> list = session
|
.createQuery("FROM ResourceVideo rv where rv.video.id=? and rv.resource.id=?")
|
.setParameter(0, videoid).setParameter(1, resourceId).list();
|
if (list != null && list.size() > 0) {
|
ResourceVideo rv = list.get(0);
|
List<VideoResource> resourceList = session
|
.createQuery("select rv.resource from ResourceVideo rv where rv.video.id=?")
|
.setParameter(0, videoid).list();
|
|
rv.getVideo().setVideoDetailList(getVideoDetailList(videoid, rv.getResource()));
|
for (VideoResource r : resourceList) {
|
if (r.getId().equalsIgnoreCase(rv.getResource().getId())) {
|
r.setChecked(true);
|
}
|
}
|
rv.getVideo().setResourceList(resourceList);
|
video = rv.getVideo();
|
|
resource = rv.getResource();
|
}
|
} else {
|
List<ResourceVideo> list = session
|
.createQuery(
|
"FROM ResourceVideo rv where rv.video.id=? order by rv.resource.orderby desc")
|
.setParameter(0, videoid).list();
|
// À´Ô´É¸²é
|
|
if (list != null)
|
for (int i = 0; i < list.size(); i++) {
|
boolean isC = false;
|
for (Long id : reList) {
|
if ((id + "").equalsIgnoreCase(list.get(i).getResource().getId())) {
|
isC = true;
|
break;
|
}
|
}
|
if (!isC) {
|
list.remove(i);
|
i--;
|
}
|
}
|
|
if (list != null && list.size() > 0) {
|
ResourceVideo rv = list.get(0);
|
List<VideoResource> resourceList = session
|
.createQuery(
|
"select rv.resource from ResourceVideo rv where rv.video.id=? order by rv.resource.id desc")
|
.setParameter(0, videoid).list();
|
|
rv.getVideo().setVideoDetailList(getVideoDetailList(videoid, rv.getResource()));
|
|
for (int i = 0; i < resourceList.size(); i++) {
|
VideoResource r = resourceList.get(i);
|
if (r.getId().equalsIgnoreCase(rv.getResource().getId())) {
|
r.setChecked(true);
|
}
|
boolean isS = false;
|
for (Long id : reList) {
|
if ((id + "").equalsIgnoreCase(r.getId())) {
|
isS = true;
|
break;
|
}
|
}
|
// ²»ÔÚÔÊÐíµÄresourceÀïÃæ
|
if (!isS) {
|
resourceList.remove(i);
|
i--;
|
}
|
|
}
|
rv.getVideo().setResourceList(resourceList);
|
video = rv.getVideo();
|
resource = rv.getResource();
|
}
|
}
|
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
try {
|
if (video.getVideoDetailList() != null && video.getVideoDetailList().size() == 1) {
|
video.getVideoDetailList().get(0).setName(video.getName());
|
video.getVideoDetailList().get(0).setTag(video.getName());
|
}
|
|
if (video != null && resource != null) {
|
video.setShowType(getShowType(video.getId(), resource));
|
}
|
} catch (Exception e) {
|
|
}
|
return video;
|
}
|
});
|
}
|
|
private List<VideoDetailInfo> getVideoDetailList(String videoid, VideoResource vr) {
|
if (vr.getName().contains("°®ÆæÒÕ2")) {
|
return iqiyi2Service.getVideoDetailList(videoid);
|
} else if (vr.getName().contains("°®ÆæÒÕ")) {
|
return iqiyiService.getVideoDetailList(videoid);
|
} else if (vr.getName().contains("ËѺü")) {
|
return soHuService.getVideoDetailList(videoid);
|
} else if (vr.getName().contains("PPTV"))
|
return pptvService.getVideoDetailList(videoid);
|
else if (vr.getName().contains("·çÐÐ"))
|
return funTVService.getVideoDetailList(videoid);
|
else if (vr.getName().contains("AcFun")) {
|
return videoInfoService.getVideoDetailList(videoid, vr);
|
}
|
return null;
|
}
|
|
public VideoDetailInfo getLatestVideoDetail(String videoid, VideoResource vr) {
|
if (vr.getName().contains("°®ÆæÒÕ2")) {
|
return iqiyi2Service.getLatestVideoDetail(videoid);
|
} else if (vr.getName().contains("°®ÆæÒÕ")) {
|
return iqiyiService.getLatestVideoDetail(videoid);
|
} else if (vr.getName().contains("ËѺü")) {
|
return soHuService.getLatestVideoDetail(videoid);
|
} else if (vr.getName().contains("PPTV"))
|
return pptvService.getLatestVideoDetail(videoid);
|
else if (vr.getName().contains("·çÐÐ"))
|
return funTVService.getLatestVideoDetail(videoid);
|
return null;
|
}
|
|
public int getShowType(String videoid, VideoResource vr) {
|
if (vr.getName().contains("°®ÆæÒÕ2")) {
|
return iqiyiUtil2.getShowType(videoid);
|
} else if (vr.getName().contains("°®ÆæÒÕ")) {
|
return iqiyiUtil.getShowType(videoid);
|
} else if (vr.getName().contains("ËѺü")) {
|
return soHuUtil.getShowType(videoid);
|
} else if (vr.getName().contains("PPTV")) {
|
return pptvService.getShowType(videoid);
|
} else if (vr.getName().contains("·çÐÐ")) {
|
return funTVService.getShowType(videoid);
|
}
|
return 1;
|
}
|
|
@Cacheable(value = "homeCache", key = "'getPlayUrl'+'-'+#detailSystemId+'-'+#id+'-'+#type+'-'+#resourceid")
|
public PlayUrl getPlayUrl(String detailSystemId, String id, String type, int resourceid, String videoid) {
|
if (resourceid == 13) {// °®ÆæÒÕ
|
return iqiyiUtil.getPlayUrl(detailSystemId, resourceid + "", type, id);
|
} else if (resourceid == 14) {// ËѺü
|
return soHuUtil.getPlayUrl(detailSystemId, resourceid + "", type, id);
|
} else if (resourceid == 16)// PPTV
|
return pptvService.getPlayUrl(detailSystemId, id, type, resourceid, videoid);
|
else if (resourceid == 19)// ·çÐÐ
|
return funTVService.getPlayUrl(detailSystemId, id, type, resourceid, videoid);
|
else if (resourceid == 21)//acfun
|
return videoInfoService.getPlayUrl(detailSystemId, id, type, resourceid, videoid);
|
else if (resourceid == 22)//°®ÆæÒÕ2
|
return iqiyiUtil2.getPlayUrl(detailSystemId, resourceid, id, videoid);
|
return null;
|
}
|
}
|