package com.yeshi.buwan.job.video;
|
|
import com.xxl.job.core.biz.model.ReturnT;
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
import com.yeshi.buwan.service.inter.juhe.TencentVideoService;
|
import com.yeshi.buwan.util.StringUtil;
|
import com.yeshi.buwan.videos.tencent.TencentVideoApiUtil;
|
import com.yeshi.buwan.videos.tencent.entity.TencentCoverInfo;
|
import com.yeshi.buwan.videos.tencent.factory.TencentCoverInfoFactory;
|
import com.yeshi.buwan.videos.tencent.vo.TencentCoverInfoVO;
|
import net.sf.json.JSONObject;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.stereotype.Component;
|
|
import javax.annotation.Resource;
|
import java.util.List;
|
|
@Component
|
public class TencentVideoUpdate {
|
|
private final static Logger logger = LoggerFactory.getLogger("debug");
|
|
@Resource
|
private TencentVideoService tencentVideoService;
|
|
|
private TencentCoverInfo getCoverDetail(String coverId) throws Exception {
|
TencentCoverInfoVO detail = TencentVideoApiUtil.getCoverInfo(String.format("https://v.qq.com/x/cover/%s.html", coverId));
|
return TencentCoverInfoFactory.create(detail);
|
}
|
|
public void updateCategory(String channel,int startPage,int endPage, Integer areaId) {
|
logger.info("更新分类:"+channel);
|
for (int i = startPage; i <= endPage; i++) {
|
List<TencentCoverInfoVO> coverInfoList = TencentVideoApiUtil.getVideoListByCategory(channel, i, areaId);
|
save(coverInfoList);
|
}
|
}
|
|
private void save(List<TencentCoverInfoVO> coverInfoList) {
|
if (coverInfoList != null)
|
for (TencentCoverInfoVO coverInfo : coverInfoList) {
|
System.out.println(coverInfo.getTitle() + ":" + coverInfo.getCover_id());
|
try {
|
// tencentVideoService.save(TencentCoverInfoFactory.create(coverInfo));
|
tencentVideoService.addToInternetSearch( TencentCoverInfoFactory.create(coverInfo),true);
|
} catch (Exception e) {
|
e.printStackTrace();
|
logger.error("保存出错",e);
|
}
|
}
|
}
|
|
|
/**
|
* 更新最近几天的视频
|
*
|
* @param param
|
* @return
|
* @throws Exception
|
*/
|
@XxlJob("video-update-tencent-updateVideo")
|
public ReturnT<String> updateLatestVideo(String param) throws Exception {
|
String[] types = new String[]{
|
"电视剧", "动漫"
|
};
|
|
if (!StringUtil.isNullOrEmpty(param)) {
|
updateCategory(param,1,1,null);
|
} else {
|
for (String type : types) {
|
updateCategory(type,1,1, null);
|
}
|
}
|
return ReturnT.SUCCESS;
|
}
|
|
|
@XxlJob("video-update-tencent-updateVideo-byweburl")
|
public ReturnT<String> updateLatestVideoByWebUrl(String param) throws Exception {
|
JSONObject json = JSONObject.fromObject(param);
|
int page = json.optInt("page");
|
String url = json.optString("url");
|
// List<TencentCoverInfoVO> list = TencentVideoApiUtil.getVideoList(TencentWebUtil.getApiUrl(url, page));
|
// save(list);
|
return ReturnT.SUCCESS;
|
}
|
|
|
/**
|
* 更新单个视频
|
*
|
* @param param
|
* @return
|
* @throws Exception
|
*/
|
@XxlJob("video-update-tencent-updateSingleVideo")
|
public ReturnT<String> updateSingleVideo(String param) throws Exception {
|
String[] cids = param.split(",");
|
for (String cid : cids) {
|
try {
|
TencentCoverInfo detail = getCoverDetail(cid);
|
tencentVideoService.addToInternetSearch(detail, true);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
return ReturnT.SUCCESS;
|
}
|
}
|