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.YouKuService;
|
import com.yeshi.buwan.util.StringUtil;
|
import com.yeshi.buwan.util.video.web.YouKuWebUtil;
|
import com.yeshi.buwan.videos.youku.YouKuApiUtil;
|
import com.yeshi.buwan.videos.youku.entity.YouKuShowDetail;
|
import com.yeshi.buwan.videos.youku.entity.YouKuShowSimple;
|
import com.yeshi.buwan.videos.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 {
|
for(int i=0;i<2;i++){
|
YouKuApiUtil.ListResultDTO dto = YouKuApiUtil.getHotShowListByCategory(categoryName, i+1, 24);
|
for (YouKuShowSimple simple : (List<YouKuShowSimple>) dto.getList()) {
|
System.out.println(simple.getName() + ":" + simple.getId());
|
try {
|
YouKuShowDetail detail = getShowDetail(simple.getId());
|
youKuService.addToInternetSearch(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.addToInternetSearch(detail);
|
}
|
}
|
} else {
|
for (String type : types) {
|
updateCategory(type);
|
}
|
}
|
return ReturnT.SUCCESS;
|
}
|
|
|
//更新专辑列表
|
@XxlJob("video-update-youku-updateVideo-byCategoryUrl")
|
public ReturnT<String> updatebyCategoryUrl(String param) throws Exception {
|
String[] urlList = param.split(",");
|
for (String url : urlList) {
|
List<YouKuWebUtil.YouKuCoverInfo> list = YouKuWebUtil.parseCategoryList(url);
|
if (list != null) {
|
for (YouKuWebUtil.YouKuCoverInfo info : list) {
|
try {
|
YouKuShowDetail detail = getShowDetail(info.getShowId());
|
youKuService.addToInternetSearch(detail);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
}
|
|
}
|
|
}
|
|
|
return ReturnT.SUCCESS;
|
}
|
|
}
|