admin
2021-03-26 351b317c56487676b4f5a60b5bc3710a383d7a7b
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
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.mogotv.MogoTVApiUtil;
import com.yeshi.buwan.mogotv.entity.MogoTVClipInfo;
import com.yeshi.buwan.mogotv.entity.MogoTVVideo;
import com.yeshi.buwan.service.inter.juhe.MogoTVService;
import com.yeshi.buwan.service.inter.juhe.TencentVideoService;
import com.yeshi.buwan.tencent.TencentVideoApiUtil;
import com.yeshi.buwan.tencent.TencentVideoUtil;
import com.yeshi.buwan.tencent.entity.TencentCoverInfo;
import com.yeshi.buwan.util.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.util.List;
 
@Component
public class TencentVideoUpdate {
 
    private final static Logger logger = LoggerFactory.getLogger(TencentVideoUpdate.class);
 
    @Resource
    private TencentVideoService tencentVideoService;
 
 
    private TencentCoverInfo getCoverDetail(String coverId) throws Exception {
        TencentCoverInfo detail = TencentVideoApiUtil.getCoverInfo(String.format("https://v.qq.com/x/cover/%s.html", coverId));
        return detail;
    }
 
    private void updateCategory(String channel) {
        int totalPage = 50;
        for (int i = 0; i < totalPage; i++) {
            List<TencentCoverInfo> coverInfoList = TencentVideoApiUtil.getVideoListByCategory(channel, i + 1);
            for (TencentCoverInfo coverInfo : coverInfoList) {
                System.out.println(coverInfo.getTitle()+":"+coverInfo.getCover_id());
                try {
                    tencentVideoService.save(coverInfo);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
 
    private String getChannel(String cate) throws Exception {
        switch (cate) {
            case "综艺":
                return "variety";
            case "电影":
                return "movie";
            case "电视剧":
                return "tv";
            case "动漫":
                return "cartoon";
        }
 
        throw new Exception("类型不匹配");
 
    }
 
    /**
     * 更新最近几天的视频
     *
     * @param param
     * @return
     * @throws Exception
     */
    @XxlJob("video-update-tencent-updateVideo")
    public ReturnT<String> updateLatestVideo(String param) throws Exception {
        String[] types = new String[]{
                "电视剧", "动漫"
        };
 
        if (!StringUtil.isNullOrEmpty(param)) {
            updateCategory(getChannel(param));
        } else {
            for (String type : types) {
                updateCategory(getChannel(type));
            }
        }
        return ReturnT.SUCCESS;
    }
 
 
    /**
     * 更新单个视频
     *
     * @param param
     * @return
     * @throws Exception
     */
    @XxlJob("video-update-tencent-updateSingleVideo")
    public ReturnT<String> updateSingleVideo(String param) throws Exception {
        String[] cids = param.split(",");
        for (String cid : cids) {
            try {
                TencentCoverInfo detail = getCoverDetail(cid);
                tencentVideoService.save(detail);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return ReturnT.SUCCESS;
    }
}