package com.hxh.spring.test.video;
|
|
|
import com.yeshi.buwan.dao.VideoInfoDao;
|
import com.yeshi.buwan.dao.juhe.hanmi.HanmiShowDao;
|
import com.yeshi.buwan.dao.juhe.hanmi.HanmiShowEpisodeDao;
|
import com.yeshi.buwan.dao.juhe.hanmi.VideoHanmiMapDao;
|
import com.yeshi.buwan.dao.juhe.youku.InternetSearchVideoDao;
|
import com.yeshi.buwan.domain.ResourceVideo;
|
import com.yeshi.buwan.domain.video.InternetSearchVideo;
|
import com.yeshi.buwan.service.imp.ResourceVideoService;
|
import com.yeshi.buwan.service.imp.VideoInfoService;
|
import com.yeshi.buwan.service.imp.VideoService;
|
import com.yeshi.buwan.service.inter.juhe.HanmiService;
|
import com.yeshi.buwan.service.inter.juhe.InternetSearchVideoService;
|
import com.yeshi.buwan.videos.hanmi.HanmiApiUtil;
|
import com.yeshi.buwan.videos.hanmi.entity.HanmiShow;
|
import com.yeshi.buwan.videos.hanmi.entity.HanmiShowEpisode;
|
import com.yeshi.buwan.videos.hanmi.entity.VideoHanmiMap;
|
import org.junit.Test;
|
import org.junit.runner.RunWith;
|
import org.springframework.data.mongodb.core.query.Criteria;
|
import org.springframework.data.mongodb.core.query.Query;
|
import org.springframework.data.mongodb.core.query.Update;
|
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.web.WebAppConfiguration;
|
|
import javax.annotation.Resource;
|
import java.io.IOException;
|
import java.util.Collections;
|
import java.util.Date;
|
import java.util.List;
|
|
@RunWith(SpringJUnit4ClassRunner.class) //使用junit4进行测试
|
@ContextConfiguration(locations = {"classpath:spring.xml"})
|
@WebAppConfiguration
|
public class HanmiTest {
|
|
@Resource
|
private HanmiService hanmiService;
|
|
@Resource
|
private HanmiShowEpisodeDao hanmiShowEpisodeDao;
|
|
@Resource
|
private HanmiShowDao hanmiShowDao;
|
|
final String MOVIE_URL = "https://www.wztaichuan.com/vod/show/area/%E9%9F%A9%E5%9B%BD/id/1/page/{页码}.html";
|
final String SHOW_URL = "https://www.wztaichuan.com/vod/show/area/%E9%9F%A9%E5%9B%BD/id/3/page/{页码}.html";
|
final String TV_URL = "https://www.wztaichuan.com/vod/type/id/5/page/{页码}.html";
|
|
private List<HanmiShow> updateShow(String listUrl,int page) throws Exception {
|
List<HanmiShow> showList = HanmiApiUtil.parseDetailList(HanmiApiUtil.parseList(listUrl.replace("{页码}",page+"")));
|
for (HanmiShow show : showList) {
|
if(listUrl.contains("/id/1/")){
|
show.setType("电影");
|
}else if(listUrl.contains("/id/3/")){
|
show.setType("综艺");
|
}else if(listUrl.contains("/id/5/")){
|
show.setType("电视剧");
|
}
|
hanmiService.saveShow(show);
|
}
|
return showList;
|
}
|
|
|
|
@Test
|
public void updateLatest() throws Exception {
|
String[] urls =new String[]{MOVIE_URL,SHOW_URL,TV_URL};
|
for(String url: urls) {
|
for (int i = 1; i < 20; i++) {
|
System.out.printf(i + "==========================");
|
// 电影 https://www.wztaichuan.com/vod/show/area/%E9%9F%A9%E5%9B%BD/id/1/page/2.html
|
// 综艺 https://www.wztaichuan.com/vod/show/area/%E9%9F%A9%E5%9B%BD/id/3/page/2.html
|
// 韩剧 https://www.wztaichuan.com/vod/type/id/5/page/2.html
|
List<HanmiShow> showList = updateShow(url,i);
|
if (showList.size() < 10) {
|
break;
|
}
|
}
|
}
|
}
|
|
|
@Test
|
public void addHanJu() throws Exception {
|
for (int i = 1; i < 30; i++) {
|
List<HanmiShow> showList = updateShow(SHOW_URL,i);
|
if (showList.size() < 10) {
|
break;
|
}
|
}
|
}
|
|
@Test
|
public void addToVideo() throws IOException {
|
long count = hanmiService.countAll();
|
int pageSize = 100;
|
int totalPage=(int) (count%pageSize ==0?count/pageSize:count/pageSize+1);
|
for(int i=0;i<totalPage;i++) {
|
List<HanmiShow> list = hanmiService.listAll(i + 1, pageSize);
|
for(HanmiShow show:list){
|
try {
|
show = hanmiService.getShowDetail(show.getId());
|
hanmiService.addToInternetSearch(show);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
}
|
|
@Test
|
public void addSingleVideo() throws Exception {
|
//解析数据
|
String pageUrl="https://www.hmtv.me/search/?wd=%E6%88%90%E4%BA%BA%E7%BB%83%E4%B9%A0%E7%94%9F";
|
List<HanmiShow> showList = HanmiApiUtil.parseDetailList(HanmiApiUtil.parseList(pageUrl));
|
for (HanmiShow show : showList) {
|
show.setType("韩剧");
|
hanmiService.saveShow(show);
|
}
|
//添加数据
|
for (HanmiShow show : showList) {
|
show.setId(show.getUrl().split("/show/")[1].trim());
|
show = hanmiService.getShowDetail(show.getId());
|
show.setType("韩剧");
|
if (show != null)
|
hanmiService.addToInternetSearch(show);
|
}
|
|
}
|
|
@Resource
|
private VideoHanmiMapDao videoHanmiMapDao;
|
|
@Resource
|
private InternetSearchVideoDao internetSearchVideoDao;
|
|
@Resource
|
private ResourceVideoService resourceVideoService;
|
|
@Resource
|
private VideoInfoDao videoInfoDao;
|
|
@Test
|
public void update() {
|
for (int i = 0; i < 100; i++) {
|
List<HanmiShow> list = hanmiShowDao.listAll(i*100, 100);
|
for (HanmiShow show : list) {
|
try {
|
show = HanmiApiUtil.parseShowDetail(show);
|
if (show != null && show.getEpisodeList() != null) {
|
// 更新封面图片
|
VideoHanmiMap map = videoHanmiMapDao.selectByShowId(show.getId());
|
if(map!=null){
|
InternetSearchVideo video = internetSearchVideoDao.get(map.getVideoId());
|
if(video!=null){
|
InternetSearchVideo update = new InternetSearchVideo();
|
update.setId(video.getId());
|
update.setVpicture(show.getPicture());
|
internetSearchVideoDao.updateSelective(update);
|
}
|
}
|
Query query = new Query();
|
query.addCriteria(new Criteria().where("_id").is(show.getId()));
|
Update update = new Update();
|
update.set("tag", show.getTag());
|
hanmiShowDao.update(query, update);
|
query = new Query();
|
query.addCriteria(new Criteria().where("showId").is(show.getId()));
|
hanmiShowEpisodeDao.delete(query);
|
// 删除原来的数据
|
for (HanmiShowEpisode episode : show.getEpisodeList()) {
|
episode.setShowId(show.getId());
|
episode.setId(HanmiShowEpisode.createId(episode.getShowId(), episode.getTag()));
|
episode.setCreateTime(new Date());
|
hanmiShowEpisodeDao.save(episode);
|
}
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
}
|
}
|
}
|
|
|
@Test
|
public void deleteFromVideo(){
|
// 清除韩迷数据
|
List<ResourceVideo> resourceVideos = resourceVideoService.listResourceVideo(28L,1,100 );
|
for(ResourceVideo rv:resourceVideos){
|
List<ResourceVideo> resourceList = resourceVideoService.getResourceList(rv.getVideo().getId());
|
resourceVideoService.delete(rv.getVideo().getId(), rv.getResource().getId());
|
if(resourceList.size()<2){
|
// 删除视频
|
videoInfoDao.delete(rv.getVideo());
|
}
|
}
|
}
|
|
|
}
|