admin
2021-07-30 19533a17aa55fafc70d0a385928e785cb50e1ebc
src/main/java/com/yeshi/buwan/iqiyi/util/IqiyiUtil2.java
@@ -9,22 +9,26 @@
import com.yeshi.buwan.service.inter.juhe.Iqiyi2Service;
import com.yeshi.buwan.util.StringUtil;
import com.yeshi.buwan.util.TimeUtil;
import com.yeshi.buwan.util.log.VideoLogFactory;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.*;
@Component
public class IqiyiUtil2 {
    private final Logger logger = LoggerFactory.getLogger("iqiyiVideoUpdate");
    public final static int PLAY_NONE = 0;// 不能播放
    public final static int PLAY_HTML = 1;// 跳转移动端网页播放
    public final static int PLAY_SWF = 2;// 嵌套网页播放
@@ -40,8 +44,13 @@
        for (IqiyiAlbum2 album : list) {
            if (album.getContentType() != 1)
                continue;
            if (!albumIsValid(album))
            if (!albumIsValid(album)) {//如果是无效的专辑就需要删除
                iqiyi2Service.deleteByAid(album.getId());
                continue;
            }
            logger.info(VideoLogFactory.createAddAlbumLog(album));
            if (album.getTvQipuIds() != null && album.getTvQipuIds().size() > 0) {
                //查询最新的一集是否缓存
@@ -51,6 +60,7 @@
                        needSaveVideos = false;
                }
                if (needSaveVideos) {
                    int pageSize = 10;
                    int page = album.getTvQipuIds().size() % pageSize == 0 ? album.getTvQipuIds().size() / pageSize : album.getTvQipuIds().size() / pageSize + 1;
@@ -59,13 +69,22 @@
                        int toIndex = (startIndex + pageSize) > album.getTvQipuIds().size() ? album.getTvQipuIds().size() : (startIndex + pageSize);
                        List<Long> tvQipuIds = new ArrayList<>();
                        tvQipuIds.addAll(album.getTvQipuIds().subList(startIndex, toIndex));
                        for (int i = 0; i < tvQipuIds.size(); i++) {
                            long count = iqiyi2Service.countById(tvQipuIds.get(i));
                            if (count > 0) {
                                tvQipuIds.remove(i);
                                i--;
                        //查询是否已经存在了
                        List<IqiyiAlbum2> existList = iqiyi2Service.listByIds(tvQipuIds);
                        Set<Long> sets = new HashSet<>();
                        if (existList != null && existList.size() > 0) {
                            for (IqiyiAlbum2 a : existList)
                                sets.add(a.getId());
                            //删除已经存在的
                            for (int i = 0; i < tvQipuIds.size(); i++) {
                                if (sets.contains(tvQipuIds.get(i))) {
                                    tvQipuIds.remove(i--);
                                }
                            }
                        }
                        if (tvQipuIds.size() > 0) {
                            List<IqiyiAlbum2> detailList = IqiYiNewAPI.getAlbumOrVideoDetail(tvQipuIds);
                            if (detailList != null)
@@ -132,12 +151,12 @@
    }
    //更新专辑
    public void updateAlbum(int categoryId, Date startTime, Date endTime) {
        IqiyiAlbumListResult result = IqiYiNewAPI.getUpdateAlbumList(categoryId + "", startTime, endTime, null, true, 10);
    public void updateAlbum(int categoryId, boolean isAlbum, Date startTime, Date endTime) {
        IqiyiAlbumListResult result = IqiYiNewAPI.getUpdateAlbumList(categoryId + "", startTime, endTime, null, isAlbum, 10);
        if (result.getAlbum2List() != null)
            saveAlbumAndVideo(result.getAlbum2List());
        while (result.getMinId() != null) {
            result = IqiYiNewAPI.getUpdateAlbumList(categoryId + "", startTime, endTime, result.getMinId(), true, 10);
            result = IqiYiNewAPI.getUpdateAlbumList(categoryId + "", startTime, endTime, result.getMinId(), isAlbum, 10);
            if (result.getAlbum2List() != null)
                saveAlbumAndVideo(result.getAlbum2List());
        }
@@ -157,25 +176,22 @@
    //更新最近一天的的专辑与视频
    public void updateTodayAlbumAndVideo() {
    public void updateTodayAlbumAndVideo(int channelId) {
        long now = System.currentTimeMillis();
        for (int i = 0; i < 8; i++) {
            Date endTime = new Date(now - i * 1000 * 60 * 60L * 3);
            Date endTime = new Date(now - 1000 * 60 * 60L * 3 * i);
            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);
            switch (channelId) {
                case IqiYiNewAPI.TYPE_DIANYING:
                    updateAlbum(channelId, true, startTime, endTime);
                    break;
                case IqiYiNewAPI.TYPE_DIANSHIJU:
                case IqiYiNewAPI.TYPE_DONGMAN:
                case IqiYiNewAPI.TYPE_ZONGYI:
                    updateAlbum(channelId, true, startTime, endTime);
                    break;
            }
        }
    }