| | |
| | | package com.hxh.spring.test; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.yeshi.buwan.dao.juhe.pptv.PPTVProgramDao; |
| | | import com.yeshi.buwan.dao.juhe.pptv.PPTVSeriesDao; |
| | | import com.yeshi.buwan.dao.juhe.pptv.PPTVSeriesProgramMapDao; |
| | | import com.yeshi.buwan.dao.juhe.pptv.VideoPPTVMapDao; |
| | | import com.yeshi.buwan.job.video.PPTVVideoUpdate; |
| | | import com.yeshi.buwan.videos.pptv.PPTVApiUtil; |
| | | import com.yeshi.buwan.videos.pptv.entity.PPTVSeries; |
| | | import com.yeshi.buwan.videos.pptv.entity.PPTVSeriesProgramMap; |
| | | import com.yeshi.buwan.videos.pptv.entity.VideoPPTVMap; |
| | | import com.yeshi.buwan.service.inter.LoginUserService; |
| | | import com.yeshi.buwan.service.inter.juhe.PPTVService; |
| | | import com.yeshi.buwan.util.StringUtil; |
| | | import jxl.Sheet; |
| | | import jxl.Workbook; |
| | | import jxl.write.Label; |
| | | import jxl.write.WritableCell; |
| | | import jxl.write.WritableSheet; |
| | | import jxl.write.WritableWorkbook; |
| | | 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 org.yeshi.utils.HtmlToolUtil; |
| | | |
| | | import com.yeshi.buwan.pptv.PPTVUtil; |
| | | import com.yeshi.buwan.util.BeanUtil; |
| | | import javax.annotation.Resource; |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.util.*; |
| | | |
| | | |
| | | @RunWith(SpringJUnit4ClassRunner.class) //使用junit4进行测试 |
| | | @ContextConfiguration(locations = {"classpath:spring.xml"}) |
| | | @WebAppConfiguration |
| | | public class PPTVTest { |
| | | |
| | | @Test |
| | | public void pptvShort() { |
| | | // SolrUtil.search("崔神驾到", 1); |
| | | // PPTVService pptvService = BeanUtil.getBean(PPTVService.class); |
| | | // PPTVShortVideo pv = new PPTVShortVideo(); |
| | | // pv.setAid("158552322"); |
| | | // pptvService.deletePPTVShort(pv); |
| | | // VideoManager vm = BeanUtil.getBean(VideoManager.class); |
| | | // vm.deleteVideo("921153"); |
| | | PPTVUtil pptvUtil=BeanUtil.getBean(PPTVUtil.class); |
| | | pptvUtil.startParseTV(); |
| | | @Resource |
| | | private PPTVService pptvService; |
| | | |
| | | } |
| | | |
| | | @Resource |
| | | private PPTVSeriesDao pptvSeriesDao; |
| | | |
| | | |
| | | @Resource |
| | | private PPTVProgramDao pptvProgramDao; |
| | | |
| | | @Resource |
| | | private PPTVSeriesProgramMapDao pptvSeriesProgramMapDao; |
| | | |
| | | @Resource |
| | | private VideoPPTVMapDao videoPPTVMapDao; |
| | | |
| | | |
| | | @Resource |
| | | private PPTVVideoUpdate pptvVideoUpdate; |
| | | |
| | | @Resource |
| | | private LoginUserService loginUserService; |
| | | |
| | | @Test |
| | | public void saveAll() { |
| | | List<PPTVSeries> list = PPTVApiUtil.getTotalList(); |
| | | // pptvService.save(list); |
| | | } |
| | | |
| | | @Test |
| | | public void addToVideoInfo() { |
| | | // List<PPTVSeries> list = pptvSeriesDao.list(2000, 1000); |
| | | // for (PPTVSeries s : list) { |
| | | // if (s.getProgramType().contains("少儿") || s.getProgramType2().contains("少儿")) { |
| | | // continue; |
| | | // } |
| | | // System.out.println(s.getName() + ":" + s.getInfoID()); |
| | | |
| | | Query query = new Query(); |
| | | query.addCriteria(new Criteria().orOperator(Criteria.where("programType").regex("电影"), Criteria.where("programType2").regex("电影"))); |
| | | |
| | | List<String> list = new ArrayList<>(); |
| | | |
| | | List<PPTVSeries> seriesList = pptvSeriesDao.findList(query); |
| | | for (PPTVSeries series : seriesList) { |
| | | VideoPPTVMap map = pptvService.selectVideoPPTVMapByPPInfo(series.getInfoID(), null); |
| | | |
| | | if (map != null && map.getProgramCode() == null) { |
| | | series = pptvService.getSeriesDetail(series.getInfoID()); |
| | | map.setSeriesCode(series.getSeriesCode()); |
| | | map.setProgramCode(series.getSeries().get(0).getProgramCode()); |
| | | videoPPTVMapDao.save(map); |
| | | } else { |
| | | if (map == null) { |
| | | list.add(series.getInfoID()); |
| | | // series = PPTVApiUtil.getDetail(series.getSeriesCode()); |
| | | series = pptvService.getSeriesDetail(series.getInfoID()); |
| | | pptvService.addToVideoInfo(series); |
| | | } |
| | | } |
| | | } |
| | | |
| | | System.out.println(new Gson().toJson(list)); |
| | | |
| | | |
| | | // } |
| | | } |
| | | |
| | | |
| | | @Test |
| | | public void test() { |
| | | PPTVApiUtil.getOpenId("123"); |
| | | } |
| | | |
| | | @Test |
| | | public void update() { |
| | | // try { |
| | | // pptvVideoUpdate.updateLatestVideo(""); |
| | | // } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | |
| | | List<PPTVSeries> list = PPTVApiUtil.getUpdateList(); |
| | | System.out.println(list); |
| | | } |
| | | |
| | | @Test |
| | | public void syncVideo() { |
| | | try { |
| | | pptvVideoUpdate.syncVideo("32427297"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | @Test |
| | | public void login() { |
| | | PPTVApiUtil.login("zcoAY6ev7RpYSLzXKtWybniCK+sgBiCARUii_uyNdFw-"); |
| | | } |
| | | |
| | | |
| | | @Test |
| | | public void getApiDetail() { |
| | | PPTVSeries series = PPTVApiUtil.getDetail("28544897"); |
| | | System.out.println(series); |
| | | } |
| | | |
| | | |
| | | @Test |
| | | public void getOpenId() { |
| | | //CODE:XefbSM0H8BC9kaEGEjHF2U7wd6Sd9ec1oSUmG1gZDTg= |
| | | // PPTVApiUtil.login("XefbSM0H8BC9kaEGEjHF2U7wd6Sd9ec1oSUmG1gZDTg="); |
| | | String pptvUid = "buwan_844600";//PPTVUtil.decryptPPTVCode("XefbSM0H8BC9kaEGEjHF2U7wd6Sd9ec1oSUmG1gZDTg=").pptvUid; |
| | | String openId = PPTVApiUtil.getOpenId(pptvUid); |
| | | System.out.println(openId); |
| | | |
| | | // try { |
| | | // loginUserService.updatePPTVOpenId("766693"); |
| | | // } catch (PPTVException e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | |
| | | } |
| | | |
| | | |
| | | @Test |
| | | public void getVIPPriceList() { |
| | | PPTVApiUtil.getVIPPriceList(); |
| | | } |
| | | |
| | | |
| | | @Test |
| | | public void addVideoInfo() { |
| | | // List<PPTVSeries> seriesList = pptvSeriesDao.list("少儿", 0, 100); |
| | | // for (PPTVSeries series : seriesList) { |
| | | PPTVSeries series = pptvService.getSeriesDetail("381472"); |
| | | pptvService.addToVideoInfo(series); |
| | | // } |
| | | } |
| | | |
| | | @Test |
| | | public void offline() { |
| | | List<String[]> list = HtmlToolUtil.parseSQLYogExportHtmData("C:\\Users\\Administrator\\Desktop\\草稿\\PPTV重复的电视剧.htm", 1); |
| | | for (int i = 1000; i < list.size(); i++) { |
| | | String[] sts = list.get(i); |
| | | String name = sts[0]; |
| | | Query query = new Query(); |
| | | query.addCriteria(Criteria.where("name").is(name)); |
| | | PPTVSeries series = pptvSeriesDao.findOne(query); |
| | | if (series != null) { |
| | | pptvService.offLineSeries(series.getInfoID()); |
| | | //添加到详情 |
| | | try { |
| | | Thread.sleep(1000 * 3L); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | series = pptvService.getSeriesDetail(series.getInfoID()); |
| | | pptvService.addToVideoInfo(series); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Test |
| | | public void reAddVideo() { |
| | | reAdd("武林外传"); |
| | | } |
| | | |
| | | private void reAdd(String name) { |
| | | Query query = new Query(); |
| | | query.addCriteria(Criteria.where("name").is(name)); |
| | | PPTVSeries series = pptvSeriesDao.findOne(query); |
| | | if (series != null) { |
| | | pptvService.offLineSeries(series.getInfoID()); |
| | | //添加到详情 |
| | | try { |
| | | Thread.sleep(1000 * 3L); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | series = pptvService.getSeriesDetail(series.getInfoID()); |
| | | pptvService.addToVideoInfo(series); |
| | | } |
| | | } |
| | | |
| | | private List<String[]> getPPTVVideos(File f, int sheetNum) { |
| | | List<String[]> videoList = new ArrayList<>(); |
| | | try { |
| | | jxl.Workbook rwb = Workbook.getWorkbook(new FileInputStream(f)); |
| | | Sheet sheet = rwb.getSheet(sheetNum); |
| | | for (int c = 1; c < sheet.getRows(); c++) { |
| | | String infoId = sheet.getCell(0, c).getContents().trim(); |
| | | String name = sheet.getCell(1, c).getContents().trim(); |
| | | String del = sheet.getCell(21, c).getContents().trim(); |
| | | if (!StringUtil.isNullOrEmpty(infoId) && StringUtil.isNullOrEmpty(del)) { |
| | | videoList.add(new String[]{infoId, name, del}); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | return videoList; |
| | | } |
| | | |
| | | |
| | | @Test |
| | | public void checkPPTVVideos() { |
| | | List<String[]> list1 = getPPTVVideos(new File("C:\\Users\\Administrator\\Desktop\\全量.xls"), 0); |
| | | List<String[]> list2 = getPPTVVideos(new File("C:\\Users\\Administrator\\Desktop\\全量.xls"), 1); |
| | | Map<String, String[]> map = new TreeMap<>(); |
| | | Set<String> sets = new HashSet<>(); |
| | | for (String[] sts : list1) { |
| | | map.put(sts[0], sts); |
| | | sets.add(sts[1]); |
| | | } |
| | | |
| | | for (String[] sts : list2) { |
| | | map.put(sts[0], sts); |
| | | sets.add(sts[1]); |
| | | } |
| | | |
| | | // List<PPTVSeries> list = pptvSeriesDao.list(0, 10000); |
| | | // Set<String> infoIds = new HashSet<>(); |
| | | // for (PPTVSeries s : list) { |
| | | // infoIds.add(s.getInfoID()); |
| | | // } |
| | | // |
| | | // for (String infoId : infoIds) { |
| | | // map.remove(infoId); |
| | | // } |
| | | |
| | | for (String code : sets) |
| | | getDetail(code); |
| | | |
| | | // try { |
| | | // save(map); |
| | | // } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | |
| | | // System.out.println(map); |
| | | } |
| | | |
| | | private void save(Map<String, String[]> data) throws Exception { |
| | | WritableWorkbook wwb = Workbook.createWorkbook(new File("C:\\Users\\Administrator\\Desktop\\布丸输出片单_缺失.xls")); |
| | | WritableSheet sheet = wwb.createSheet("缺失", 0); |
| | | sheet.addCell((WritableCell) new Label(0, 0, "百科ID")); |
| | | sheet.addCell((WritableCell) new Label(1, 0, "名称")); |
| | | int row = 1; |
| | | for (Iterator<String> its = data.keySet().iterator(); its.hasNext(); ) { |
| | | String key = its.next(); |
| | | sheet.addCell((WritableCell) new Label(0, row, key)); |
| | | sheet.addCell((WritableCell) new Label(1, row, data.get(key)[1])); |
| | | row++; |
| | | } |
| | | wwb.write(); |
| | | wwb.close(); |
| | | } |
| | | |
| | | |
| | | @Test |
| | | public void logs() { |
| | | // LoggerUtil.getVIPLogger().info("123123"); |
| | | |
| | | Map<String, String[]> data = new TreeMap<>(); |
| | | data.put("4234234", new String[]{"4234234", "测试"}); |
| | | try { |
| | | save(data); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | // @Test |
| | | public void getDetail(String sCode) { |
| | | PPTVSeries series = PPTVApiUtil.getDetail(sCode); |
| | | pptvService.save(series); |
| | | } |
| | | |
| | | |
| | | @Test |
| | | public void buy() { |
| | | PPTVApiUtil.buyGoods("257dfd950c20ad25dee9f99ef926c0f8", "danpian-1", "AB5574873120458", new Date()); |
| | | } |
| | | |
| | | @Test |
| | | public void updateGoodsInfo() { |
| | | Query query = new Query(); |
| | | query.addCriteria(new Criteria("goodsInfo").is(null).andOperator(Criteria.where("free").is("1"))); |
| | | query.limit(400); |
| | | List<PPTVSeries> list = pptvSeriesDao.findList(query); |
| | | for (PPTVSeries series : list) { |
| | | PPTVSeries detail = PPTVApiUtil.getDetail(series.getSeriesCode()); |
| | | query = new Query(); |
| | | query.addCriteria(Criteria.where("_id").is(detail.getInfoID())); |
| | | Update update = new Update(); |
| | | update.set("goodsInfo", detail.getGoodsInfo()); |
| | | pptvSeriesDao.update(query, update); |
| | | } |
| | | } |
| | | |
| | | |
| | | @Test |
| | | public void repaire() { |
| | | |
| | | Query query = new Query(); |
| | | query.addCriteria(Criteria.where("seriesCode").is(null)); |
| | | query.limit(200); |
| | | List<PPTVSeries> list = pptvSeriesDao.findList(query); |
| | | for (PPTVSeries pptvSeries : list) { |
| | | PPTVSeriesProgramMap map = pptvSeriesProgramMapDao.getLatestByInfoId(pptvSeries.getInfoID()); |
| | | pptvService.syncSeries(map.getSeriesCode()); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | @Test |
| | | public void sync() { |
| | | // PPTVSeries series = pptvService.getSeriesDetailByVideoId("8268375"); |
| | | // System.out.println(series); |
| | | |
| | | |
| | | getDetail("32501376"); |
| | | |
| | | } |
| | | |
| | | |
| | | } |