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.dao.juhe.pptv.PPTVSeriesDao;
|
import com.yeshi.buwan.dao.juhe.pptv.VideoPPTVMapDao;
|
import com.yeshi.buwan.pptv.PPTVApiUtil;
|
import com.yeshi.buwan.pptv.entity.PPTVSeries;
|
import com.yeshi.buwan.service.inter.juhe.PPTVService;
|
import com.yeshi.buwan.service.inter.juhe.YouKuService;
|
import com.yeshi.buwan.util.StringUtil;
|
import com.yeshi.buwan.youku.YouKuApiUtil;
|
import com.yeshi.buwan.youku.entity.YouKuShowDetail;
|
import com.yeshi.buwan.youku.entity.YouKuShowSimple;
|
import com.yeshi.buwan.youku.entity.YouKuVideo;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.stereotype.Component;
|
|
import javax.annotation.Resource;
|
import java.util.List;
|
|
@Component
|
public class YouKuVideoUpdate {
|
|
private final static Logger logger = LoggerFactory.getLogger(YouKuVideoUpdate.class);
|
|
@Resource
|
private YouKuService youKuService;
|
|
|
private YouKuShowDetail getShowDetail(String showId) throws Exception {
|
|
YouKuShowDetail detail = YouKuApiUtil.getShowDetail(showId);
|
int pageSize = 100;
|
YouKuApiUtil.ListResultDTO resultDTO = YouKuApiUtil.getVideoList(showId, 1, pageSize);
|
if (resultDTO == null)
|
throw new Exception("视频列表获取出错");
|
List<YouKuVideo> videoList = resultDTO.getList();
|
if (videoList.size() < resultDTO.getTotal()) {
|
int totalPage = resultDTO.getTotal() % pageSize == 0 ? resultDTO.getTotal() / pageSize : resultDTO.getTotal() / pageSize + 1;
|
for (int i = 1; i < totalPage; i++) {
|
resultDTO = YouKuApiUtil.getVideoList(showId, i + 1, pageSize);
|
if (resultDTO != null)
|
videoList.addAll(resultDTO.getList());
|
}
|
}
|
|
detail.setVideoList(videoList);
|
return detail;
|
}
|
|
private void updateCategory(String categoryName) throws Exception {
|
YouKuApiUtil.ListResultDTO dto = YouKuApiUtil.getShowListByCategory(categoryName, 1, 20);
|
if (dto != null) {
|
int pageSize = 100;
|
int totalPage = dto.getTotal() % pageSize == 0 ? dto.getTotal() / pageSize : dto.getTotal() / pageSize + 1;
|
totalPage = totalPage > 20 ? 20 : totalPage;
|
for (int i = 0; i < totalPage; i++) {
|
dto = YouKuApiUtil.getShowListByCategory(categoryName, i + 1, pageSize);
|
for (YouKuShowSimple simple : (List<YouKuShowSimple>) dto.getList()) {
|
System.out.println(simple.getName() + ":" + simple.getId());
|
try {
|
YouKuShowDetail detail = getShowDetail(simple.getId());
|
youKuService.save(detail);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
}
|
}
|
|
/**
|
* 更新最近几天的视频
|
*
|
* @param param
|
* @return
|
* @throws Exception
|
*/
|
@XxlJob("video-update-youku-updateVideo")
|
public ReturnT<String> updateLatestVideo(String param) throws Exception {
|
|
String[] types = new String[]{
|
"电影", "电视剧", "动漫", "综艺"
|
};
|
if (!StringUtil.isNullOrEmpty(param)) {
|
if (param.length() < 10) {
|
updateCategory(param);
|
} else {
|
String[] ids = param.split(",");
|
for (String id : ids) {
|
YouKuShowDetail detail = getShowDetail(id);
|
youKuService.save(detail);
|
}
|
}
|
} else {
|
for (String type : types) {
|
updateCategory(type);
|
}
|
}
|
return ReturnT.SUCCESS;
|
}
|
|
}
|