admin
2020-10-10 81db7b3b070c003e6f5f0d1c757ab30b6f42c944
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package com.yeshi.buwan.job.video;
 
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.yeshi.buwan.funtv.FunTVNewApi;
import com.yeshi.buwan.funtv.entity.FunTVAlbum2;
import com.yeshi.buwan.funtv.entity.FunTVShortVideo2;
import com.yeshi.buwan.funtv.entity.FunTVVideo2;
import com.yeshi.buwan.iqiyi.IqiYiNewAPI;
import com.yeshi.buwan.iqiyi.util.IqiyiUtil2;
import com.yeshi.buwan.service.inter.juhe.FunTV2Service;
import com.yeshi.buwan.service.inter.juhe.Iqiyi2Service;
import com.yeshi.buwan.util.StringUtil;
import com.yeshi.buwan.util.mq.CMQManager;
import com.yeshi.buwan.vo.video.funtv.Funtv2ResultVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
 
@Component
public class FunTV2VideoUpdate {
 
    private final static Logger logger = LoggerFactory.getLogger(FunTV2VideoUpdate.class);
 
    @Resource
    private FunTV2Service funTV2Service;
 
 
    @XxlJob("video-update-funtv2-updateLatestVideo")
    public ReturnT<String> updateLatestVideo(String param) throws Exception {
        int d = 1;
        if (!StringUtil.isNullOrEmpty(param))
            d = Integer.parseInt(param);
        //获取最近1天的专辑
        List<FunTVAlbum2> list = getLatestAlbum(d);
        for (FunTVAlbum2 album2 : list) {
            funTV2Service.saveAlbum(album2);
            if (album2.getEpisodes() != null)
                for (FunTVVideo2 video2 : album2.getEpisodes())
                    funTV2Service.saveVideo(video2);
            CMQManager.getInstance().addFunTVAlbumUpdateMsg(album2.getId());
        }
 
        //获取最近一天的短视频
        List<FunTVShortVideo2> shortVideo2List = getLatestShortVideo(d);
        if (shortVideo2List != null)
            for (FunTVShortVideo2 video2 : shortVideo2List)
                funTV2Service.saveShortVideo(video2);
        return ReturnT.SUCCESS;
    }
 
 
    @XxlJob("video-update-funtv2-updateAlbumById")
    public ReturnT<String> updateAlbumById(String param) throws Exception {
        FunTVAlbum2 album2 = FunTVNewApi.getAlbumsDetail(param);
        if (album2 != null) {
            funTV2Service.saveAlbum(album2);
            if (album2.getEpisodes() != null)
                for (FunTVVideo2 video2 : album2.getEpisodes())
                    funTV2Service.saveVideo(video2);
            CMQManager.getInstance().addFunTVAlbumUpdateMsg(album2.getId());
        }
        return ReturnT.SUCCESS;
    }
 
    /**
     * 获取最近的短视频
     *
     * @return
     */
    public List<FunTVShortVideo2> getLatestShortVideo(int d) {
        List<FunTVShortVideo2> shortVideo2List = new ArrayList<>();
        int pageSize = 100;
        long now = System.currentTimeMillis();
        int page = 1;
        int totalPage = -1;
        while (true) {
            Funtv2ResultVO result = FunTVNewApi.getVideos(page, pageSize, now - 1000 * 60 * 60L * 24 * d, now - 1000 * 60 * 60L * 24 * (d - 1), null, null);
            if (result != null) {
                for (Serializable a : result.getList()) {
                    FunTVShortVideo2 video2 = (FunTVShortVideo2) a;
                    shortVideo2List.add(video2);
                }
            }
            int count = result.getCount();
            if (totalPage < 0)
                totalPage = count % pageSize == 0 ? count / pageSize : count / pageSize + 1;
            if (page > totalPage)
                break;
            page++;
        }
        return shortVideo2List;
    }
 
 
    /**
     * 获取最近的专辑
     *
     * @return
     */
    private List<FunTVAlbum2> getLatestAlbum(int d) {
        List<FunTVAlbum2> funTVAlbum2List = new ArrayList<>();
        int pageSize = 100;
        long now = System.currentTimeMillis();
        int page = 1;
        int totalPage = -1;
        while (true) {
            Funtv2ResultVO result = FunTVNewApi.getAlbums(page, pageSize, now - 1000 * 60 * 60L * 24 * d, now - 1000 * 60 * 60L * 24 * (d - 1), null, null);
            if (result != null) {
                for (Serializable a : result.getList()) {
                    FunTVAlbum2 video2 = (FunTVAlbum2) a;
                    funTVAlbum2List.add(video2);
                }
            }
            int count = result.getCount();
            if (totalPage < 0)
                totalPage = count % pageSize == 0 ? count / pageSize : count / pageSize + 1;
            if (page > totalPage)
                break;
            page++;
        }
        return funTVAlbum2List;
    }
 
}