package com.yeshi.buwan.iqiyi.util;
|
|
import com.yeshi.buwan.dao.VideoInfoDao;
|
import com.yeshi.buwan.dao.juhe.iqiyi.IqiyiAlbum2Dao;
|
import com.yeshi.buwan.dao.juhe.iqiyi.VideoIqiyi2Dao;
|
import com.yeshi.buwan.dao.video.AlbumVideoMapDao;
|
import com.yeshi.buwan.domain.*;
|
import com.yeshi.buwan.domain.entity.PlayUrl;
|
import com.yeshi.buwan.domain.video.AlbumVideoMap;
|
import com.yeshi.buwan.iqiyi.IqiYiNewAPI;
|
import com.yeshi.buwan.iqiyi.entity.IqiyiAlbum2;
|
import com.yeshi.buwan.iqiyi.entity.VideoIqiyi2;
|
import com.yeshi.buwan.iqiyi.vo.IqiyiAlbumListResult;
|
import com.yeshi.buwan.service.imp.CategoryVideoService;
|
import com.yeshi.buwan.service.imp.ResourceVideoService;
|
import com.yeshi.buwan.service.imp.VideoInfoService;
|
import com.yeshi.buwan.service.imp.VideoResourceService;
|
import com.yeshi.buwan.util.TimeUtil;
|
import com.yeshi.buwan.util.mq.CMQManager;
|
import com.yeshi.buwan.util.video.VideoConstant;
|
import org.springframework.stereotype.Component;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.annotation.Resource;
|
import java.io.Serializable;
|
import java.util.Calendar;
|
import java.util.Date;
|
import java.util.List;
|
|
@Component
|
public class IqiyiUtil2 {
|
|
|
public final int PLAY_NONE = 0;// ²»Äܲ¥·Å
|
public final int PLAY_HTML = 1;// Ìø×ªÒÆ¶¯¶ËÍøÒ³²¥·Å
|
public final int PLAY_SWF = 2;// ǶÌ×ÍøÒ³²¥·Å
|
|
private final static long RESOURCE_ID = 22L;
|
|
@Resource
|
private IqiyiAlbum2Dao iqiyiAlbum2Dao;
|
|
@Resource
|
private VideoIqiyi2Dao videoIqiyi2Dao;
|
|
@Resource
|
private VideoInfoDao videoInfoDao;
|
|
|
@Resource
|
private ResourceVideoService resourceVideoService;
|
|
@Resource
|
private VideoInfoService videoInfoService;
|
|
@Resource
|
private CategoryVideoService categoryVideoService;
|
|
@Resource
|
private VideoResourceService videoResourceService;
|
|
@Resource
|
private AlbumVideoMapDao albumVideoMapDao;
|
|
private void saveAlbumAndVideo(List<IqiyiAlbum2> list) {
|
if (list == null)
|
return;
|
for (IqiyiAlbum2 album : list) {
|
if (album.getTvQipuIds() != null && album.getTvQipuIds().size() > 0) {
|
int pageSize = 10;
|
int page = album.getTvQipuIds().size() % pageSize == 0 ? album.getTvQipuIds().size() / pageSize : album.getTvQipuIds().size() / pageSize + 1;
|
for (int p = 0; p < page; p++) {
|
int startIndex = p * pageSize;
|
int toIndex = (startIndex + pageSize) > album.getTvQipuIds().size() ? album.getTvQipuIds().size() : (startIndex + pageSize);
|
List<IqiyiAlbum2> detailList = IqiYiNewAPI.getAlbumOrVideoDetail(album.getTvQipuIds().subList(startIndex, toIndex));
|
if (detailList != null)
|
for (IqiyiAlbum2 video : detailList)
|
iqiyiAlbum2Dao.save(video);
|
}
|
}
|
iqiyiAlbum2Dao.save(album);
|
}
|
}
|
|
/**
|
* ͬ²½ËùÓеÄר¼ÓëÊÓÆµ
|
*
|
* @param categoryId
|
* @param isAlbum
|
*/
|
private void syncAlbumAndVideo(int categoryId, boolean isAlbum, Long minId) {
|
IqiyiAlbumListResult result = IqiYiNewAPI.getAllAlbumAndVideoList(categoryId + "", minId, isAlbum, 10);
|
if (result.getAlbum2List() != null)
|
saveAlbumAndVideo(result.getAlbum2List());
|
while (result.getMinId() != null) {
|
result = IqiYiNewAPI.getAllAlbumAndVideoList(categoryId + "", result.getMinId(), isAlbum, 10);
|
if (result.getAlbum2List() != null) {
|
saveAlbumAndVideo(result.getAlbum2List());
|
}
|
|
}
|
}
|
|
//ÀÈ¡ËùÓеĵçÓ°
|
public void syncAllDianYing() {
|
syncAlbumAndVideo(IqiYiNewAPI.TYPE_DIANYING, false, 255675400l);
|
}
|
|
//ÀÈ¡ËùÓеĵçÊÓ¾ç
|
public void syncAllDianShiJu() {
|
syncAlbumAndVideo(IqiYiNewAPI.TYPE_DIANSHIJU, true, 206929801L);
|
}
|
|
//ÀÈ¡ËùÓе͝Âþ
|
public void syncAllDongMan() {
|
syncAlbumAndVideo(IqiYiNewAPI.TYPE_DONGMAN, true, 217289601L);
|
}
|
|
//ÀÈ¡ËùÓеÄ×ÛÒÕ
|
public void syncAllZongYi() {
|
syncAlbumAndVideo(IqiYiNewAPI.TYPE_ZONGYI, true, 246881501L);
|
}
|
|
//¸üÐÂר¼
|
public void updateAlbum(int categoryId, Date startTime, Date endTime) {
|
IqiyiAlbumListResult result = IqiYiNewAPI.getUpdateAlbumList(categoryId + "", startTime, endTime, null, true, 10);
|
if (result.getAlbum2List() != null)
|
saveAlbumAndVideo(result.getAlbum2List());
|
while (result.getMinId() != null) {
|
result = IqiYiNewAPI.getUpdateAlbumList(categoryId + "", startTime, endTime, result.getMinId(), true, 10);
|
if (result.getAlbum2List() != null)
|
saveAlbumAndVideo(result.getAlbum2List());
|
}
|
}
|
|
//¸üÐÂÊÓÆµ
|
public void updateVideo(int categoryId, Date startTime, Date endTime) {
|
IqiyiAlbumListResult result = IqiYiNewAPI.getUpdateVideoList(categoryId + "", startTime, endTime, null, true, 10);
|
if (result.getAlbum2List() != null)
|
saveAlbumAndVideo(result.getAlbum2List());
|
while (result.getMinId() != null) {
|
result = IqiYiNewAPI.getUpdateVideoList(categoryId + "", startTime, endTime, result.getMinId(), true, 10);
|
if (result.getAlbum2List() != null)
|
saveAlbumAndVideo(result.getAlbum2List());
|
}
|
}
|
|
//½«×¨¼Ìí¼Óµ½ÊÓÆµ
|
@Transactional
|
public void addToVideoInfo(IqiyiAlbum2 album) {
|
if (album.getFeatureAlbumId() > 0L && album.getChannelId() != IqiYiNewAPI.TYPE_DIANYING) {
|
return;
|
}
|
|
//Ö»»º´æÓÐЧµÄ
|
if (album.getEffect() == 0)
|
return;
|
|
//Ö»»º´æÕýƬ
|
if (album.getContentType() != 1)
|
return;
|
|
//×ÛÒÕ±ØÐëÒªÓÐÄÚÈÝ
|
if (album.getChannelId() == 6) {
|
if (album.getTvQipuIds().size() == 0)
|
return;
|
}
|
|
VideoInfo newVideoInfo = convertAlbumToVideoInfo(album);
|
VideoIqiyi2 videoIqiyi2 = videoIqiyi2Dao.selectByIqiyiId(album.getId());
|
if (videoIqiyi2 != null) {//ÇþµÀÊÓÆµÒѾ´æÔÚ
|
VideoInfo videoInfo = videoInfoDao.find(VideoInfo.class, videoIqiyi2.getVideoId());
|
if (videoInfo == null)
|
return;
|
|
if (newVideoInfo.getTag().equalsIgnoreCase(videoInfo.getTag()))
|
return;
|
newVideoInfo.setId(videoInfo.getId());
|
newVideoInfo.setCreatetime(videoInfo.getCreatetime());
|
//¸üÐÂÐÅÏ¢tagÐÅÏ¢
|
videoInfo.setLatestHpicture(newVideoInfo.getLatestHpicture());
|
videoInfo.setLatestVpicture(newVideoInfo.getLatestVpicture());
|
videoInfo.setVideocount(newVideoInfo.getVideocount());
|
videoInfo.setTag(newVideoInfo.getTag());
|
videoInfo.setPicture(newVideoInfo.getPicture());
|
videoInfo.setHpicture(newVideoInfo.getHpicture());
|
videoInfo.setVpicture(newVideoInfo.getVpicture());
|
videoInfo.setShow(newVideoInfo.getShow());
|
videoInfoDao.update(videoInfo);
|
} else {//ÊÓÆµ²»´æÔÚ
|
//ÅжÏ2¸öÊÓÆµÊµÌåÊÇ·ñΪͬһÊÓÆµ
|
VideoInfo oldVideo = videoInfoService.getExistSameVideo(newVideoInfo);
|
if (oldVideo == null) {
|
//Ìí¼ÓÊÓÆµ
|
Serializable id = videoInfoDao.save(newVideoInfo);
|
newVideoInfo.setId(id + "");
|
} else {//ΪͬһÊÓÆµ
|
//¸üÐÂtag
|
newVideoInfo.setId(oldVideo.getId());
|
oldVideo.setLatestHpicture(newVideoInfo.getLatestHpicture());
|
oldVideo.setLatestVpicture(newVideoInfo.getLatestVpicture());
|
oldVideo.setVideocount(newVideoInfo.getVideocount());
|
oldVideo.setTag(newVideoInfo.getTag());
|
oldVideo.setPicture(newVideoInfo.getPicture());
|
oldVideo.setHpicture(newVideoInfo.getHpicture());
|
oldVideo.setVpicture(newVideoInfo.getVpicture());
|
oldVideo.setShow(newVideoInfo.getShow());
|
videoInfoDao.update(oldVideo);
|
}
|
|
//¼ÓÈëר¼ÊÓÆµÓ³Éä
|
AlbumVideoMap map = new AlbumVideoMap();
|
map.setCreateTime(new Date());
|
map.setVideoId(newVideoInfo.getId());
|
map.setRootVideoType(newVideoInfo.getVideoType().getId());
|
map.setVideoCount(newVideoInfo.getVideocount());
|
albumVideoMapDao.save(map);
|
|
//¼ÓÈëÓ³Éä
|
VideoIqiyi2 vi = new VideoIqiyi2();
|
vi.setIqiyiId(album.getId());
|
vi.setVideoId(Long.parseLong(newVideoInfo.getId()));
|
videoIqiyi2Dao.save(vi);
|
|
|
//Ìí¼ÓÊÓÆµÀ´Ô´Ó³Éä
|
resourceVideoService.addVideoResource(newVideoInfo.getId(), RESOURCE_ID + "");
|
//Ìí¼ÓÊÓÆµ·ÖÀàÓ³Éä
|
categoryVideoService.addCategoryVideo(newVideoInfo.getId(), newVideoInfo.getVideoType().getId());
|
|
CMQManager.getInstance().addSolrMsg(newVideoInfo.getId());
|
}
|
|
|
}
|
|
|
//¸üÐÂ×î½üÒ»ÌìµÄµÄר¼ÓëÊÓÆµ
|
public void updateTodayAlbumAndVideo() {
|
long now = System.currentTimeMillis();
|
for (int i = 0; i < 8; i++) {
|
Date endTime = new Date(now - i * 1000 * 60 * 60L * 3);
|
Date startTime = new Date(endTime.getTime() - 1000 * 60 * 60L * 3);
|
|
//¸üеçÓ°
|
updateVideo(IqiYiNewAPI.TYPE_DIANYING, startTime, endTime);
|
//¸üеçÊÓ¾ç
|
updateAlbum(IqiYiNewAPI.TYPE_DIANSHIJU, startTime, endTime);
|
updateVideo(IqiYiNewAPI.TYPE_DIANSHIJU, startTime, endTime);
|
|
//¸üж¯Âþ
|
updateAlbum(IqiYiNewAPI.TYPE_DONGMAN, startTime, endTime);
|
updateVideo(IqiYiNewAPI.TYPE_DONGMAN, startTime, endTime);
|
|
//¸üÐÂ×ÛÒÕ
|
updateAlbum(IqiYiNewAPI.TYPE_ZONGYI, startTime, endTime);
|
updateVideo(IqiYiNewAPI.TYPE_ZONGYI, startTime, endTime);
|
}
|
}
|
|
|
public VideoInfo convertAlbumToVideoInfo(IqiyiAlbum2 album) {
|
Calendar ca = Calendar.getInstance();
|
ca.setTimeInMillis(TimeUtil.convertGernalTime(album.getPeriod(), "yyyyMMdd"));
|
int day = ca.get(Calendar.DAY_OF_MONTH);
|
int month = ca.get(Calendar.MONTH) + 1;
|
int year = ca.get(Calendar.YEAR);
|
|
VideoInfo video = new VideoInfo();
|
video.setVideoType(new VideoType(IqiyiUtil.getType(album.getContentType())));
|
video.setArea(album.getAreas());
|
video.setBaseurl(album.getH5Url());
|
video.setCanSave(false);
|
video.setCommentCount(0);
|
video.setCreatetime(System.currentTimeMillis());
|
video.setDay(day + "");
|
video.setDirector(album.getDirectors());
|
video.setDuration(album.getDuration() + "");
|
video.setFinish("1");
|
video.setIntroduction(album.getDesc());
|
video.setMainActor(album.getMainCharacters());
|
video.setMonth(month + "");
|
video.setName(album.getName());
|
if (album.getLatestVideo() != null)
|
video.setNowNumber(album.getLatestVideo().getOrder() + "");
|
else
|
video.setNowNumber("1");
|
video.setOrderby("0" + "");
|
video.setPicture(album.getImageUrl());
|
|
video.setVpicture(IqiyiUtil.getVPicture(video.getPicture()));
|
video.setHpicture(IqiyiUtil.getHPicture(video.getPicture()));
|
|
if (album.getStatistics() != null)
|
video.setScore(album.getStatistics().getScore() + "");
|
video.setShare("0");
|
video.setShow("1");
|
|
video.setThirdType("1");
|
video.setTotalNumber("0");
|
|
video.setWatchCount(0 + "");
|
video.setYear(year + "");
|
video.setAdmin(new AdminInfo("1"));
|
video.setContentType(album.getContentType());
|
video.setCommentCount(0);
|
|
String tag = getAlbumTag(album);
|
video.setTag(tag);
|
|
if (album.getLatestVideo() != null) {
|
//²éѯ×î½üµÄͼƬ
|
IqiyiAlbum2 album2 = iqiyiAlbum2Dao.get(album.getLatestVideo().getId());
|
if (album2 != null) {
|
video.setLatestHpicture(IqiyiUtil.getHPicture(album2.getImageUrl()));
|
video.setLatestVpicture(IqiyiUtil.getVPicture(album2.getImageUrl()));
|
}
|
}
|
|
if (album.getTvQipuIds() != null && album.getTvQipuIds().size() > 0)
|
video.setVideocount(album.getTvQipuIds().size());
|
else
|
video.setVideocount(1);
|
|
video.setVideoType(getVideoType(album));
|
return video;
|
}
|
|
private static VideoType getVideoType(IqiyiAlbum2 album) {
|
if (album.getChannelId() == IqiYiNewAPI.TYPE_DIANYING) {
|
return new VideoType(VideoConstant.VIDEO_CATEGORY_DIANYING);
|
} else if (album.getChannelId() == IqiYiNewAPI.TYPE_DIANSHIJU) {
|
return new VideoType(VideoConstant.VIDEO_CATEGORY_DIANSHIJU);
|
} else if (album.getChannelId() == IqiYiNewAPI.TYPE_DONGMAN) {
|
return new VideoType(VideoConstant.VIDEO_CATEGORY_DONGMAN);
|
} else if (album.getChannelId() == IqiYiNewAPI.TYPE_ZONGYI) {
|
return new VideoType(VideoConstant.VIDEO_CATEGORY_ZONGYI);
|
}
|
return null;
|
}
|
|
private static String getAlbumTag(IqiyiAlbum2 album) {
|
//µçӰΪÆÀ·Ö
|
//µçÊÓ¾çºÍ¶¯ÂþΪ¸üе½¶àÉÙ¼¯
|
//×ÛÒÕΪ¸üе½¶àÉÙÆÚ
|
|
String tag = "";
|
if (album.getChannelId() == IqiYiNewAPI.TYPE_DIANYING)
|
if (album.getStatistics() != null)
|
tag = "ÆÀ·Ö£º" + album.getStatistics().getScore();
|
else if (album.getChannelId() == IqiYiNewAPI.TYPE_DIANSHIJU || album.getChannelId() == IqiYiNewAPI.TYPE_DONGMAN) {
|
if (album.getLatestVideo() != null) {
|
if (album.getLatestVideo().getOrder() == album.getVideoCount())
|
tag = album.getVideoCount() + "¼¯È«";
|
else
|
tag = "¸üÐÂÖÁ" + album.getLatestVideo().getOrder() + "¼¯";
|
}
|
tag = album.getLatestVideo().getOrder() + "";
|
} else if (album.getChannelId() == IqiYiNewAPI.TYPE_ZONGYI)
|
if (album.getLatestVideo() != null) {
|
tag = "¸üÐÂÖÁ" + album.getLatestVideo().getPeriod() + "ÆÚ";
|
}
|
return tag;
|
}
|
|
|
public static VideoDetailInfo convertAlbumToVideoDetail(IqiyiAlbum2 album) {
|
VideoDetailInfo vi = new VideoDetailInfo();
|
vi.setAdmin(new AdminInfo("1"));
|
vi.setId(album.getId());
|
vi.setIntroduction(album.getDesc());
|
vi.setName(album.getName());
|
if (album.getChannelId() == IqiYiNewAPI.TYPE_DIANYING)
|
vi.setTag(album.getName());
|
else if (album.getChannelId() == IqiYiNewAPI.TYPE_DIANSHIJU || album.getChannelId() == IqiYiNewAPI.TYPE_DONGMAN)
|
vi.setTag(album.getOrder() + "");
|
else if (album.getChannelId() == IqiYiNewAPI.TYPE_ZONGYI)
|
vi.setTag(album.getPeriod());
|
vi.setType("album");
|
return vi;
|
}
|
|
|
public int getShowType(String videoid) {
|
VideoInfo videoInfo = videoInfoDao.find(VideoInfo.class, videoid);
|
if (videoInfo.getVideoType() != null && (videoInfo.getVideoType().getId() == VideoConstant.VIDEO_CATEGORY_DIANSHIJU || videoInfo.getVideoType().getId() == VideoConstant.VIDEO_CATEGORY_DONGMAN))
|
return 1;
|
else
|
return 2;
|
}
|
|
|
public PlayUrl getPlayUrl(String detailSystemId, int resourceId, String id, String videoId) {
|
IqiyiAlbum2 album = iqiyiAlbum2Dao.get(Long.parseLong(id));
|
VideoResource vr = videoResourceService.getResource(resourceId + "");
|
int t = getPlayType(album);
|
PlayUrl pu = new PlayUrl();
|
pu.setParams("");
|
pu.setPlayType(t);
|
pu.setResource(vr);
|
|
if (t == PLAY_NONE) {
|
pu.setUrl("");
|
} else if (t == PLAY_HTML) {
|
pu.setUrl(album.getH5Url());
|
}
|
return pu;
|
}
|
|
public int getPlayType(IqiyiAlbum2 album) {
|
int type = PLAY_NONE;
|
|
if (album.getEffect() == 0)
|
type = PLAY_NONE;
|
|
for (IqiyiAlbum2.PlayControlsBean pc : album.getPlayControls()) {
|
if (pc.getPlatformId() == 15)// ÒÆ¶¯¶Ë
|
{
|
type = PLAY_HTML;
|
}
|
}
|
return type;
|
}
|
|
}
|