admin
2021-01-04 aa6ef62aef83e277d4171df1d9f0803f91738216
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
package com.newvideo.letv;
 
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Component;
 
import com.newvideo.domain.VideoDetailInfo;
import com.newvideo.domain.VideoInfo;
import com.newvideo.letv.entity.LeTVAlbum;
import com.newvideo.letv.entity.LeTVVideo;
import com.newvideo.service.imp.juhe.LeService;
import com.newvideo.util.StringUtil;
import com.newvideo.util.TimeUtil;
 
import net.sf.json.JSONObject;
 
@Component
public class LeTVUtil {
    public final static String KEY = "a9d8aaabe16ea397f11a359672b26a34";
    public final static String UID = "870919";
    public final static String UUID = "ztereukows";
 
    public static String getSign() {
        return StringUtil.Md5(UID + KEY);
    }
 
    @Resource
    private LeService leService;
 
    // ר������
    @SuppressWarnings("unchecked")
    public void startParseAlbum() {
        for (int p = 3; p < 10; p++) {
            List<LeTVAlbum> list = LeAPI.albumList(p);
            for (LeTVAlbum album : list) {
                Map<String, Object> map = LeAPI.albumVideoList(album.getAlbumId(), 1);
                int count = Integer.parseInt(map.get("count") + "");
                int page = count % 20 == 0 ? count / 20 : count / 20 + 1;
                List<LeTVVideo> videoList = new ArrayList<LeTVVideo>();
                videoList.addAll((List<LeTVVideo>) map.get("data"));
                if (page > 1)
                    for (int i = 2; i <= page; i++) {
                        map = LeAPI.albumVideoList(album.getAlbumId(), i);
                        videoList.addAll((List<LeTVVideo>) map.get("data"));
                    }
                album.setVideoList(videoList);
                // ������ݿ�
                addLeTVAlbum(album);
            }
        }
    }
 
    public void startParseVideo() {
        for (int p = 1; p < 10; p++) {
            List<LeTVVideo> list = LeAPI.videoList(p);
            // ������ݿ�
        }
    }
 
    public void addLeTVVideo(LeTVVideo tv) {
        String id = leService.addLeTVVideo(tv) + "";
        if (!StringUtil.isNullOrEmpty(id)) {
            tv.setId(id);
            leService.addToVideo(tv);
        }
    }
 
    public void addLeTVAlbum(LeTVAlbum album) {
        String id = leService.addLeTVAlbum(album) + "";
        if (!StringUtil.isNullOrEmpty(id))
            album.setId(id);
        leService.addToVideo(album, leService.isUpdate(album));
    }
 
    public static VideoInfo convertToVideoInfo(LeTVAlbum album) {
        Calendar ca = Calendar.getInstance();
        ca.setTimeInMillis(TimeUtil.convertDateToTemp(album.getReleaseDate()));
        int year = ca.get(Calendar.YEAR);
        int month = ca.get(Calendar.MONTH) + 1;
        int day = ca.get(Calendar.DAY_OF_MONTH);
        Comparator<LeTVVideo> cm = new Comparator<LeTVVideo>() {
 
            public int compare(LeTVVideo o1, LeTVVideo o2) {
 
                return Integer.parseInt(o2.getEpisode()) - Integer.parseInt(o1.getEpisode());
            }
        };
        Collections.sort(album.getVideoList(), cm);
 
        JSONObject obj = new JSONObject();
        try {
            obj = JSONObject.fromObject(album.getExtendPropertiesStr());
        } catch (Exception e) {
 
        }
        String tag = "";
        if (album.getCategoryName().contains("��Ӱ")) {
            tag = "���֣�" + album.getScore();
        } else if (album.getCategoryName().contains("���Ӿ�")) {
            if (Integer.parseInt(album.getEpisodeCount()) > Integer.parseInt(album.getEpisodeNow()))
                tag = "������" + album.getEpisodeNow() + "��";
            else
                tag = album.getEpisodeNow() + "��ȫ";
        } else if (album.getCategoryName().contains("����")) {
            if (Integer.parseInt(album.getEpisodeCount()) > Integer.parseInt(album.getEpisodeNow()))
                tag = "������" + album.getEpisodeNow() + "��";
            else
                tag = album.getEpisodeNow() + "��ȫ";
        } else if (album.getCategoryName().contains("����")) {
            tag = "������" + album.getEpisodeNow();
        }
 
        VideoInfo vi = new VideoInfo();
        vi.setArea(album.getArea());
        vi.setBaseurl("");
        vi.setCanSave(false);
        vi.setCommentCount(0);
        vi.setContentType(1);
        vi.setCreatetime(System.currentTimeMillis());
        vi.setDay(day + "");
        vi.setDirector(obj.optString("director"));
        vi.setFocus("");
        vi.setHpicture(album.getAlbumCover());
        vi.setIntroduction(album.getSynopsis());
        vi.setLatestHpicture(album.getVideoList().get(0).getCover());
        vi.setLatestVpicture("");
        vi.setMainActor(obj.optString("actor"));
        vi.setMonth(month + "");
        vi.setName(album.getAlbumName());
        vi.setNowNumber(0 + "");
        vi.setOrderby("0");
        vi.setPicture(album.getAlbumCover());
        vi.setScore(album.getScore());
        vi.setShare("0");
        vi.setShow(1 + "");
        vi.setTag(tag);
        vi.setVpicture(album.getVideoList().get(0).getCover());
        vi.setWatchCount(0 + "");
        vi.setYear(year + "");
        vi.setUpdatetime(TimeUtil.convertDateToTemp2(album.getCreateTime()) + "");
        vi.setVideocount(album.getVideoList() != null ? album.getVideoList().size() : 1);
        return vi;
    }
 
