package com.yeshi.buwan.util.video;
|
|
import com.yeshi.buwan.videos.acFun.AcFunUtil;
|
import com.yeshi.buwan.dao.VideoInfoDao;
|
import com.yeshi.buwan.domain.*;
|
import com.yeshi.buwan.domain.entity.PlayUrl;
|
import com.yeshi.buwan.videos.funtv.FunTVUtil;
|
import com.yeshi.buwan.videos.funtv.FunTVUtil2;
|
import com.yeshi.buwan.videos.hanmi.HanmiUtil;
|
import com.yeshi.buwan.videos.iqiyi.util.IqiyiUtil;
|
import com.yeshi.buwan.videos.iqiyi.util.IqiyiUtil2;
|
import com.yeshi.buwan.videos.mogotv.MogoTVUtil;
|
import com.yeshi.buwan.service.imp.VideoInfoService;
|
import com.yeshi.buwan.service.imp.VideoResourceService;
|
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.*;
|
import com.yeshi.buwan.service.manager.search.SolrShortVideoDataManager;
|
import com.yeshi.buwan.videos.sohu.SoHuUtil;
|
import com.yeshi.buwan.videos.tencent.TencentVideoUtil;
|
import com.yeshi.buwan.util.StringUtil;
|
import com.yeshi.buwan.util.log.VideoLogFactory;
|
import com.yeshi.buwan.videos.bilibili.BilibiliUtil;
|
import com.yeshi.buwan.vo.AcceptData;
|
import com.yeshi.buwan.videos.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;
|
|
@Resource
|
private MogoTVUtil mogoTVUtil;
|
|
@Resource
|
private MogoTVService mogoTVService;
|
|
@Resource
|
private TencentVideoService tencentVideoService;
|
|
@Resource
|
private TencentVideoUtil tencentVideoUtil;
|
|
@Resource
|
private BilibiliVideoService bilibiliVideoService;
|
|
@Resource
|
private HanmiService hanmiService;
|
|
@Resource
|
private BilibiliUtil bilibiliUtil;
|
|
@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);
|
case MogoTVUtil.RESOURCE_ID:
|
return mogoTVService.getVideoDetailList(videoid, page, pageSize);
|
case TencentVideoUtil.RESOURCE_ID:
|
return tencentVideoService.getVideoDetailList(videoid, page, pageSize);
|
case BilibiliUtil.RESOURCE_ID:
|
return bilibiliVideoService.getVideoDetailList(videoid, page, pageSize);
|
case HanmiUtil.RESOURCE_ID:
|
return hanmiService.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);
|
case MogoTVUtil.RESOURCE_ID:
|
return soHuService.getLatestVideoDetail(videoid);
|
case HanmiUtil.RESOURCE_ID:
|
return hanmiService.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);
|
case HanmiUtil.RESOURCE_ID:
|
return hanmiService.getShowType(videoid);
|
default:
|
return 1;
|
}
|
}
|
|
@Resource
|
private SolrShortVideoDataManager solrShortVideoDataManager;
|
|
@Resource
|
private VideoResourceService videoResourceService;
|
|
|
@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));
|
if (VideoUtil.getVideoFromType(id) == HomeVideo.FROM_TYPE_SHORT) {
|
VideoResource vr = videoResourceService.getResource(resourceid + "");
|
return solrShortVideoDataManager.getPlayUrl(id, vr);
|
}
|
|
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);
|
case MogoTVUtil.RESOURCE_ID:
|
return mogoTVUtil.getPlayUrl(detailSystemId, id, type, resourceid, videoid);
|
case TencentVideoUtil.RESOURCE_ID:
|
return tencentVideoUtil.getPlayUrl(detailSystemId, id, type, resourceid, videoid);
|
case BilibiliUtil.RESOURCE_ID:
|
return bilibiliUtil.getPlayUrl(detailSystemId, id, type, resourceid, videoid);
|
case HanmiUtil.RESOURCE_ID:
|
return hanmiService.getPlayUrl(detailSystemId, resourceid, id, videoid);
|
default:
|
return null;
|
}
|
}
|
|
}
|