package com.yeshi.buwan.util.video;
|
|
import com.yeshi.buwan.acFun.AcFunUtil;
|
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.funtv.FunTVUtil;
|
import com.yeshi.buwan.funtv.FunTVUtil2;
|
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.FunTVService;
|
import com.yeshi.buwan.service.imp.juhe.IqiyiService;
|
import com.yeshi.buwan.service.imp.juhe.SoHuService;
|
import com.yeshi.buwan.service.inter.juhe.FunTV2Service;
|
import com.yeshi.buwan.service.inter.juhe.Iqiyi2Service;
|
import com.yeshi.buwan.service.inter.juhe.YouKuService;
|
import com.yeshi.buwan.sohu.SoHuUtil;
|
import com.yeshi.buwan.util.StringUtil;
|
import com.yeshi.buwan.util.log.VideoLogFactory;
|
import com.yeshi.buwan.vo.AcceptData;
|
import com.yeshi.buwan.youku.YouKuUtil;
|
import org.hibernate.HibernateException;
|
import org.hibernate.Session;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
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 {
|
|
private final Logger playLogger = LoggerFactory.getLogger("videoPlay");
|
|
@Resource
|
private IqiyiUtil iqiyiUtil;
|
|
@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 FunTV2Service funTV2Service;
|
|
@Resource
|
private VideoInfoService videoInfoService;
|
|
@Resource
|
private YouKuUtil youKuUtil;
|
|
@Resource
|
private YouKuService youKuService;
|
|
@SuppressWarnings("unchecked")
|
// @Cacheable(value = "homeCache", key = "'getVideoInfo'+'-'+#videoid+'-'+#resourceId+'-'+#cacheMD5")
|
public VideoInfo getVideoInfo(String detailSystemId, final String videoid, final String resourceId, final List<Long> reList,
|
String cacheMD5) {
|
playLogger.info(VideoLogFactory.createVideoDetailLog(detailSystemId, videoid, resourceId));
|
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(), 1, 100));
|
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(), 1, 100));
|
|
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;
|
}
|
});
|
}
|
|
public List<VideoDetailInfo> getVideoDetailList(String videoid, VideoResource vr, int page, int pageSize) {
|
int resourceId = Integer.parseInt(vr.getId());
|
switch (resourceId) {
|
case IqiyiUtil2.RESOURCE_ID:
|
return iqiyi2Service.getVideoDetailList(videoid, page, pageSize);
|
case IqiyiUtil.RESOURCE_ID:
|
return iqiyiService.getVideoDetailList(videoid, page, pageSize);
|
case FunTVUtil2.RESOURCE_ID:
|
return funTV2Service.getVideoDetailList(videoid, page, pageSize);
|
case FunTVUtil.RESOURCE_ID:
|
return funTVService.getVideoDetailList(videoid, page, pageSize);
|
case AcFunUtil.RESOURCE_ID:
|
return videoInfoService.getVideoDetailList(videoid, vr, page, pageSize);
|
case SoHuUtil.RESOURCE_ID:
|
return soHuService.getVideoDetailList(videoid, page, pageSize);
|
case YouKuUtil.RESOURCE_ID:
|
return youKuService.getVideoDetailList(videoid, page, pageSize);
|
default:
|
return null;
|
}
|
}
|
|
public VideoDetailInfo getLatestVideoDetail(String videoid, VideoResource vr) {
|
|
int resourceId = Integer.parseInt(vr.getId());
|
switch (resourceId) {
|
case IqiyiUtil2.RESOURCE_ID:
|
return iqiyi2Service.getLatestVideoDetail(videoid);
|
case IqiyiUtil.RESOURCE_ID:
|
return iqiyiService.getLatestVideoDetail(videoid);
|
case FunTVUtil2.RESOURCE_ID:
|
return funTV2Service.getLatestVideoDetail(videoid);
|
case FunTVUtil.RESOURCE_ID:
|
return funTVService.getLatestVideoDetail(videoid);
|
case SoHuUtil.RESOURCE_ID:
|
return soHuService.getLatestVideoDetail(videoid);
|
case YouKuUtil.RESOURCE_ID:
|
return soHuService.getLatestVideoDetail(videoid);
|
default:
|
return null;
|
}
|
}
|
|
public int getShowType(String videoid, VideoResource vr) {
|
int resourceId = Integer.parseInt(vr.getId());
|
switch (resourceId) {
|
case IqiyiUtil2.RESOURCE_ID:
|
return iqiyi2Service.getShowType(videoid);
|
case IqiyiUtil.RESOURCE_ID:
|
return iqiyiUtil.getShowType(videoid);
|
case FunTVUtil2.RESOURCE_ID:
|
return funTV2Service.getShowType(videoid);
|
case FunTVUtil.RESOURCE_ID:
|
return funTVService.getShowType(videoid);
|
case SoHuUtil.RESOURCE_ID:
|
return soHuUtil.getShowType(videoid);
|
case YouKuUtil.RESOURCE_ID:
|
return soHuUtil.getShowType(videoid);
|
default:
|
return 1;
|
}
|
}
|
|
@Cacheable(value = "homeCache", key = "'getPlayUrl'+'-'+#detailSystemId+'-'+#id+'-'+#type+'-'+#resourceid")
|
public PlayUrl getPlayUrl(AcceptData acceptData, String detailSystemId, String id, String type, int resourceid, String videoid) {
|
playLogger.info(VideoLogFactory.createPlayUrlLog(detailSystemId, id, type, resourceid, videoid));
|
switch (resourceid) {
|
case IqiyiUtil2.RESOURCE_ID:
|
return iqiyi2Service.getPlayUrl(detailSystemId, resourceid, id, videoid);
|
case IqiyiUtil.RESOURCE_ID:
|
return iqiyiUtil.getPlayUrl(detailSystemId, resourceid + "", type, id);
|
case FunTVUtil2.RESOURCE_ID:
|
return funTV2Service.getPlayUrl(acceptData, detailSystemId, resourceid, id, videoid);
|
case FunTVUtil.RESOURCE_ID:
|
return funTVService.getPlayUrl(detailSystemId, id, type, resourceid, videoid);
|
case SoHuUtil.RESOURCE_ID:
|
return soHuUtil.getPlayUrl(detailSystemId, resourceid + "", type, id);
|
case AcFunUtil.RESOURCE_ID:
|
return videoInfoService.getPlayUrl(detailSystemId, id, type, resourceid, videoid);
|
case YouKuUtil.RESOURCE_ID:
|
return youKuUtil.getPlayUrl(detailSystemId, id, type, resourceid, videoid);
|
default:
|
return null;
|
}
|
}
|
|
}
|