admin
2021-09-24 f788607ff771a47bc60d6a86e00b3433c40f3d2c
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
package com.yeshi.buwan.controller.parser.web;
 
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
 
import com.yeshi.buwan.exception.video.VideoPlayException;
import org.springframework.stereotype.Controller;
 
import com.yeshi.buwan.domain.CategoryContry;
import com.yeshi.buwan.domain.system.DetailSystem;
import com.yeshi.buwan.domain.VideoDetailInfo;
import com.yeshi.buwan.domain.VideoInfo;
import com.yeshi.buwan.domain.VideoType;
import com.yeshi.buwan.domain.entity.PlayUrl;
import com.yeshi.buwan.service.imp.AttentionService;
import com.yeshi.buwan.service.imp.CategoryAreaService;
import com.yeshi.buwan.service.imp.ClassService;
import com.yeshi.buwan.service.imp.CommentService;
import com.yeshi.buwan.service.imp.RecommendService;
import com.yeshi.buwan.service.imp.SystemService;
import com.yeshi.buwan.util.CacheUtil;
import com.yeshi.buwan.util.JsonUtil;
import com.yeshi.buwan.util.StringUtil;
import com.yeshi.buwan.util.TimeUtil;
import com.yeshi.buwan.util.Utils;
import com.yeshi.buwan.util.VideoPictureUtil;
import com.yeshi.buwan.util.JuHe.VideoResourceUtil;
import com.yeshi.buwan.util.video.VideoDetailUtil;
 
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
 
@Controller
public class WebVideosParser {
 
    @Resource
    private SystemService systemService;
 
    @Resource
    private VideoResourceUtil videoResouceUtil;
 
    @Resource
    private ClassService classService;
 
    @Resource
    private CategoryAreaService categoryAreaService;
 
    @Resource
    private VideoDetailUtil videoDeailUtil;
 
    @Resource
    private CommentService commentService;
 
    @Resource
    private AttentionService attentionService;
 
    @Resource
    private RecommendService recommendService;
 
    // 获取视频列表
    public void getVideoList(String uid, HttpServletRequest request, PrintWriter out) {
        String method = request.getParameter("Method");
        String system = request.getParameter("System");
        String sign = request.getParameter("Sign");
        String platform = request.getParameter("Platform");
        String packageName = request.getParameter("Package");
        String pid = request.getParameter("Pid");
        String cid = request.getParameter("Cid");
        String order = request.getParameter("Order");
        String type = request.getParameter("CategoryType");
        String pageIndex = request.getParameter("Page");
 
        if (StringUtil.isNullOrEmpty(method)) {
            out.print(JsonUtil.loadFalseJson("请上传Method"));
            return;
        }
        if (StringUtil.isNullOrEmpty(uid)) {
            out.print(JsonUtil.loadFalseJson("请上传Uid"));
            return;
        }
        if (StringUtil.isNullOrEmpty(system)) {
            out.print(JsonUtil.loadFalseJson("请上传System"));
            return;
        }
        if (StringUtil.isNullOrEmpty(sign)) {
            out.print(JsonUtil.loadFalseJson("请上传Sign"));
            return;
        }
        if (StringUtil.isNullOrEmpty(platform)) {
            out.print(JsonUtil.loadFalseJson("请上传Platform"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(packageName)) {
            out.print(JsonUtil.loadFalseJson("请上传Package"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(pid)) {
            out.print(JsonUtil.loadFalseJson("请上传Platform"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(cid)) {
            out.print(JsonUtil.loadFalseJson("请上传Platform"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(order)) {
            out.print(JsonUtil.loadFalseJson("请上传Order"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(type)) {
            out.print(JsonUtil.loadFalseJson("请上传Type"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(pageIndex)) {
            out.print(JsonUtil.loadFalseJson("请上传Page"));
            return;
        }
 
        JSONObject object = new JSONObject();
 
        DetailSystem detailSystem = systemService.getDetailSystemByPackage(packageName);
        List<Long> resourceList = videoResouceUtil.getAvailableResourceIds(detailSystem, 1,null);
        // 获取视频列表
        List<VideoInfo> list1;
        if (type.equalsIgnoreCase("area")) {
            CategoryContry cc = categoryAreaService.getCategoryArea(cid);
            String country = cc.getName();
            long typeid = cc.getParent().getCid();
            if (StringUtil.isNullOrEmpty(order))
                order = 1 + "";
            list1 = categoryAreaService.getVideoInfoByArea(typeid + "", detailSystem, Integer.parseInt(pageIndex), 20,
                    Integer.parseInt(order), resourceList, country, StringUtil.Md5(typeid + "-" + detailSystem + "-"
                            + pageIndex + "-" + order + "-" + country + "-" + CacheUtil.getMD5Long(resourceList)));
        } else {
            list1 = classService.getTypeVideoList(StringUtil.isNullOrEmpty(cid) ? pid : cid, detailSystem,
                    Integer.parseInt(pageIndex), 20, Integer.parseInt(order), resourceList,
                    CacheUtil.getMD5Long(resourceList));
        }
 
        List<VideoInfo> list = new ArrayList<>();
        list.addAll(list1);
        JSONArray array = new JSONArray();
        for (VideoInfo info : list)
            array.add(StringUtil.outPutResultJson(info));
        object.put("data", array);
        object.put("count", 1000);
        out.print(JsonUtil.loadTrueJsonNoencript(object.toString()));
    }
 
    // 获取视频列表
    public void getVideoDetail(String uid, HttpServletRequest request, PrintWriter out) {
        String method = request.getParameter("Method");
        String system = request.getParameter("System");
        String sign = request.getParameter("Sign");
        String platform = request.getParameter("Platform");
        String packageName = request.getParameter("Package");
        String videoId = request.getParameter("VideoId");
        String loginUid = request.getParameter("LoginUid");
        String resourceId = request.getParameter("ResourceId");
 
        if (StringUtil.isNullOrEmpty(method)) {
            out.print(JsonUtil.loadFalseJson("请上传Method"));
            return;
        }
        if (StringUtil.isNullOrEmpty(uid)) {
            out.print(JsonUtil.loadFalseJson("请上传Uid"));
            return;
        }
        if (StringUtil.isNullOrEmpty(system)) {
            out.print(JsonUtil.loadFalseJson("请上传System"));
            return;
        }
        if (StringUtil.isNullOrEmpty(sign)) {
            out.print(JsonUtil.loadFalseJson("请上传Sign"));
            return;
        }
        if (StringUtil.isNullOrEmpty(platform)) {
            out.print(JsonUtil.loadFalseJson("请上传Platform"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(packageName)) {
            out.print(JsonUtil.loadFalseJson("请上传Package"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(videoId)) {
            out.print(JsonUtil.loadFalseJson("请上传VideoId"));
            return;
        }
 
        List<Long> resourceList = videoResouceUtil.getAvailableResourceIds(new DetailSystem("44"), 1,null);
 
        VideoInfo info = (videoDeailUtil.getVideoInfo(null, videoId, resourceId, resourceList,
                CacheUtil.getMD5Long(resourceList)));
        if (info == null)
            return;
 
        List<VideoType> typeList = classService.getVideoTypeList(info.getId());
        if (typeList != null && typeList.size() > 0) {
            VideoType type = typeList.get(0);
            while (type.getParent() != null)
                type = type.getParent();
            info.setVideoType(type);
        }
 
        info.setPlayPicture(VideoPictureUtil.getShowPicture(info, platform, 0 + ""));
 
        for (VideoDetailInfo vd : info.getVideoDetailList()) {
            if (StringUtil.isNullOrEmpty(vd.getExtraId()))
                vd.setExtraId(vd.getId() + "");
        }
        System.out.println(info.getPlayPicture());
 
        // 过滤版权视频关键字
        long count = commentService.getComment2ListCount(videoId, 0 + "");
        if (info != null)
            info.setCommentCount((int) count);
 
        JSONObject obj = new JSONObject();
        if (info.getVideoDetailList().size() > 1) {// 多集,可关注
            boolean isAttention = false;
            if (!StringUtil.isNullOrEmpty(loginUid)) {
                isAttention = attentionService.isAddAttention(loginUid, info.getId());
            }
            JSONObject attentionInfo = new JSONObject();
            attentionInfo.put("Name", info.getName());
            attentionInfo.put("Picture", info.getPicture());
            attentionInfo.put("UpdateInfo", "更新:" + TimeUtil.getCommentTime(Long.parseLong(info.getUpdatetime())));
            attentionInfo.put("IsAttention", isAttention);
            obj.put("Attention", attentionInfo);
        }
 
        out.print(JsonUtil.loadTrueJsonWithNoEncry(StringUtil.outPutResultJson(Utils.convertVideo(info)), "",
                obj.toString()));
 
    }
 
    // 获取视频列表
    public void getRecommendVideos(String uid, HttpServletRequest request, PrintWriter out) {
        String method = request.getParameter("Method");
        String system = request.getParameter("System");
        String sign = request.getParameter("Sign");
        String platform = request.getParameter("Platform");
        String packageName = request.getParameter("Package");
        String videoId = request.getParameter("VideoId");
 
        if (StringUtil.isNullOrEmpty(method)) {
            out.print(JsonUtil.loadFalseJson("请上传Method"));
            return;
        }
        if (StringUtil.isNullOrEmpty(uid)) {
            out.print(JsonUtil.loadFalseJson("请上传Uid"));
            return;
        }
        if (StringUtil.isNullOrEmpty(system)) {
            out.print(JsonUtil.loadFalseJson("请上传System"));
            return;
        }
        if (StringUtil.isNullOrEmpty(sign)) {
            out.print(JsonUtil.loadFalseJson("请上传Sign"));
            return;
        }
        if (StringUtil.isNullOrEmpty(platform)) {
            out.print(JsonUtil.loadFalseJson("请上传Platform"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(packageName)) {
            out.print(JsonUtil.loadFalseJson("请上传Package"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(videoId)) {
            out.print(JsonUtil.loadFalseJson("请上传VideoId"));
            return;
        }
 
        List<Long> resourceList = videoResouceUtil.getAvailableResourceIds(new DetailSystem("44"), 1,null);
 
        DetailSystem ds = systemService.getDetailSystemByPackage(packageName);
        // 猜你喜欢
        List<VideoInfo> list1 = StringUtil.isNullOrEmpty(videoId)
                ? recommendService.guessLikeList(ds.getId(), 10, resourceList, CacheUtil.getMD5Long(resourceList))
                : recommendService.guessLikeList(ds.getId(), 10, videoId, resourceList,
                CacheUtil.getMD5Long(resourceList));
        List<VideoInfo> list = new ArrayList<>();
        list.addAll(list1);
 
        // 相关视频
        List<VideoInfo> list2 = recommendService.getRelativeVideoList(ds.getId(), 10, videoId, resourceList,
                CacheUtil.getMD5Long(resourceList));
        List<VideoInfo> xlist = new ArrayList<>();
        xlist.addAll(list2);
 
        // 大家都在看
        List<VideoInfo> list3 = recommendService.peopleSee(ds.getId(), 10, videoId, resourceList,
                CacheUtil.getMD5Long(resourceList));
        List<VideoInfo> plist = new ArrayList<>();
        plist.addAll(list3);
        JSONArray garray = new JSONArray();
        JSONArray xarray = new JSONArray();
        JSONArray parray = new JSONArray();
        for (VideoInfo v : list) {
            v.setIntroduction("");
            v.setPicture(VideoPictureUtil.getShowPicture(v, platform, "0"));
            garray.add(StringUtil.outPutResultJson(v));
        }
 
        for (VideoInfo v : xlist) {
            v.setIntroduction("");
            v.setPicture(VideoPictureUtil.getShowPicture(v, platform, "0"));
            xarray.add(StringUtil.outPutResultJson(v));
        }
 
        for (VideoInfo v : plist) {
            v.setIntroduction("");
            v.setPicture(VideoPictureUtil.getShowPicture(v, platform, "0"));
            parray.add(StringUtil.outPutResultJson(v));
        }
        JSONObject data = new JSONObject();
        data.put("guesslike", garray);
        data.put("relative", xarray);
        data.put("peoplesee", parray);
        out.print(JsonUtil.loadTrueJsonNoencript(data.toString()));
    }
 
    // 获取视频列表
    public void getPlayUrl(String uid, HttpServletRequest request, PrintWriter out) {
        String method = request.getParameter("Method");
        String system = request.getParameter("System");
        String sign = request.getParameter("Sign");
        String platform = request.getParameter("Platform");
        String packageName = request.getParameter("Package");
        String resourceId = request.getParameter("ResourceId");
        String id = request.getParameter("Id");
        String type = request.getParameter("Type");
        String videoId = request.getParameter("VideoId");
 
        if (StringUtil.isNullOrEmpty(method)) {
            out.print(JsonUtil.loadFalseJson("请上传Method"));
            return;
        }
        if (StringUtil.isNullOrEmpty(uid)) {
            out.print(JsonUtil.loadFalseJson("请上传Uid"));
            return;
        }
        if (StringUtil.isNullOrEmpty(system)) {
            out.print(JsonUtil.loadFalseJson("请上传System"));
            return;
        }
        if (StringUtil.isNullOrEmpty(sign)) {
            out.print(JsonUtil.loadFalseJson("请上传Sign"));
            return;
        }
        if (StringUtil.isNullOrEmpty(platform)) {
            out.print(JsonUtil.loadFalseJson("请上传Platform"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(packageName)) {
            out.print(JsonUtil.loadFalseJson("请上传Package"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(videoId)) {
            out.print(JsonUtil.loadFalseJson("请上传VideoId"));
            return;
        }
 
        DetailSystem detailSystem = systemService.getDetailSystemByPackage(packageName);
 
        PlayUrl pu = null;
        try {
            pu = videoDeailUtil.getPlayUrl(null, detailSystem.getId(), id, type, Integer.parseInt(resourceId), videoId);
        } catch (VideoPlayException e) {
            e.printStackTrace();
        }
 
        if (pu != null) {
            if (!StringUtil.isNullOrEmpty(pu.getUrl()))
                pu.setUrl(pu.getUrl());
            JSONObject object = JSONObject.fromObject(StringUtil.outPutResultJson(pu));
            out.print(JsonUtil.loadTrueJsonNoencript(object.toString()));
        } else {
            out.print(JsonUtil.loadFalseJsonNoencript("找不到该视频"));
        }
 
    }
 
}