admin
2025-02-20 f537abe9f3646c739beaf15076246a2f71a347e9
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
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.service.inter.juhe.TencentVideoService;
import com.yeshi.buwan.util.StringUtil;
import com.yeshi.buwan.videos.tencent.TencentVideoApiUtil;
import com.yeshi.buwan.videos.tencent.entity.TencentCoverInfo;
import com.yeshi.buwan.videos.tencent.factory.TencentCoverInfoFactory;
import com.yeshi.buwan.videos.tencent.vo.TencentCoverInfoVO;
import net.sf.json.JSONObject;
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("debug");
 
    @Resource
    private TencentVideoService tencentVideoService;
 
 
    private TencentCoverInfo getCoverDetail(String coverId) throws Exception {
        TencentCoverInfoVO detail = TencentVideoApiUtil.getCoverInfo(String.format("https://v.qq.com/x/cover/%s.html", coverId));
        return TencentCoverInfoFactory.create(detail);
    }
 
    public void updateCategory(String channel,int startPage,int endPage, Integer areaId) {
        logger.info("更新分类:"+channel);
        for (int i = startPage; i <= endPage; i++) {
            List<TencentCoverInfoVO> coverInfoList = TencentVideoApiUtil.getVideoListByCategory(channel, i, areaId);
            save(coverInfoList);
        }
    }
 
    private void save(List<TencentCoverInfoVO> coverInfoList) {
        if (coverInfoList != null)
            for (TencentCoverInfoVO coverInfo : coverInfoList) {
                System.out.println(coverInfo.getTitle() + ":" + coverInfo.getCover_id());
                try {
//                    tencentVideoService.save(TencentCoverInfoFactory.create(coverInfo));
                    tencentVideoService.addToInternetSearch( TencentCoverInfoFactory.create(coverInfo),true);
                } catch (Exception e) {
                    e.printStackTrace();
                    logger.error("保存出错",e);
                }
            }
    }
 
 
    /**
     * 更新最近几天的视频
     *
     * @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(param,1,1,null);
        } else {
            for (String type : types) {
                updateCategory(type,1,1, null);
            }
        }
        return ReturnT.SUCCESS;
    }
 
 
    @XxlJob("video-update-tencent-updateVideo-byweburl")
    public ReturnT<String> updateLatestVideoByWebUrl(String param) throws Exception {
        JSONObject json = JSONObject.fromObject(param);
        int page = json.optInt("page");
        String url = json.optString("url");
//        List<TencentCoverInfoVO> list = TencentVideoApiUtil.getVideoList(TencentWebUtil.getApiUrl(url, page));
//        save(list);
        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.addToInternetSearch(detail, true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return ReturnT.SUCCESS;
    }
}