package com.hxh.spring.test.video;
|
|
|
import com.yeshi.buwan.dao.juhe.hanmi.HanmiShowDao;
|
import com.yeshi.buwan.dao.juhe.hanmi.HanmiShowEpisodeDao;
|
import com.yeshi.buwan.service.inter.juhe.HanmiService;
|
import com.yeshi.buwan.videos.hanmi.HanmiApiUtil;
|
import com.yeshi.buwan.videos.hanmi.entity.HanmiShow;
|
import com.yeshi.buwan.videos.hanmi.entity.HanmiShowEpisode;
|
import org.junit.Test;
|
import org.junit.runner.RunWith;
|
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;
|
|
@Test
|
public void addHanJu() throws Exception {
|
for (int i = 1; i < 3; i++) {
|
List<HanmiShow> showList = HanmiApiUtil.parseDetailList(HanmiApiUtil.parseList("https://www.hmtv.me/hanju/page/" + i));
|
for (HanmiShow show : showList) {
|
hanmiService.saveShow(show);
|
// hanmiService.deleteByShowId(show.getId());
|
}
|
}
|
}
|
|
@Test
|
public void addToVideo() throws IOException {
|
|
for (int i = 1; i < 3; i++) {
|
List<HanmiShow> showList = HanmiApiUtil.parseList("https://www.hmtv.me/hanju/page/" + i);
|
Collections.reverse(showList);
|
for (HanmiShow show : showList) {
|
show.setId(show.getUrl().replace("/show/", "").trim());
|
show = hanmiService.getShowDetail(show.getId());
|
if (show != null)
|
hanmiService.addToVideoInfo(show);
|
}
|
}
|
}
|
|
@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.addToVideoInfo(show);
|
}
|
|
}
|
|
@Test
|
public void update() {
|
List<HanmiShow> list = hanmiShowDao.listAll(0, 100);
|
for (HanmiShow show : list) {
|
List<HanmiShowEpisode> epList = hanmiShowEpisodeDao.listByShowId(show.getId(), 0, 1);
|
if (epList != null && epList.size() > 0) {
|
try {
|
List<HanmiShowEpisode> episodeList = HanmiApiUtil.getShowEpisodesFromPlayUrl(epList.get(0).getPlayUrl());
|
if (episodeList != null)
|
for (HanmiShowEpisode episode : episodeList) {
|
episode.setShowId(show.getId());
|
episode.setId(HanmiShowEpisode.createId(episode.getShowId(), episode.getTag()));
|
episode.setCreateTime(new Date());
|
hanmiShowEpisodeDao.save(episode);
|
}
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
}
|
|
|
}
|