From 2778cf2a16823f9b1153a0549b47f7b503176a17 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期六, 12 九月 2020 18:04:43 +0800 Subject: [PATCH] 爱奇艺正片,搜索引擎 --- src/main/java/com/yeshi/buwan/iqiyi/util/IqiyiUtil2.java | 353 ++++++++++++++-------------------------------------------- 1 files changed, 89 insertions(+), 264 deletions(-) diff --git a/src/main/java/com/yeshi/buwan/iqiyi/util/IqiyiUtil2.java b/src/main/java/com/yeshi/buwan/iqiyi/util/IqiyiUtil2.java index 9055086..5994e7c 100644 --- a/src/main/java/com/yeshi/buwan/iqiyi/util/IqiyiUtil2.java +++ b/src/main/java/com/yeshi/buwan/iqiyi/util/IqiyiUtil2.java @@ -1,66 +1,35 @@ package com.yeshi.buwan.iqiyi.util; -import com.yeshi.buwan.dao.VideoInfoDao; -import com.yeshi.buwan.dao.juhe.iqiyi.IqiyiAlbum2Dao; -import com.yeshi.buwan.dao.juhe.iqiyi.VideoIqiyi2Dao; -import com.yeshi.buwan.dao.video.AlbumVideoMapDao; -import com.yeshi.buwan.domain.*; -import com.yeshi.buwan.domain.entity.PlayUrl; -import com.yeshi.buwan.domain.video.AlbumVideoMap; +import com.yeshi.buwan.domain.AdminInfo; +import com.yeshi.buwan.domain.VideoDetailInfo; +import com.yeshi.buwan.domain.VideoType; import com.yeshi.buwan.iqiyi.IqiYiNewAPI; import com.yeshi.buwan.iqiyi.entity.IqiyiAlbum2; -import com.yeshi.buwan.iqiyi.entity.VideoIqiyi2; import com.yeshi.buwan.iqiyi.vo.IqiyiAlbumListResult; -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.imp.VideoResourceService; -import com.yeshi.buwan.util.TimeUtil; +import com.yeshi.buwan.service.inter.juhe.Iqiyi2Service; import com.yeshi.buwan.util.mq.CMQManager; import com.yeshi.buwan.util.video.VideoConstant; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; -import java.io.Serializable; -import java.util.Calendar; +import java.io.IOException; +import java.util.ArrayList; import java.util.Date; import java.util.List; @Component public class IqiyiUtil2 { + public final static int PLAY_NONE = 0;// 涓嶈兘鎾斁 + public final static int PLAY_HTML = 1;// 璺宠浆绉诲姩绔綉椤垫挱鏀� + public final static int PLAY_SWF = 2;// 宓屽缃戦〉鎾斁 - - public final int PLAY_NONE = 0;// 不能播放 - public final int PLAY_HTML = 1;// 跳转移动端网页播放 - public final int PLAY_SWF = 2;// 嵌套网页播放 - - private final static long RESOURCE_ID = 22L; - + public final static long RESOURCE_ID = 22L; @Resource - private IqiyiAlbum2Dao iqiyiAlbum2Dao; - - @Resource - private VideoIqiyi2Dao videoIqiyi2Dao; - - @Resource - private VideoInfoDao videoInfoDao; - - - @Resource - private ResourceVideoService resourceVideoService; - - @Resource - private VideoInfoService videoInfoService; - - @Resource - private CategoryVideoService categoryVideoService; - - @Resource - private VideoResourceService videoResourceService; - - @Resource - private AlbumVideoMapDao albumVideoMapDao; + private Iqiyi2Service iqiyi2Service; private void saveAlbumAndVideo(List<IqiyiAlbum2> list) { if (list == null) @@ -75,15 +44,16 @@ List<IqiyiAlbum2> detailList = IqiYiNewAPI.getAlbumOrVideoDetail(album.getTvQipuIds().subList(startIndex, toIndex)); if (detailList != null) for (IqiyiAlbum2 video : detailList) - iqiyiAlbum2Dao.save(video); + iqiyi2Service.saveIqiyiAlbum(video); } } - iqiyiAlbum2Dao.save(album); + iqiyi2Service.saveIqiyiAlbum(album); + CMQManager.getInstance().addAlbumUpdateMsg(album.getId()); } } /** - * 同步所有的专辑与视频 + * 鍚屾鎵�鏈夌殑涓撹緫涓庤棰� * * @param categoryId * @param isAlbum @@ -97,31 +67,43 @@ if (result.getAlbum2List() != null) { saveAlbumAndVideo(result.getAlbum2List()); } - } } - //拉取所有的电影 + + /** + * 鏍规嵁涓撹緫ID鏌ヨ + * + * @param aid + */ + public void syncByAid(Long aid) { + List<Long> aidList = new ArrayList<>(); + aidList.add(aid); + List<IqiyiAlbum2> album2List = IqiYiNewAPI.getAlbumOrVideoDetail(aidList); + saveAlbumAndVideo(album2List); + } + + //鎷夊彇鎵�鏈夌殑鐢靛奖 public void syncAllDianYing() { syncAlbumAndVideo(IqiYiNewAPI.TYPE_DIANYING, false, 255675400l); } - //拉取所有的电视剧 + //鎷夊彇鎵�鏈夌殑鐢佃鍓� public void syncAllDianShiJu() { syncAlbumAndVideo(IqiYiNewAPI.TYPE_DIANSHIJU, true, 206929801L); } - //拉取所有的动漫 + //鎷夊彇鎵�鏈夌殑鍔ㄦ极 public void syncAllDongMan() { syncAlbumAndVideo(IqiYiNewAPI.TYPE_DONGMAN, true, 217289601L); } - //拉取所有的综艺 + //鎷夊彇鎵�鏈夌殑缁艰壓 public void syncAllZongYi() { syncAlbumAndVideo(IqiYiNewAPI.TYPE_ZONGYI, true, 246881501L); } - //更新专辑 + //鏇存柊涓撹緫 public void updateAlbum(int categoryId, Date startTime, Date endTime) { IqiyiAlbumListResult result = IqiYiNewAPI.getUpdateAlbumList(categoryId + "", startTime, endTime, null, true, 10); if (result.getAlbum2List() != null) @@ -133,7 +115,7 @@ } } - //更新视频 + //鏇存柊瑙嗛 public void updateVideo(int categoryId, Date startTime, Date endTime) { IqiyiAlbumListResult result = IqiYiNewAPI.getUpdateVideoList(categoryId + "", startTime, endTime, null, true, 10); if (result.getAlbum2List() != null) @@ -145,188 +127,32 @@ } } - //将专辑添加到视频 - @Transactional - public void addToVideoInfo(IqiyiAlbum2 album) { - if (album.getFeatureAlbumId() > 0L && album.getChannelId() != IqiYiNewAPI.TYPE_DIANYING) { - return; - } - //只缓存有效的 - if (album.getEffect() == 0) - return; - - //只缓存正片 - if (album.getContentType() != 1) - return; - - //综艺必须要有内容 - if (album.getChannelId() == 6) { - if (album.getTvQipuIds().size() == 0) - return; - } - - VideoInfo newVideoInfo = convertAlbumToVideoInfo(album); - VideoIqiyi2 videoIqiyi2 = videoIqiyi2Dao.selectByIqiyiId(album.getId()); - if (videoIqiyi2 != null) {//渠道视频已经存在 - VideoInfo videoInfo = videoInfoDao.find(VideoInfo.class, videoIqiyi2.getVideoId()); - if (videoInfo == null) - return; - - if (newVideoInfo.getTag().equalsIgnoreCase(videoInfo.getTag())) - return; - newVideoInfo.setId(videoInfo.getId()); - newVideoInfo.setCreatetime(videoInfo.getCreatetime()); - //更新信息tag信息 - videoInfo.setLatestHpicture(newVideoInfo.getLatestHpicture()); - videoInfo.setLatestVpicture(newVideoInfo.getLatestVpicture()); - videoInfo.setVideocount(newVideoInfo.getVideocount()); - videoInfo.setTag(newVideoInfo.getTag()); - videoInfo.setPicture(newVideoInfo.getPicture()); - videoInfo.setHpicture(newVideoInfo.getHpicture()); - videoInfo.setVpicture(newVideoInfo.getVpicture()); - videoInfo.setShow(newVideoInfo.getShow()); - videoInfoDao.update(videoInfo); - } else {//视频不存在 - //判断2个视频实体是否为同一视频 - VideoInfo oldVideo = videoInfoService.getExistSameVideo(newVideoInfo); - if (oldVideo == null) { - //添加视频 - Serializable id = videoInfoDao.save(newVideoInfo); - newVideoInfo.setId(id + ""); - } else {//为同一视频 - //更新tag - newVideoInfo.setId(oldVideo.getId()); - oldVideo.setLatestHpicture(newVideoInfo.getLatestHpicture()); - oldVideo.setLatestVpicture(newVideoInfo.getLatestVpicture()); - oldVideo.setVideocount(newVideoInfo.getVideocount()); - oldVideo.setTag(newVideoInfo.getTag()); - oldVideo.setPicture(newVideoInfo.getPicture()); - oldVideo.setHpicture(newVideoInfo.getHpicture()); - oldVideo.setVpicture(newVideoInfo.getVpicture()); - oldVideo.setShow(newVideoInfo.getShow()); - videoInfoDao.update(oldVideo); - } - - //加入专辑视频映射 - AlbumVideoMap map = new AlbumVideoMap(); - map.setCreateTime(new Date()); - map.setVideoId(newVideoInfo.getId()); - map.setRootVideoType(newVideoInfo.getVideoType().getId()); - map.setVideoCount(newVideoInfo.getVideocount()); - albumVideoMapDao.save(map); - - //加入映射 - VideoIqiyi2 vi = new VideoIqiyi2(); - vi.setIqiyiId(album.getId()); - vi.setVideoId(Long.parseLong(newVideoInfo.getId())); - videoIqiyi2Dao.save(vi); - - - //添加视频来源映射 - resourceVideoService.addVideoResource(newVideoInfo.getId(), RESOURCE_ID + ""); - //添加视频分类映射 - categoryVideoService.addCategoryVideo(newVideoInfo.getId(), newVideoInfo.getVideoType().getId()); - - CMQManager.getInstance().addSolrMsg(newVideoInfo.getId()); - } - - - } - - - //更新最近一天的的专辑与视频 + //鏇存柊鏈�杩戜竴澶╃殑鐨勪笓杈戜笌瑙嗛 public void updateTodayAlbumAndVideo() { long now = System.currentTimeMillis(); for (int i = 0; i < 8; i++) { Date endTime = new Date(now - i * 1000 * 60 * 60L * 3); Date startTime = new Date(endTime.getTime() - 1000 * 60 * 60L * 3); - //更新电影 + //鏇存柊鐢靛奖 updateVideo(IqiYiNewAPI.TYPE_DIANYING, startTime, endTime); - //更新电视剧 + //鏇存柊鐢佃鍓� updateAlbum(IqiYiNewAPI.TYPE_DIANSHIJU, startTime, endTime); updateVideo(IqiYiNewAPI.TYPE_DIANSHIJU, startTime, endTime); - //更新动漫 + //鏇存柊鍔ㄦ极 updateAlbum(IqiYiNewAPI.TYPE_DONGMAN, startTime, endTime); updateVideo(IqiYiNewAPI.TYPE_DONGMAN, startTime, endTime); - //更新综艺 + //鏇存柊缁艰壓 updateAlbum(IqiYiNewAPI.TYPE_ZONGYI, startTime, endTime); updateVideo(IqiYiNewAPI.TYPE_ZONGYI, startTime, endTime); } } - public VideoInfo convertAlbumToVideoInfo(IqiyiAlbum2 album) { - Calendar ca = Calendar.getInstance(); - ca.setTimeInMillis(TimeUtil.convertGernalTime(album.getPeriod(), "yyyyMMdd")); - int day = ca.get(Calendar.DAY_OF_MONTH); - int month = ca.get(Calendar.MONTH) + 1; - int year = ca.get(Calendar.YEAR); - - VideoInfo video = new VideoInfo(); - video.setVideoType(new VideoType(IqiyiUtil.getType(album.getContentType()))); - video.setArea(album.getAreas()); - video.setBaseurl(album.getH5Url()); - video.setCanSave(false); - video.setCommentCount(0); - video.setCreatetime(System.currentTimeMillis()); - video.setDay(day + ""); - video.setDirector(album.getDirectors()); - video.setDuration(album.getDuration() + ""); - video.setFinish("1"); - video.setIntroduction(album.getDesc()); - video.setMainActor(album.getMainCharacters()); - video.setMonth(month + ""); - video.setName(album.getName()); - if (album.getLatestVideo() != null) - video.setNowNumber(album.getLatestVideo().getOrder() + ""); - else - video.setNowNumber("1"); - video.setOrderby("0" + ""); - video.setPicture(album.getImageUrl()); - - video.setVpicture(IqiyiUtil.getVPicture(video.getPicture())); - video.setHpicture(IqiyiUtil.getHPicture(video.getPicture())); - - if (album.getStatistics() != null) - video.setScore(album.getStatistics().getScore() + ""); - video.setShare("0"); - video.setShow("1"); - - video.setThirdType("1"); - video.setTotalNumber("0"); - - video.setWatchCount(0 + ""); - video.setYear(year + ""); - video.setAdmin(new AdminInfo("1")); - video.setContentType(album.getContentType()); - video.setCommentCount(0); - - String tag = getAlbumTag(album); - video.setTag(tag); - - if (album.getLatestVideo() != null) { - //查询最近的图片 - IqiyiAlbum2 album2 = iqiyiAlbum2Dao.get(album.getLatestVideo().getId()); - if (album2 != null) { - video.setLatestHpicture(IqiyiUtil.getHPicture(album2.getImageUrl())); - video.setLatestVpicture(IqiyiUtil.getVPicture(album2.getImageUrl())); - } - } - - if (album.getTvQipuIds() != null && album.getTvQipuIds().size() > 0) - video.setVideocount(album.getTvQipuIds().size()); - else - video.setVideocount(1); - - video.setVideoType(getVideoType(album)); - return video; - } - - private static VideoType getVideoType(IqiyiAlbum2 album) { + public static VideoType getVideoType(IqiyiAlbum2 album) { if (album.getChannelId() == IqiYiNewAPI.TYPE_DIANYING) { return new VideoType(VideoConstant.VIDEO_CATEGORY_DIANYING); } else if (album.getChannelId() == IqiYiNewAPI.TYPE_DIANSHIJU) { @@ -339,27 +165,26 @@ return null; } - private static String getAlbumTag(IqiyiAlbum2 album) { - //电影为评分 - //电视剧和动漫为更新到多少集 - //综艺为更新到多少期 + public static String getAlbumTag(IqiyiAlbum2 album) { + //鐢靛奖涓鸿瘎鍒� + //鐢佃鍓у拰鍔ㄦ极涓烘洿鏂板埌澶氬皯闆� + //缁艰壓涓烘洿鏂板埌澶氬皯鏈� String tag = ""; - if (album.getChannelId() == IqiYiNewAPI.TYPE_DIANYING) + if (album.getChannelId() == IqiYiNewAPI.TYPE_DIANYING) { if (album.getStatistics() != null) - tag = "评分:" + album.getStatistics().getScore(); - else if (album.getChannelId() == IqiYiNewAPI.TYPE_DIANSHIJU || album.getChannelId() == IqiYiNewAPI.TYPE_DONGMAN) { - if (album.getLatestVideo() != null) { - if (album.getLatestVideo().getOrder() == album.getVideoCount()) - tag = album.getVideoCount() + "集全"; - else - tag = "更新至" + album.getLatestVideo().getOrder() + "集"; - } - tag = album.getLatestVideo().getOrder() + ""; - } else if (album.getChannelId() == IqiYiNewAPI.TYPE_ZONGYI) - if (album.getLatestVideo() != null) { - tag = "更新至" + album.getLatestVideo().getPeriod() + "期"; - } + tag = "璇勫垎锛�" + album.getStatistics().getScore(); + } else if (album.getChannelId() == IqiYiNewAPI.TYPE_DIANSHIJU || album.getChannelId() == IqiYiNewAPI.TYPE_DONGMAN) { + if (album.getLatestVideo() != null) { + if (album.getLatestVideo().getOrder() == album.getVideoCount()) + tag = album.getVideoCount() + "闆嗗叏"; + else + tag = "鏇存柊鑷�" + album.getLatestVideo().getOrder() + "闆�"; + } + } else if (album.getChannelId() == IqiYiNewAPI.TYPE_ZONGYI) + if (album.getLatestVideo() != null) { + tag = "鏇存柊鑷�" + album.getLatestVideo().getPeriod() + "鏈�"; + } return tag; } @@ -381,40 +206,14 @@ } - public int getShowType(String videoid) { - VideoInfo videoInfo = videoInfoDao.find(VideoInfo.class, videoid); - if (videoInfo.getVideoType() != null && (videoInfo.getVideoType().getId() == VideoConstant.VIDEO_CATEGORY_DIANSHIJU || videoInfo.getVideoType().getId() == VideoConstant.VIDEO_CATEGORY_DONGMAN)) - return 1; - else - return 2; - } - - - public PlayUrl getPlayUrl(String detailSystemId, int resourceId, String id, String videoId) { - IqiyiAlbum2 album = iqiyiAlbum2Dao.get(Long.parseLong(id)); - VideoResource vr = videoResourceService.getResource(resourceId + ""); - int t = getPlayType(album); - PlayUrl pu = new PlayUrl(); - pu.setParams(""); - pu.setPlayType(t); - pu.setResource(vr); - - if (t == PLAY_NONE) { - pu.setUrl(""); - } else if (t == PLAY_HTML) { - pu.setUrl(album.getH5Url()); - } - return pu; - } - - public int getPlayType(IqiyiAlbum2 album) { + public static int getPlayType(IqiyiAlbum2 album) { int type = PLAY_NONE; if (album.getEffect() == 0) type = PLAY_NONE; for (IqiyiAlbum2.PlayControlsBean pc : album.getPlayControls()) { - if (pc.getPlatformId() == 15)// 移动端 + if (pc.getPlatformId() == 15)// 绉诲姩绔� { type = PLAY_HTML; } @@ -422,4 +221,30 @@ return type; } + + /** + * 閫氳繃鍒楄〃閾炬帴鑾峰彇鐖卞鑹轰腑鐨勮棰� + * + * @param url + * @return + */ + public static List<String> getAlbumUrlsFromUrl(String url) { + List<String> list = new ArrayList<>(); + try { + Document doc = Jsoup.connect(url).userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36").timeout(60000).get(); + Element root = doc.getElementsByAttributeValue("class", "qy-mod-ul").get(0); + Elements items = root.getElementsByAttributeValue("class", "qy-mod-li"); + for (int i = 0; i < items.size(); i++) { + String href = items.get(i).getElementsByTag("a").get(0).attr("href"); + if (href.startsWith("//")) + href = "http:" + href; + list.add(href); + } + } catch (IOException e) { + e.printStackTrace(); + } + return list; + } + + } -- Gitblit v1.8.0