package com.yeshi.buwan.job.video;
|
|
import com.google.gson.Gson;
|
import com.xxl.job.core.biz.model.ReturnT;
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
import com.yeshi.buwan.videos.iqiyi.IqiYiNewAPI;
|
import com.yeshi.buwan.videos.iqiyi.entity.IqiyiAlbum2;
|
import com.yeshi.buwan.service.manager.search.SolrShortVideoDataManager;
|
import com.yeshi.buwan.util.StringUtil;
|
import com.yeshi.buwan.util.factory.SolrShortVideoFactory;
|
import com.yeshi.buwan.util.video.web.IqiyiWebUtil;
|
import com.yeshi.buwan.util.video.web.TencentWebUtil;
|
import org.springframework.stereotype.Component;
|
|
import javax.annotation.Resource;
|
import java.util.Collections;
|
import java.util.List;
|
|
/**
|
* 短视频更新
|
*/
|
@Component
|
public class ShortVideoUpdateJob {
|
|
@Resource
|
private SolrShortVideoDataManager solrShortVideoDataManager;
|
|
private class URLParams {
|
|
private Integer videoType;
|
private String url;
|
private String area;
|
|
public Integer getVideoType() {
|
return videoType;
|
}
|
|
public void setVideoType(Integer videoType) {
|
this.videoType = videoType;
|
}
|
|
public String getUrl() {
|
return url;
|
}
|
|
public void setUrl(String url) {
|
this.url = url;
|
}
|
|
public String getArea() {
|
return area;
|
}
|
|
public void setArea(String area) {
|
this.area = area;
|
}
|
}
|
|
/**
|
* 同
|
*
|
* @param param
|
* @return
|
* @throws Exception
|
*/
|
|
private URLParams getParams(String param) throws Exception {
|
if (StringUtil.isNullOrEmpty(param)) {
|
throw new Exception("参数不能为空");
|
}
|
URLParams urlParams = new Gson().fromJson(param, URLParams.class);
|
if (urlParams.getVideoType() == null) {
|
throw new Exception("videoType不能为空");
|
}
|
if (StringUtil.isNullOrEmpty(urlParams.getUrl())) {
|
throw new Exception("url不能为空");
|
}
|
return urlParams;
|
}
|
|
/**
|
* 更新爱奇艺视频
|
*
|
* @param param
|
* @return
|
* @throws Exception
|
*/
|
@XxlJob("video-update-shortvideo-iqiyi")
|
public ReturnT<String> updateIqiyiShortVideo(String param) throws Exception {
|
URLParams urlParams = getParams(param);
|
|
for (int i = 19; i >= 0; i--) {
|
try {
|
List<Long> idList = IqiyiWebUtil.getVideoTvidList(IqiyiWebUtil.parseParams(urlParams.getUrl()), i + 1);
|
if (idList.size() == 0) {
|
continue;
|
}
|
Collections.reverse(idList);
|
//保存
|
for (Long id : idList) {
|
IqiyiAlbum2 album = IqiYiNewAPI.getAlbumOrVideoDetail(id);
|
if (album != null)
|
solrShortVideoDataManager.saveOrUpdate(SolrShortVideoFactory.create(album, urlParams.getVideoType()));
|
}
|
|
} catch (Exception e) {
|
}
|
}
|
|
return ReturnT.SUCCESS;
|
}
|
|
/**
|
* 更新腾讯视频
|
*
|
* @param param
|
* @return
|
* @throws Exception
|
*/
|
@XxlJob("video-update-shortvideo-tencent")
|
public ReturnT<String> updateTencentShortVideo(String param) throws Exception {
|
URLParams urlParams = getParams(param);
|
if (StringUtil.isNullOrEmpty(urlParams.getArea())) {
|
throw new Exception("area不能为空");
|
}
|
|
for (int i = 19; i >= 0; i--) {
|
try {
|
List<TencentWebUtil.TencentWebVideoInfo> list = TencentWebUtil.getVideoList(TencentWebUtil.parseParams(urlParams.getUrl()), i + 1);
|
if (list.size() == 0)
|
continue;
|
Collections.reverse(list);
|
for (TencentWebUtil.TencentWebVideoInfo videoInfo : list) {
|
solrShortVideoDataManager.saveOrUpdate(SolrShortVideoFactory.create(videoInfo, urlParams.getArea(), urlParams.getVideoType()));
|
}
|
} catch (Exception e) {
|
|
}
|
}
|
return ReturnT.SUCCESS;
|
}
|
}
|