package com.yeshi.buwan.videos.acFun;
|
|
import java.util.ArrayList;
|
import java.util.Calendar;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Scanner;
|
|
import javax.annotation.Resource;
|
|
import org.springframework.stereotype.Component;
|
|
import com.google.gson.reflect.TypeToken;
|
import com.yeshi.buwan.domain.VideoInfo;
|
import com.yeshi.buwan.domain.VideoResource;
|
import com.yeshi.buwan.domain.VideoType;
|
import com.yeshi.buwan.service.imp.AcTypeEqVideoTypeService;
|
import com.yeshi.buwan.service.imp.VideoInfoService;
|
import com.yeshi.buwan.service.imp.juhe.AcfunVideoNewService;
|
import com.yeshi.buwan.util.StringUtil;
|
|
@Component
|
public class AcFunUtil {
|
|
public final static int RESOURCE_ID = 21;
|
public final static String RESOURCE_NAME = "AcFun";
|
|
@Resource
|
private AcTypeEqVideoTypeService acTypeEqVideoTypeService;
|
|
@Resource
|
private VideoInfoService videoInfoService;
|
|
@Resource
|
private AcfunVideoNewService acfunVideoNewService;
|
|
/**
|
* acFun添加视频
|
*/
|
public void addVideo(AcfunVideoNew acfunVideo) {
|
if (acfunVideoNewService.isAddToVideo(acfunVideo.getId()))
|
return;
|
try {
|
VideoInfo videoInfo = convert(acfunVideo);
|
saveVideoInfo(videoInfo, acfunVideo.getId());
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
public void saveVideoInfo(VideoInfo videoInfo, String id) {
|
if (videoInfo == null)
|
return;
|
VideoInfo vi = videoInfoService.getVideoInfo(videoInfo.getName(), videoInfo.getVideoType());
|
if (vi == null) {
|
List<VideoResource> resourList = new ArrayList<VideoResource>();
|
resourList.add(new VideoResource("21"));
|
videoInfo.setResourceList(resourList);
|
videoInfoService.saveWithCategoryAndResource(videoInfo);
|
acfunVideoNewService.addAcfunVideoMap(id, Long.parseLong(videoInfo.getId()));
|
}
|
}
|
|
private VideoInfo convert(AcfunVideoNew acFunVideo) {
|
VideoInfo vi = new VideoInfo();
|
String playUrl = acFunVideo.getPlayUrl();
|
Long updateTime = acFunVideo.getUpdateTime();
|
String videoDesc = acFunVideo.getDesc();
|
Integer videoNum = 1;
|
String videoTitle = acFunVideo.getTitle();
|
String thumbImg = acFunVideo.getCover();
|
Map<Integer, Long> typeMap = getAcfunVideoTypeMap();
|
Long type = typeMap.get(acFunVideo.getChannelIds().get(0));
|
if (type == null) {
|
return null;
|
}
|
|
VideoType vt = new VideoType(type);
|
|
int acfunType = acFunVideo.getChannelIds().get(0);
|
|
// acfun地域添加
|
if (acfunType == 195) {
|
vi.setArea("日本");
|
} else if (acfunType == 120) {
|
vi.setArea("内地");
|
} else if (acfunType == 67 || acfunType == 180) {
|
vi.setArea("日本");
|
}
|
|
vi.setName(videoTitle);
|
vi.setPicture(thumbImg);
|
vi.setUpdatetime(updateTime + "");
|
vi.setVideoType(vt);
|
vi.setIntroduction(videoDesc);
|
vi.setBaseurl(playUrl);
|
vi.setShow(1 + "");
|
vi.setHpicture(thumbImg);
|
vi.setVpicture(thumbImg);
|
vi.setLatestHpicture(thumbImg);
|
vi.setLatestVpicture(thumbImg);
|
vi.setCreatetime(System.currentTimeMillis());
|
vi.setVideocount(1);
|
vi.setContentType(2);
|
vi.setTag("");
|
vi.setWatchCount(0 + "");
|
vi.setOrderby(1 + "");
|
Calendar instance = Calendar.getInstance();
|
instance.setTimeInMillis(updateTime);
|
vi.setYear(instance.get(Calendar.YEAR) + "");
|
vi.setDirector("");
|
return vi;
|
}
|
|
static Map<Integer, Long> typeMap = null;
|
|
public static Map<Integer, Long> getAcfunVideoTypeMap() {
|
if (typeMap != null)
|
return typeMap;
|
typeMap = new HashMap<>();
|
Scanner scanner = new Scanner(AcFunUtil.class.getClassLoader().getResourceAsStream("acfun_class_map.txt"));
|
while (scanner.hasNextLine()) {
|
String content = scanner.nextLine();
|
if (content != null && content.indexOf("[") > -1 && content.indexOf("]") > -1) {
|
Long videoType = Long.parseLong(content.substring(0, content.indexOf("[")).trim());
|
String acfunTypeStr = content.substring(content.indexOf("[") + 1, content.indexOf("]"));
|
String[] sts = acfunTypeStr.split(" ");
|
for (String st : sts) {
|
if (!StringUtil.isNullOrEmpty(st)) {
|
int acfunType = Integer.parseInt(st.trim());
|
typeMap.put(acfunType, videoType);
|
}
|
}
|
}
|
}
|
scanner.close();
|
return typeMap;
|
}
|
}
|
|
class MyType extends TypeToken<List<AcFunVideo>> {
|
|
}
|