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.mogotv.MogoTVApiUtil;
|
import com.yeshi.buwan.mogotv.entity.MogoTVClipInfo;
|
import com.yeshi.buwan.mogotv.entity.MogoTVVideo;
|
import com.yeshi.buwan.service.inter.juhe.MogoTVService;
|
import com.yeshi.buwan.service.inter.juhe.TencentVideoService;
|
import com.yeshi.buwan.tencent.TencentVideoApiUtil;
|
import com.yeshi.buwan.tencent.TencentVideoUtil;
|
import com.yeshi.buwan.tencent.entity.TencentCoverInfo;
|
import com.yeshi.buwan.util.StringUtil;
|
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(TencentVideoUpdate.class);
|
|
@Resource
|
private TencentVideoService tencentVideoService;
|
|
|
private TencentCoverInfo getCoverDetail(String coverId) throws Exception {
|
TencentCoverInfo detail = TencentVideoApiUtil.getCoverInfo(String.format("https://v.qq.com/x/cover/%s.html", coverId));
|
return detail;
|
}
|
|
private void updateCategory(String channel) {
|
int totalPage = 50;
|
for (int i = 0; i < totalPage; i++) {
|
List<TencentCoverInfo> coverInfoList = TencentVideoApiUtil.getVideoListByCategory(channel, i + 1);
|
for (TencentCoverInfo coverInfo : coverInfoList) {
|
System.out.println(coverInfo.getTitle()+":"+coverInfo.getCover_id());
|
try {
|
tencentVideoService.save(coverInfo);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
}
|
|
private String getChannel(String cate) throws Exception {
|
switch (cate) {
|
case "综艺":
|
return "variety";
|
case "电影":
|
return "movie";
|
case "电视剧":
|
return "tv";
|
case "动漫":
|
return "cartoon";
|
}
|
|
throw new Exception("类型不匹配");
|
|
}
|
|
/**
|
* 更新最近几天的视频
|
*
|
* @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(getChannel(param));
|
} else {
|
for (String type : types) {
|
updateCategory(getChannel(type));
|
}
|
}
|
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.save(detail);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
return ReturnT.SUCCESS;
|
}
|
}
|