admin
2024-09-05 ab35ac8b769b2d9816dffb33a64f2c6f7bd5dd6e
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
131
132
133
134
135
136
137
138
139
140
141
142
package com.yeshi.buwan.job.video;
 
import com.google.gson.Gson;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.yeshi.buwan.videos.iqiyi.IqiYiNewAPI;
import com.yeshi.buwan.videos.iqiyi.entity.IqiyiAlbum2;
import com.yeshi.buwan.service.manager.search.SolrShortVideoDataManager;
import com.yeshi.buwan.util.StringUtil;
import com.yeshi.buwan.util.factory.SolrShortVideoFactory;
import com.yeshi.buwan.util.video.web.IqiyiWebUtil;
import com.yeshi.buwan.util.video.web.TencentWebUtil;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
 
/**
 * 短视频更新
 */
@Component
public class ShortVideoUpdateJob {
 
    @Resource
    private SolrShortVideoDataManager solrShortVideoDataManager;
 
    private class URLParams {
 
        private Integer videoType;
        private String url;
        private String area;
 
        public Integer getVideoType() {
            return videoType;
        }
 
        public void setVideoType(Integer videoType) {
            this.videoType = videoType;
        }
 
        public String getUrl() {
            return url;
        }
 
        public void setUrl(String url) {
            this.url = url;
        }
 
        public String getArea() {
            return area;
        }
 
        public void setArea(String area) {
            this.area = area;
        }
    }
 
    /**
     * 同
     *
     * @param param
     * @return
     * @throws Exception
     */
 
    private URLParams getParams(String param) throws Exception {
        if (StringUtil.isNullOrEmpty(param)) {
            throw new Exception("参数不能为空");
        }
        URLParams urlParams = new Gson().fromJson(param, URLParams.class);
        if (urlParams.getVideoType() == null) {
            throw new Exception("videoType不能为空");
        }
        if (StringUtil.isNullOrEmpty(urlParams.getUrl())) {
            throw new Exception("url不能为空");
        }
        return urlParams;
    }
 
    /**
     * 更新爱奇艺视频
     *
     * @param param
     * @return
     * @throws Exception
     */
    @XxlJob("video-update-shortvideo-iqiyi")
    public ReturnT<String> updateIqiyiShortVideo(String param) throws Exception {
        URLParams urlParams = getParams(param);
 
        for (int i = 19; i >= 0; i--) {
            try {
                List<Long> idList = IqiyiWebUtil.getVideoTvidList(IqiyiWebUtil.parseParams(urlParams.getUrl()), i + 1);
                if (idList.size() == 0) {
                    continue;
                }
                Collections.reverse(idList);
                //保存
                for (Long id : idList) {
                    IqiyiAlbum2 album = IqiYiNewAPI.getAlbumOrVideoDetail(id);
                    if (album != null)
                        solrShortVideoDataManager.saveOrUpdate(SolrShortVideoFactory.create(album, urlParams.getVideoType()));
                }
 
            } catch (Exception e) {
            }
        }
 
        return ReturnT.SUCCESS;
    }
 
    /**
     * 更新腾讯视频
     *
     * @param param
     * @return
     * @throws Exception
     */
    @XxlJob("video-update-shortvideo-tencent")
    public ReturnT<String> updateTencentShortVideo(String param) throws Exception {
        URLParams urlParams = getParams(param);
        if (StringUtil.isNullOrEmpty(urlParams.getArea())) {
            throw new Exception("area不能为空");
        }
 
//        for (int i = 19; i >= 0; i--) {
//            try {
//                List<TencentWebUtil.TencentWebVideoInfo> list = TencentWebUtil.getVideoList(TencentWebUtil.parseParams(urlParams.getUrl()), i + 1);
//                if (list.size() == 0)
//                    continue;
//                Collections.reverse(list);
//                for (TencentWebUtil.TencentWebVideoInfo videoInfo : list) {
//                    solrShortVideoDataManager.saveOrUpdate(SolrShortVideoFactory.create(videoInfo, urlParams.getArea(), urlParams.getVideoType()));
//                }
//            } catch (Exception e) {
//
//            }
//        }
        return ReturnT.SUCCESS;
    }
}