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
package com.yeshi.buwan.videos.tencent.factory;
 
import com.yeshi.buwan.util.NumberUtil;
import com.yeshi.buwan.util.StringUtil;
import com.yeshi.buwan.videos.tencent.entity.TencentCoverInfo;
import com.yeshi.buwan.videos.tencent.entity.TencentCoverVideo;
import com.yeshi.buwan.videos.tencent.vo.TencentCoverInfoVO;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
/**
 * @author hxh
 * @title: TencentCoverInfoFactory
 * @description: 工厂
 * @date 2024/3/14 16:25
 */
public class TencentCoverInfoFactory {
 
    private static List<String> toList(Object data){
        if(data instanceof Map){
            List<String> list=new ArrayList<>();
            for(Object k : ((Map)data).keySet()){
                list.add(((Map)data).get(k).toString());
            }
            return list;
        }if(data instanceof  List){
         return (List<String>)data;
        }
        return null;
    }
 
    public static TencentCoverInfo create(TencentCoverInfoVO vo){
        TencentCoverInfo info=new TencentCoverInfo();
 
        info.setAlias(toList(vo.getAlias()));
        info.setArea_name(vo.getArea_name());
        info.setCartoon_age(vo.getCartoon_age());
        info.setCategory_map(toList(vo.getCategory_map()));
        info.setCover_id(vo.getCover_id());
        info.setDescription(vo.getDescription());
        info.setEpisode_all(vo.getEpisode_all());
        info.setEpisode_updated(null);
        info.setGuests(toList(vo.getGuests()));
        info.setKeyword(toList(vo.getKeyword()));
        info.setLeading_actor(toList(vo.getLeading_actor()));
        info.setNew_pic_hz(vo.getNew_pic_hz());
        info.setNew_pic_vt(vo.getNew_pic_vt());
        info.setPay_status(vo.getPay_status());
        info.setPublish_date(vo.getPublish_date());
        info.setScore(null);
        info.setSecond_title(vo.getSecond_title());
        info.setTag(toList(vo.getTag()));
        info.setTitle(vo.getTitle());
        info.setType(vo.getType());
        info.setType_name(vo.getType_name());
        List<TencentCoverVideo> videoList=new ArrayList<>();
        for(TencentCoverInfoVO.EpisodeVO ep:vo.getEpisodes()){
            videoList.add(create(ep));
        }
        info.setVideoList(videoList);
        // 电视剧与动漫
        if(vo.getEpisode_update()!=null){
            info.setEpisode_updated(vo.getEpisode_update());
        }else {
            if (vo.getType() == 2 || vo.getType() == 3) {
                String latestTag = null;
                for (int i = vo.getEpisodes().size() - 1; i >= 0; i--) {
                    if (NumberUtil.isNumeric(vo.getEpisodes().get(i).getTitle())) {
                        latestTag = vo.getEpisodes().get(i).getTitle();
                        break;
                    }
                }
                if (latestTag != null) {
                    if (Integer.parseInt(vo.getEpisode_all()) == Integer.parseInt(latestTag)) {
                        info.setEpisode_updated("全" + vo.getEpisode_all() + "集");
                    } else {
                        info.setEpisode_updated("更新至" + latestTag + "集");
                    }
                } else {
                    info.setEpisode_updated("更新至0集");
                }
            }
        }
        return info;
    }
 
    private static TencentCoverVideo create(TencentCoverInfoVO.EpisodeVO vo){
        TencentCoverVideo video=new TencentCoverVideo();
        video.setCoverId(vo.getCid());
        video.setDate(vo.getPublishDate());
        video.setLink(String.format("https://v.qq.com/x/cover/%s/%s.html",vo.getCid(),vo.getVid()));
        video.setPosition(vo.getIndex());
        video.setStage(vo.getIndex()+1);
        video.setVideoId(vo.getVid());
        video.setTitle(vo.getTitle());
        video.setSubTitle(vo.getVideoSubtitle());
        return video;
    }
 
}