| | |
| | | package com.hxh.spring.test; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.yeshi.buwan.dao.juhe.iqiyi.IqiyiAlbum2Dao; |
| | | import com.yeshi.buwan.iqiyi.entity.IqiyiAlbum2; |
| | | import com.yeshi.buwan.iqiyi.util.IqiyiUtil2; |
| | | import com.yeshi.buwan.dao.juhe.iqiyi.VideoIqiyi2Dao; |
| | | import com.yeshi.buwan.dao.juhe.iqiyi.VideoIqiyiDao; |
| | | import com.yeshi.buwan.domain.ResourceVideo; |
| | | import com.yeshi.buwan.domain.VideoInfo; |
| | | import com.yeshi.buwan.domain.VideoResource; |
| | | import com.yeshi.buwan.exception.video.IqiyiVideoSolrException; |
| | | import com.yeshi.buwan.videos.iqiyi.IqiYiNewAPI; |
| | | import com.yeshi.buwan.videos.iqiyi.entity.IqiyiAlbum2; |
| | | import com.yeshi.buwan.videos.iqiyi.entity.VideoIqiyi; |
| | | import com.yeshi.buwan.videos.iqiyi.util.IqiyiUtil2; |
| | | import com.yeshi.buwan.videos.iqiyi.vo.IqiyiAlbumListResult; |
| | | import com.yeshi.buwan.job.video.Iqiyi2VideoUpdate; |
| | | import com.yeshi.buwan.query.Iqiyi2AlbumQuery; |
| | | import com.yeshi.buwan.service.imp.CategoryVideoService; |
| | | import com.yeshi.buwan.service.imp.ResourceVideoService; |
| | | import com.yeshi.buwan.service.imp.VideoInfoService; |
| | | import com.yeshi.buwan.service.inter.juhe.Iqiyi2Service; |
| | | import com.yeshi.buwan.service.manager.search.SolrAlbumVideoDataManager; |
| | | import com.yeshi.buwan.util.HtmlToolUtil; |
| | | import com.yeshi.buwan.util.StringUtil; |
| | | import com.yeshi.buwan.util.TimeUtil; |
| | | import com.yeshi.buwan.util.mq.CMQManager; |
| | | import net.sf.json.JSONArray; |
| | | import org.junit.Test; |
| | | import org.junit.runner.RunWith; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.orm.hibernate4.HibernateObjectRetrievalFailureException; |
| | | 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.*; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Scanner; |
| | | |
| | | // |
| | | @RunWith(SpringJUnit4ClassRunner.class) //使用junit4进行测试 |
| | | @ContextConfiguration(locations = {"classpath:spring.xml"}) |
| | | @WebAppConfiguration |
| | | public class Iqiyi2 { |
| | | |
| | | private final static Logger errorLogger = LoggerFactory.getLogger("errorLogger"); |
| | | |
| | | @Resource |
| | | private IqiyiUtil2 iqiyiUtil2; |
| | |
| | | @Resource |
| | | private IqiyiAlbum2Dao iqiyiAlbum2Dao; |
| | | |
| | | @Resource |
| | | private Iqiyi2Service iqiyi2Service; |
| | | |
| | | @Resource |
| | | private CategoryVideoService categoryVideoService; |
| | | |
| | | @Resource |
| | | private ResourceVideoService resourceVideoService; |
| | | |
| | | @Resource |
| | | private Iqiyi2VideoUpdate iqiyi2VideoUpdate; |
| | | |
| | | |
| | | @Test |
| | | public void syncAll() { |
| | | iqiyiUtil2.syncAllZongYi(); |
| | | iqiyiUtil2.updateTodayAlbumAndVideo(IqiYiNewAPI.TYPE_DIANYING); |
| | | } |
| | | |
| | | @Test |
| | | public void syncDongMan(){ |
| | | public void syncDongMan() { |
| | | iqiyiUtil2.syncAllDongMan(); |
| | | } |
| | | |
| | | @Test |
| | | public void addToVideoInfo() { |
| | | IqiyiAlbum2 album = iqiyiAlbum2Dao.get(90023000L); |
| | | iqiyiUtil2.addToVideoInfo(album); |
| | | List<IqiyiAlbum2> list = iqiyiAlbum2Dao.listByChannelId(1, null, 1, 11000, 3000); |
| | | for (IqiyiAlbum2 album : list) |
| | | try { |
| | | iqiyi2Service.addToVideoInfo(album); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | @Test |
| | | public void syncOne() { |
| | | iqiyiUtil2.syncByAid(111367401L, true); |
| | | // iqiyiUtil2.syncByAid(253393601L); |
| | | // iqiyiUtil2.syncByAid(253305701L); |
| | | // iqiyiUtil2.syncByAid(247742201L); |
| | | } |
| | | |
| | | |
| | | @Test |
| | | public void getIdFromUrl() { |
| | | String id = "240793601"; |
| | | List<Long> list = new ArrayList<>(); |
| | | list.add(Long.parseLong(id)); |
| | | List<IqiyiAlbum2> album2List = IqiYiNewAPI.getAlbumOrVideoDetail(list); |
| | | System.out.println(album2List); |
| | | |
| | | } |
| | | |
| | | |
| | | @Test |
| | | public void syncByAid() { |
| | | |
| | | // Long[] ids = new Long[]{ |
| | | // 246508201L, 248886801L, 230798901L, 1569537751867101L, |
| | | // }; |
| | | |
| | | iqiyiUtil2.syncByAid(3697683745816301L,true); |
| | | |
| | | // IqiyiAlbum2 album2 = iqiyi2Service.selectAlbumById(240793601L); |
| | | // if (album2 != null) { |
| | | // iqiyi2Service.addToVideoInfo(album2); |
| | | // } |
| | | |
| | | Long qikuID = 3697683745816301L; |
| | | |
| | | IqiyiAlbum2 album2 = iqiyi2Service.selectAlbumById(qikuID); |
| | | if (album2 != null) { |
| | | iqiyi2Service.addToVideoInfo(album2); |
| | | } |
| | | |
| | | // CMQManager.getInstance().addSolrMsg(8169108L+""); |
| | | |
| | | |
| | | // errorLogger.error("测试错误"); |
| | | |
| | | } |
| | | |
| | | |
| | | @Test |
| | | public void updateLatest() { |
| | | List<String> urlList = IqiyiUtil2.getAlbumUrlsFromUrl("https://www.iqiyi.com/v_u3d4t2dr7o.html?vfrm=pcw_dianshiju&vfrmblk=B&vfrmrst=fcs_2_p2"); |
| | | for (String url : urlList) { |
| | | String aid = IqiYiNewAPI.getAidByUrl(url); |
| | | iqiyiUtil2.syncByAid(Long.parseLong(aid), true); |
| | | } |
| | | } |
| | | |
| | | @Test |
| | | public void test6() { |
| | | try { |
| | | iqiyi2VideoUpdate.updateVideoByPlayerUrl("https://www.iqiyi.com/v_u3d4t2dr7o.html?vfrm=pcw_dianshiju&vfrmblk=B&vfrmrst=fcs_2_p2"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | private void saveToFile(List<Long> list) { |
| | | FileWriter fw = null; |
| | | try { |
| | | //如果文件存在,则追加内容;如果文件不存在,则创建文件 |
| | | File f = new File("E:\\iqiyialbum_invalid.txt"); |
| | | fw = new FileWriter(f, true); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | PrintWriter pw = new PrintWriter(fw); |
| | | pw.println(new Gson().toJson(list)); |
| | | pw.flush(); |
| | | try { |
| | | fw.flush(); |
| | | pw.close(); |
| | | fw.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | @Test |
| | | public void count() { |
| | | // long count = iqiyiAlbum2Dao.countVideoByAid(253120001L); |
| | | // System.out.println(count); |
| | | IqiyiAlbum2 album2 = iqiyiAlbum2Dao.get(2928406697871201L); |
| | | iqiyi2Service.addToVideoInfo(album2); |
| | | } |
| | | |
| | | |
| | | @Test |
| | | public void sync() { |
| | | |
| | | iqiyi2Service.convertAlbumToVideoInfo(iqiyiAlbum2Dao.get(253593801L)); |
| | | |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | Date startTime = new Date(TimeUtil.convertGernalTime("2020-10-23", "yyyy-MM-dd")); |
| | | Date endTime = new Date(TimeUtil.convertGernalTime("2020-10-23 03", "yyyy-MM-dd HH")); |
| | | IqiyiAlbumListResult result = IqiYiNewAPI.getUpdateAlbumList(IqiYiNewAPI.TYPE_DIANYING + "", startTime, endTime, null, false, 20); |
| | | System.out.println(result); |
| | | } |
| | | |
| | | @Test |
| | | public void deleteAlbum() { |
| | | try { |
| | | Scanner scanner = new Scanner(new FileInputStream(new File("E:\\iqiyialbum_invalid.txt"))); |
| | | while (scanner.hasNextLine()) { |
| | | String text = scanner.nextLine(); |
| | | if (!StringUtil.isNullOrEmpty(text)) { |
| | | JSONArray array = JSONArray.fromObject(text); |
| | | for (int i = 0; i < array.size(); i++) { |
| | | iqiyi2Service.deleteByAid(array.optLong(i)); |
| | | } |
| | | } |
| | | } |
| | | scanner.close(); |
| | | } catch (FileNotFoundException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | @Test |
| | | public void addToMQ() { |
| | | Iqiyi2AlbumQuery query = new Iqiyi2AlbumQuery(); |
| | | query.setContentType(1); |
| | | query.setFeatureAlbumId(0L); |
| | | query.setChannelId(2); |
| | | |
| | | long count = iqiyiAlbum2Dao.countByAid(query); |
| | | int page = (int) (count % 100 == 0 ? count / 100 : count / 100 + 1); |
| | | |
| | | for (int i = 0; i < page; i++) { |
| | | List<IqiyiAlbum2> album2List = iqiyiAlbum2Dao.listByAid(query, IqiyiAlbum2.SORT_ID, i * 100, 100); |
| | | for (IqiyiAlbum2 album2 : album2List) { |
| | | System.out.println(album2.getName()); |
| | | if (IqiyiUtil2.albumIsValid(album2)) { |
| | | CMQManager.getInstance().addIqiyiAlbumUpdateMsg(album2.getId()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Test |
| | | public void addCategory() { |
| | | List<String[]> list = HtmlToolUtil.parseSQLYogExportHtmData("C:\\Users\\Administrator\\Desktop\\爱奇艺分类缺失.htm", 2); |
| | | for (String[] sts : list) { |
| | | String videoId = sts[0]; |
| | | String videoType = sts[1]; |
| | | categoryVideoService.addCategoryVideo(videoId, Long.parseLong(videoType)); |
| | | } |
| | | } |
| | | |
| | | |
| | | @Resource |
| | | private VideoIqiyiDao videoIqiyiDao; |
| | | |
| | | @Test |
| | | public void deleteOldIqiyiVideo() { |
| | | List<String[]> list = HtmlToolUtil.parseSQLYogExportHtmData("C:\\Users\\Administrator\\Desktop\\爱奇艺老版正片.htm", 3); |
| | | for (String[] sts : list) { |
| | | String videoId = sts[0]; |
| | | List<VideoIqiyi> list1 = videoIqiyiDao.listByVideoId(videoId); |
| | | if (list1 != null) |
| | | for (VideoIqiyi videoIqiyi : list1) |
| | | videoIqiyiDao.delete(videoIqiyi); |
| | | } |
| | | } |
| | | |
| | | @Resource |
| | | private VideoInfoService videoInfoService; |
| | | |
| | | @Resource |
| | | private SolrAlbumVideoDataManager solrDataManager; |
| | | |
| | | @Test |
| | | public void addResources() { |
| | | try { |
| | | VideoInfo videoInfo = videoInfoService.getVideoInfo(8174476 + ""); |
| | | if (videoInfo != null) { |
| | | if ("1".equalsIgnoreCase(videoInfo.getShow())) { |
| | | List<VideoResource> resourceList = new ArrayList<>(); |
| | | List<ResourceVideo> rvList = resourceVideoService.getResourceList(videoInfo.getId()); |
| | | if (rvList != null) |
| | | for (ResourceVideo rv : rvList) |
| | | resourceList.add(rv.getResource()); |
| | | videoInfo.setResourceList(resourceList); |
| | | solrDataManager.saveOrUpdate(videoInfo); |
| | | } else |
| | | solrDataManager.deleteById(videoInfo.getId()); |
| | | } |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | |
| | | |
| | | @Resource |
| | | private VideoIqiyi2Dao videoIqiyi2Dao; |
| | | |
| | | @Test |
| | | public void getDetail() { |
| | | |
| | | |
| | | iqiyiUtil2.syncByAid(2928406697871201L, true); |
| | | // System.out.println(album2); |
| | | } |
| | | |
| | | //同步爱奇艺的专题 |
| | | @Test |
| | | public void syncIqiyiAlbum() throws IOException { |
| | | //写入爱奇艺ID |
| | | // File f = new File("D:/iqiyi.txt"); |
| | | // f.delete(); |
| | | // if (!f.exists()) |
| | | // f.createNewFile(); |
| | | // BufferedWriter out = new BufferedWriter(new FileWriter(f.getAbsolutePath())); |
| | | // try { |
| | | // for (int i = 0; i < 261; i++) { |
| | | // List<VideoIqiyi2> list = videoIqiyi2Dao.listAll(i*100, 100); |
| | | // for (VideoIqiyi2 iqiyi2 : list) { |
| | | // out.write(iqiyi2.getIqiyiId() + ""); |
| | | // out.newLine(); |
| | | // } |
| | | // } |
| | | // } finally { |
| | | // out.close(); |
| | | // } |
| | | |
| | | List<String> list = new ArrayList<>(); |
| | | Scanner scanner = new Scanner(new File("D:/iqiyi.txt")); |
| | | while (scanner.hasNextLine()) { |
| | | String line = scanner.nextLine(); |
| | | list.add(line.trim()); |
| | | } |
| | | scanner.close(); |
| | | for (int i = 25244; i < list.size(); i++) |
| | | try { |
| | | iqiyiUtil2.syncByAid(Long.parseLong(list.get(i)), true); |
| | | } catch (HibernateObjectRetrievalFailureException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | @Test |
| | | public void validSolrState() { |
| | | try { |
| | | iqiyi2Service.validAlbumSolrState(2928406697871201L); |
| | | } catch (IqiyiVideoSolrException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |