admin
2021-04-27 f3ff5ab043cf612e119fd90cd82e49b2cfc2ab5a
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
package com.yeshi.buwan.pptv;
 
import com.yeshi.buwan.domain.VideoInfo;
import com.yeshi.buwan.domain.VideoType;
import com.yeshi.buwan.pptv.entity.PPTVProgram;
import com.yeshi.buwan.pptv.entity.PPTVSeries;
import com.yeshi.buwan.util.AESUtil;
import com.yeshi.buwan.util.StringUtil;
import com.yeshi.buwan.util.video.VideoConstant;
import com.yeshi.buwan.vo.AcceptData;
 
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
 
public class PPTVUtil {
 
    public final static int RESOURCE_ID = 25;
 
    public final static int PLAY_NONE = 0;// 不能播放
    public final static int PLAY_HTML = 1;// 跳转移动端网页播放
    public final static int PLAY_SDK = 2;// 内嵌SDK播放
 
 
    private static Long getVideoType(PPTVSeries series) {
        String type = series.getProgramType();
        if (type.contains("VIP")) {
            type = series.getProgramType2();
        }
 
        int videoType = 0;
        switch (type) {
            case "电影":
                videoType = VideoConstant.VIDEO_CATEGORY_DIANYING;
                break;
            case "电视剧":
                videoType = VideoConstant.VIDEO_CATEGORY_DIANSHIJU;
                break;
            case "综艺":
                videoType = VideoConstant.VIDEO_CATEGORY_ZONGYI;
                break;
            case "动漫":
                videoType = VideoConstant.VIDEO_CATEGORY_DONGMAN;
                break;
            case "少儿":
                videoType = 312;
                break;
            default:
                return null;
        }
 
        return (long) videoType;
    }
 
 
    /**
     * 视频转换
     *
     * @param series
     * @return
     */
    public static List<VideoConvertResult> convertToVideoInfo(PPTVSeries series) {
        Long videoTypeId = getVideoType(series);
 
        if (videoTypeId == null)
            return null;
 
        List<VideoConvertResult> list = new ArrayList<>();
 
        if (videoTypeId.longValue() == VideoConstant.VIDEO_CATEGORY_DIANYING) {
            //PPTV电影一个百科ID下面可能有多个视频(国语版/粤语版)
            for (PPTVProgram program : series.getSeries()) {
                list.add(new VideoConvertResult(convertToVideoInfo(series, program), program.getProgramCode()));
            }
        } else {
            list.add(new VideoConvertResult(convertToVideoInfo(series, null), null));
        }
        return list;
    }
 
    private static VideoInfo convertToVideoInfo(PPTVSeries series, PPTVProgram program) {
        int year = Integer.parseInt(series.getReleaseYear());
        int month = 1;
        int day = 1;
        String director = series.getDirector();
        String mainActor = series.getActor();
 
        String score = series.getScore();
 
        String tag = "";
        Long videoTypeId = getVideoType(series);
        if (videoTypeId == null)
            return null;
        VideoType videoType = new VideoType(videoTypeId);
 
 
        //电影
        if (videoType.getId() == VideoConstant.VIDEO_CATEGORY_DIANYING) {
            tag = "评分:" + score;
        } else if (videoType.getId() == VideoConstant.VIDEO_CATEGORY_DIANSHIJU || videoType.getId() == VideoConstant.VIDEO_CATEGORY_DONGMAN) {
            //电视剧,动漫
            if (series.getCurrentNum() != null && series.getSeriesCount().trim().equalsIgnoreCase(series.getCurrentNum().trim())) {
                tag = series.getSeriesCount() + "集全";
            } else {
                tag = "更新至" + series.getCurrentNum() + "集";
            }
        } else if (videoType.getId() == VideoConstant.VIDEO_CATEGORY_ZONGYI) {
            //综艺
            if (!StringUtil.isNullOrEmpty(series.getCurrentNum())) {
                tag = series.getCurrentNum().replace("期", "");
            } else {
                tag = series.getPublishTime().split(" ")[0];
            }
        } else {
            if ("1".equalsIgnoreCase(series.getSeriesCount())) {
                tag = "评分:" + score;
            } else {
                if (series.getCurrentNum() != null && series.getSeriesCount().trim().equalsIgnoreCase(series.getCurrentNum().trim())) {
                    tag = series.getSeriesCount() + "集全";
                } else {
                    if (series.getCurrentNum() != null)
                        tag = "更新至" + series.getCurrentNum() + "集";
                    else {
                        tag = "更新至" + series.getSeriesCount() + "集";
                    }
                }
            }
        }
 
 
        String latestHpicture = program != null ? program.getSubHorCover() : series.getSeries().get(series.getSeries().size() - 1).getSubHorCover();
 
        long updateTime = System.currentTimeMillis();
 
        VideoInfo vi = new VideoInfo();
        vi.setVideoType(videoType);
        vi.setArea(series.getCountry());
        vi.setBaseurl("");
        vi.setCanSave(false);
        vi.setCommentCount(0);
        vi.setContentType(1);
        vi.setCreatetime(System.currentTimeMillis());
        vi.setDay(day + "");
        vi.setDirector(director);
        vi.setFocus("");
        vi.setHpicture(series.getHorCover());
        vi.setIntroduction(series.getDescription());
        vi.setLatestHpicture(latestHpicture);
        vi.setLatestVpicture("");
        vi.setMainActor(mainActor);
        vi.setMonth(month + "");
        vi.setName(program != null ? program.getProgramSetTiltle() : series.getName());
        vi.setNowNumber(0 + "");
        vi.setOrderby("0");
        vi.setPicture(series.getCover());
        vi.setScore(score);
        vi.setShare("0");
        vi.setShow(1 + "");
        vi.setTag(tag);
        vi.setVpicture(series.getCover());
        vi.setWatchCount(0 + "");
        vi.setYear(year + "");
        vi.setUpdatetime(updateTime + "");
        vi.setVideocount(program != null ? 1 : series.getSeries().size());
        return vi;
    }
 
 
    public static int getPlayType(AcceptData acceptData, PPTVProgram pptvProgram) {
        if (!pptvProgram.getStatus().equalsIgnoreCase("del")) {
            return PLAY_SDK;
        } else {
            return PLAY_NONE;
        }
    }
 
    /**
     * 获取pptv的用户ID
     *
     * @param uid
     * @return
     */
    public static String getPPTVUid(String uid) {
        return "buwan_" + uid;
    }
 
    /**
     * 获取pptvcode
     *
     * @param pptvUid
     * @return
     */
    public static String getPPTVCode(String pptvUid) {
        if (StringUtil.isNullOrEmpty(pptvUid))
            return null;
        return AESUtil.encrypt(pptvUid + "#" + System.currentTimeMillis()).replace("/", "_").replace("=", "-");
    }
 
    public static String getUidFromPPTVUid(String pptvUid) {
        return pptvUid.split("_")[1];
    }
 
 
    /**
     * 解密PPTVCode
     *
     * @param code
     * @return
     */
    public static PPTVCodeInfo decryptPPTVCode(String code) {
        code = code.replace("_", "/").replace("-", "=");
        String info = AESUtil.decrypt(code);
        if (StringUtil.isNullOrEmpty(info)) {
            return null;
        } else {
            String[] sts = info.split("#");
            if (sts.length != 2)
                return null;
            PPTVCodeInfo codeInfo = new PPTVCodeInfo();
            codeInfo.pptvUid = sts[0];
            codeInfo.time = Long.parseLong(sts[1]);
            return codeInfo;
        }
    }
 
 
    /**
     * 获取播放链接
     *
     * @param series
     * @param program
     * @return
     */
    public static String getPlayUrl(PPTVSeries series, PPTVProgram program) {
        return getPlayUrl(series, program.getProgramCode());
    }
 
 
    public static String getPlayUrl(PPTVSeries series, String programCode) {
        boolean isMovie = (series.getProgramType() != null && series.getProgramType().contains("电影")) || (series.getProgramType2() != null && series.getProgramType2().contains("电影"));
        //programtype 电影-3  其他-2
        return String.format("https://acmd.api.pptv.com/2021/bwysdqmovie_thrid_h5.html?cid=%s&vid=%s&programtype=%s", isMovie ? programCode : series.getSeriesCode(), programCode, isMovie ? 3 : 2);
    }
 
 
    public static class PPTVCodeInfo {
        public String pptvUid;
        public long time;
    }
 
    public static Set<String> getAvaiableStates() {
        Set<String> stateSets = new HashSet<>();
        stateSets.add("add");
        stateSets.add("update");
        return stateSets;
    }
 
    public static boolean isVIPVideo(String free) {
        return "1".equalsIgnoreCase((free + "").trim());
    }
 
 
    /**
     * 获取商品购买成功的缓存Key
     *
     * @param uid
     * @param goodsNo
     * @return
     */
    public static String getBuyGoodsCacheKey(String uid, String goodsNo) {
        return String.format("pptvbuygoods-%s-%s", uid, goodsNo);
    }
 
 
    /**
     * 获取虚拟的视频ID
     *
     * @param cid
     * @return
     */
    public static String getVisualVideoId(String cid, String vid) {
        return "pptv-" + cid + "-" + vid;
    }
 
    /**
     * 解析infoId
     *
     * @param videoId
     * @return
     */
    public static String[] parseCidAndVidFromVisualVideoId(String videoId) {
        if (videoId == null)
            return null;
        if (!videoId.contains("pptv-"))
            return null;
        return videoId.replace("pptv-", "").trim().split("-");
    }
 
    public static class VideoConvertResult {
        public VideoInfo videoInfo;
        public String programCode;
 
        public VideoConvertResult(VideoInfo videoInfo, String programCode) {
            this.videoInfo = videoInfo;
            this.programCode = programCode;
        }
    }
 
 
}