admin
2024-10-17 b30fb8afd3cd6228bda9b182dc412bb3c8daf69c
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
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.YouKuService;
import com.yeshi.buwan.util.StringUtil;
import com.yeshi.buwan.util.video.web.YouKuWebUtil;
import com.yeshi.buwan.videos.youku.YouKuApiUtil;
import com.yeshi.buwan.videos.youku.entity.YouKuShowDetail;
import com.yeshi.buwan.videos.youku.entity.YouKuShowSimple;
import com.yeshi.buwan.videos.youku.entity.YouKuVideo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.util.List;
 
@Component
public class YouKuVideoUpdate {
 
    private final static Logger logger = LoggerFactory.getLogger(YouKuVideoUpdate.class);
 
    @Resource
    private YouKuService youKuService;
 
 
    private YouKuShowDetail getShowDetail(String showId) throws Exception {
 
        YouKuShowDetail detail = YouKuApiUtil.getShowDetail(showId);
        int pageSize = 100;
        YouKuApiUtil.ListResultDTO resultDTO = YouKuApiUtil.getVideoList(showId, 1, pageSize);
        if (resultDTO == null)
            throw new Exception("视频列表获取出错");
        List<YouKuVideo> videoList = resultDTO.getList();
        if (videoList.size() < resultDTO.getTotal()) {
            int totalPage = resultDTO.getTotal() % pageSize == 0 ? resultDTO.getTotal() / pageSize : resultDTO.getTotal() / pageSize + 1;
            for (int i = 1; i < totalPage; i++) {
                resultDTO = YouKuApiUtil.getVideoList(showId, i + 1, pageSize);
                if (resultDTO != null)
                    videoList.addAll(resultDTO.getList());
            }
        }
 
        detail.setVideoList(videoList);
        return detail;
    }
 
    private void updateCategory(String categoryName) throws Exception {
        for(int i=0;i<2;i++){
            YouKuApiUtil.ListResultDTO dto = YouKuApiUtil.getHotShowListByCategory(categoryName, i+1, 24);
            for (YouKuShowSimple simple : (List<YouKuShowSimple>) dto.getList()) {
                System.out.println(simple.getName() + ":" + simple.getId());
                try {
                    YouKuShowDetail detail = getShowDetail(simple.getId());
                    youKuService.addToInternetSearch(detail);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
 
    /**
     * 更新最近几天的视频
     *
     * @param param
     * @return
     * @throws Exception
     */
    @XxlJob("video-update-youku-updateVideo")
    public ReturnT<String> updateLatestVideo(String param) throws Exception {
 
        String[] types = new String[]{
                "电影", "电视剧", "动漫", "综艺"
        };
        if (!StringUtil.isNullOrEmpty(param)) {
            if (param.length() < 10) {
                updateCategory(param);
            } else {
                String[] ids = param.split(",");
                for (String id : ids) {
                    YouKuShowDetail detail = getShowDetail(id);
                    youKuService.addToInternetSearch(detail);
                }
            }
        } else {
            for (String type : types) {
                updateCategory(type);
            }
        }
        return ReturnT.SUCCESS;
    }
 
 
    //更新专辑列表
    @XxlJob("video-update-youku-updateVideo-byCategoryUrl")
    public ReturnT<String> updatebyCategoryUrl(String param) throws Exception {
        String[] urlList = param.split(",");
        for (String url : urlList) {
            List<YouKuWebUtil.YouKuCoverInfo> list = YouKuWebUtil.parseCategoryList(url);
            if (list != null) {
                for (YouKuWebUtil.YouKuCoverInfo info : list) {
                    try {
                        YouKuShowDetail detail = getShowDetail(info.getShowId());
                        youKuService.addToInternetSearch(detail);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
 
                }
 
            }
 
        }
 
 
        return ReturnT.SUCCESS;
    }
 
}