package com.hxh.spring.test.video;
|
|
import com.google.gson.Gson;
|
import com.yeshi.buwan.dao.video.AlbumVideoMapDao;
|
import com.yeshi.buwan.domain.VideoInfo;
|
import com.yeshi.buwan.domain.video.AlbumVideoMap;
|
import com.yeshi.buwan.domain.video.InternetSearchVideo;
|
import com.yeshi.buwan.service.imp.VideoInfoService;
|
import com.yeshi.buwan.service.inter.juhe.InternetSearchVideoService;
|
import com.yeshi.buwan.util.DouBanUtil;
|
import com.yeshi.buwan.util.FileUtil;
|
import com.yeshi.buwan.util.factory.VideoInfoFactory;
|
import org.junit.Test;
|
|
import javax.annotation.Resource;
|
import java.io.File;
|
import java.io.FileInputStream;
|
import java.io.IOException;
|
import java.util.ArrayList;
|
import java.util.Collections;
|
import java.util.List;
|
import java.util.Scanner;
|
|
/**
|
* @author hxh
|
* @title: DouBanTest
|
* @description: TODO
|
* @date 2022/3/16 14:59
|
*/
|
//@RunWith(SpringJUnit4ClassRunner.class)
|
//@ContextConfiguration(locations = {"classpath:spring.xml"})
|
//@WebAppConfiguration
|
public class DouBanTest {
|
|
@Resource
|
private AlbumVideoMapDao albumVideoMapDao;
|
@Resource
|
private VideoInfoService videoInfoService;
|
@Resource
|
private InternetSearchVideoService internetSearchVideoService;
|
|
|
@Test
|
public void saveSearchResult() throws Exception {
|
//读取视频名称
|
Scanner scanner = new Scanner(new FileInputStream(new File("F:\\影视信息\\片名.txt")));
|
int sleepTime = 1;
|
List<String> nameList = new ArrayList<>();
|
while (scanner.hasNextLine()) {
|
String st = scanner.nextLine();
|
VideoInfo videoInfo = new Gson().fromJson(st, VideoInfo.class);
|
String name = videoInfo.getName();
|
nameList.add(name);
|
}
|
scanner.close();
|
|
Collections.shuffle(nameList);
|
for (String name : nameList) {
|
File f = new File("F:\\影视信息\\豆瓣影视搜索信息\\" + name + ".html");
|
if (!f.exists()) {
|
try {
|
DouBanUtil.saveSearch(name, f.getAbsolutePath());
|
if (sleepTime > 1) {
|
sleepTime--;
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
sleepTime++;
|
}
|
Thread.sleep(sleepTime * 1000);
|
}
|
}
|
|
|
}
|
|
@Test
|
public void saveVideoInfo() throws IOException {
|
List<AlbumVideoMap> mapList = albumVideoMapDao.listAll(6690, 40000);
|
int page = mapList.size() % 20 == 0 ? mapList.size() / 20 : mapList.size() / 20 + 1;
|
for (int i = 0; i < page; i++) {
|
int start = i * 20;
|
int end = mapList.size() > i * 20 + 20 ? i * 20 + 20 : mapList.size();
|
List<AlbumVideoMap> subList = mapList.subList(start, end);
|
List<String> localIdList = new ArrayList<>();
|
List<String> internetIdList = new ArrayList<>();
|
for (AlbumVideoMap map : subList) {
|
String videoId = map.getVideoId();
|
if (org.yeshi.utils.NumberUtil.isNumeric(videoId)) {
|
localIdList.add(videoId);
|
} else {
|
internetIdList.add(videoId);
|
}
|
}
|
List<VideoInfo> videoInfoList = new ArrayList<>();
|
if (localIdList.size() > 0) {
|
videoInfoList.addAll(videoInfoService.listByVideoIds(localIdList));
|
}
|
|
if (internetIdList.size() > 0) {
|
List<InternetSearchVideo> ivideoList = internetSearchVideoService.listByIds(internetIdList);
|
if (ivideoList.size() > 0) {
|
for (InternetSearchVideo searchVideo : ivideoList) {
|
videoInfoList.add(VideoInfoFactory.create(searchVideo));
|
}
|
}
|
}
|
|
for (VideoInfo videoInfo : videoInfoList) {
|
videoInfo.setIntroduction("");
|
FileUtil.appendSave(new Gson().toJson(videoInfo) + "\n", "F:\\影视信息\\片名.txt");
|
}
|
|
}
|
}
|
|
|
}
|