    public static VideoInfo convertToVideoInfo(LeTVVideo tv) {
        Calendar ca = Calendar.getInstance();
        ca.setTimeInMillis(TimeUtil.convertDateToTemp2(tv.getCreateTime()));
        int year = ca.get(Calendar.YEAR);
        int month = ca.get(Calendar.MONTH) + 1;
        int day = ca.get(Calendar.DAY_OF_MONTH);
 
        JSONObject obj = JSONObject.fromObject(tv.getExtendPropertiesStr());
        String tag = "";
        if (tv.getCategoryName().contains("��Ӱ")) {
            tag = "���֣�" + tv.getScore();
        } else
            tag = "���֣�" + tv.getScore();
        VideoInfo vi = new VideoInfo();
        vi.setArea(tv.getArea());
        vi.setBaseurl("");
        vi.setCanSave(false);
        vi.setCommentCount(0);
        vi.setContentType(1);
        vi.setCreatetime(System.currentTimeMillis());
        vi.setDay(day + "");
        vi.setDirector(obj.optString("director"));
        vi.setFocus("");
        vi.setHpicture(tv.getCover());
        vi.setIntroduction(tv.getSynopsis());
        vi.setLatestHpicture(tv.getCover());
        vi.setLatestVpicture("");
        vi.setMainActor(obj.optString("actor"));
        vi.setMonth(month + "");
        vi.setName(tv.getVideoName());
        vi.setNowNumber(0 + "");
        vi.setOrderby("0");
        vi.setPicture(tv.getCover());
        vi.setScore(tv.getScore());
        vi.setShare("0");
        vi.setShow(1 + "");
        vi.setTag(tag);
        vi.setVpicture(tv.getCover());
        vi.setWatchCount(0 + "");
        vi.setYear(year + "");
        vi.setUpdatetime(ca.getTimeInMillis() + "");
        vi.setVideocount(1);
        return vi;
    }
 
    public static int getVideoType(String categoryName) {
        if (categoryName.contains("��Ӱ")) {
            return 151;
        } else if (categoryName.contains("���Ӿ�")) {
            return 150;
        } else if (categoryName.contains("����")) {
            return 153;
        } else if (categoryName.contains("����")) {
            return 152;
        } else {
            return 299;
        }
    }
 
    public static boolean isSameVideo(VideoInfo first, VideoInfo second) {
        if (first.getPicture().equalsIgnoreCase(second.getPicture()))
            return true;
        if (first.getYear().equalsIgnoreCase(second.getYear()))
            return true;
        return false;
    }
 
    public static VideoDetailInfo convertLeTVVideoToVideoDetail(LeTVVideo video) {
        VideoDetailInfo info = new VideoDetailInfo();
        if (video.getCategoryName().contains("����"))
            info.setTag(video.getVideoName());
        else if (video.getCategoryName().contains("��Ӱ")) {
            info.setTag(video.getVideoName());
        } else if (video.getCategoryName().contains("���Ӿ�")) {
            info.setTag(video.getEpisode());
        } else if (video.getCategoryName().contains("����")) {
            info.setTag(video.getEpisode());
        } else
            info.setTag(video.getVideoName());
        info.setId(Long.parseLong(video.getVideoId()));
        info.setExtraId(video.getVideoId());
        info.setType("letv");
        return info;
    }
 
}