admin
2021-09-03 b41a6efe17ba61d150c5a9b7309651cebae54e0d
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
package com.yeshi.buwan.util.video;
 
import com.yeshi.buwan.videos.acFun.AcFunUtil;
import com.yeshi.buwan.dao.VideoInfoDao;
import com.yeshi.buwan.domain.*;
import com.yeshi.buwan.domain.entity.PlayUrl;
import com.yeshi.buwan.videos.funtv.FunTVUtil;
import com.yeshi.buwan.videos.funtv.FunTVUtil2;
import com.yeshi.buwan.videos.hanmi.HanmiUtil;
import com.yeshi.buwan.videos.iqiyi.util.IqiyiUtil;
import com.yeshi.buwan.videos.iqiyi.util.IqiyiUtil2;
import com.yeshi.buwan.videos.mogotv.MogoTVUtil;
import com.yeshi.buwan.service.imp.VideoInfoService;
import com.yeshi.buwan.service.imp.VideoResourceService;
import com.yeshi.buwan.service.imp.juhe.FunTVService;
import com.yeshi.buwan.service.imp.juhe.IqiyiService;
import com.yeshi.buwan.service.imp.juhe.SoHuService;
import com.yeshi.buwan.service.inter.juhe.*;
import com.yeshi.buwan.service.manager.search.SolrShortVideoDataManager;
import com.yeshi.buwan.videos.sohu.SoHuUtil;
import com.yeshi.buwan.videos.tencent.TencentVideoUtil;
import com.yeshi.buwan.util.StringUtil;
import com.yeshi.buwan.util.log.VideoLogFactory;
import com.yeshi.buwan.videos.bilibili.BilibiliUtil;
import com.yeshi.buwan.vo.AcceptData;
import com.yeshi.buwan.videos.youku.YouKuUtil;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.orm.hibernate4.HibernateCallback;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.util.List;
 
@Component
public class VideoDetailUtil {
 
    private final Logger playLogger = LoggerFactory.getLogger("videoPlay");
 
    @Resource
    private IqiyiUtil iqiyiUtil;
 
    @Resource
    private SoHuUtil soHuUtil;
 
    @Resource
    private IqiyiService iqiyiService;
 
    @Resource
    private Iqiyi2Service iqiyi2Service;
 
    @Resource
    private SoHuService soHuService;
 
    @Resource
    private VideoInfoDao videoInfoDao;
 
    @Resource
    private FunTVService funTVService;
 
    @Resource
    private FunTV2Service funTV2Service;
 
    @Resource
    private VideoInfoService videoInfoService;
 
    @Resource
    private YouKuUtil youKuUtil;
 
    @Resource
    private YouKuService youKuService;
 
    @Resource
    private MogoTVUtil mogoTVUtil;
 
    @Resource
    private MogoTVService mogoTVService;
 
    @Resource
    private TencentVideoService tencentVideoService;
 
    @Resource
    private TencentVideoUtil tencentVideoUtil;
 
    @Resource
    private BilibiliVideoService bilibiliVideoService;
 
    @Resource
    private HanmiService hanmiService;
 
    @Resource
    private BilibiliUtil bilibiliUtil;
 
    @SuppressWarnings("unchecked")
//    @Cacheable(value = "homeCache", key = "'getVideoInfo'+'-'+#videoid+'-'+#resourceId+'-'+#cacheMD5")
    public VideoInfo getVideoInfo(String detailSystemId, final String videoid, final String resourceId, final List<Long> reList,
                                  String cacheMD5) {
        playLogger.info(VideoLogFactory.createVideoDetailLog(detailSystemId, videoid, resourceId));
        return (VideoInfo) videoInfoDao.excute(new HibernateCallback<VideoInfo>() {
            public VideoInfo doInHibernate(Session session) throws HibernateException {
 
                VideoInfo video = null;
                VideoResource resource = null;
                try {
                    if (!StringUtil.isNullOrEmpty(resourceId)) {
 
                        // 来源限制判断
                        boolean isCan = false;
                        for (long re : reList)
                            if (resourceId.equalsIgnoreCase(re + "")) {
                                isCan = true;
                            }
                        if (!isCan)
                            return null;
 
                        List<ResourceVideo> list = session
                                .createQuery("FROM ResourceVideo rv where rv.video.id=? and rv.resource.id=?")
                                .setParameter(0, videoid).setParameter(1, resourceId).list();
                        if (list != null && list.size() > 0) {
                            ResourceVideo rv = list.get(0);
                            List<VideoResource> resourceList = session
                                    .createQuery("select rv.resource from ResourceVideo rv where rv.video.id=?")
                                    .setParameter(0, videoid).list();
 
                            rv.getVideo().setVideoDetailList(getVideoDetailList(videoid, rv.getResource(), 1, 100));
                            for (VideoResource r : resourceList) {
                                if (r.getId().equalsIgnoreCase(rv.getResource().getId())) {
                                    r.setChecked(true);
                                }
                            }
                            rv.getVideo().setResourceList(resourceList);
                            video = rv.getVideo();
 
                            resource = rv.getResource();
                        }
                    } else {
                        List<ResourceVideo> list = session
                                .createQuery(
                                        "FROM ResourceVideo rv where rv.video.id=? order by rv.resource.orderby desc")
                                .setParameter(0, videoid).list();
                        // 来源筛查
 
                        if (list != null)
                            for (int i = 0; i < list.size(); i++) {
                                boolean isC = false;
                                for (Long id : reList) {
                                    if ((id + "").equalsIgnoreCase(list.get(i).getResource().getId())) {
                                        isC = true;
                                        break;
                                    }
                                }
                                if (!isC) {
                                    list.remove(i);
                                    i--;
                                }
                            }
 
                        if (list != null && list.size() > 0) {
                            ResourceVideo rv = list.get(0);
                            List<VideoResource> resourceList = session
                                    .createQuery(
                                            "select rv.resource from ResourceVideo rv where rv.video.id=? order by rv.resource.id desc")
                                    .setParameter(0, videoid).list();
 
                            rv.getVideo().setVideoDetailList(getVideoDetailList(videoid, rv.getResource(), 1, 100));
 
                            for (int i = 0; i < resourceList.size(); i++) {
                                VideoResource r = resourceList.get(i);
                                if (r.getId().equalsIgnoreCase(rv.getResource().getId())) {
                                    r.setChecked(true);
                                }
                                boolean isS = false;
                                for (Long id : reList) {
                                    if ((id + "").equalsIgnoreCase(r.getId())) {
                                        isS = true;
                                        break;
                                    }
                                }
                                // 不在允许的resource里面
                                if (!isS) {
                                    resourceList.remove(i);
                                    i--;
                                }
 
                            }
                            rv.getVideo().setResourceList(resourceList);
                            video = rv.getVideo();
                            resource = rv.getResource();
                        }
                    }
 
                } catch (Exception e) {
                    e.printStackTrace();
                }
 
                try {
                    if (video.getVideoDetailList() != null && video.getVideoDetailList().size() == 1) {
                        video.getVideoDetailList().get(0).setName(video.getName());
                        video.getVideoDetailList().get(0).setTag(video.getName());
                    }
 
                    if (video != null && resource != null) {
                        video.setShowType(getShowType(video.getId(), resource));
                    }
                } catch (Exception e) {
 
                }
                return video;
            }
        });
    }
 
    public List<VideoDetailInfo> getVideoDetailList(String videoid, VideoResource vr, int page, int pageSize) {
        int resourceId = Integer.parseInt(vr.getId());
        switch (resourceId) {
            case IqiyiUtil2.RESOURCE_ID:
                return iqiyi2Service.getVideoDetailList(videoid, page, pageSize);
            case IqiyiUtil.RESOURCE_ID:
                return iqiyiService.getVideoDetailList(videoid, page, pageSize);
            case FunTVUtil2.RESOURCE_ID:
                return funTV2Service.getVideoDetailList(videoid, page, pageSize);
            case FunTVUtil.RESOURCE_ID:
                return funTVService.getVideoDetailList(videoid, page, pageSize);
            case AcFunUtil.RESOURCE_ID:
                return videoInfoService.getVideoDetailList(videoid, vr, page, pageSize);
            case SoHuUtil.RESOURCE_ID:
                return soHuService.getVideoDetailList(videoid, page, pageSize);
            case YouKuUtil.RESOURCE_ID:
                return youKuService.getVideoDetailList(videoid, page, pageSize);
            case MogoTVUtil.RESOURCE_ID:
                return mogoTVService.getVideoDetailList(videoid, page, pageSize);
            case TencentVideoUtil.RESOURCE_ID:
                return tencentVideoService.getVideoDetailList(videoid, page, pageSize);
            case BilibiliUtil.RESOURCE_ID:
                return bilibiliVideoService.getVideoDetailList(videoid, page, pageSize);
            case HanmiUtil.RESOURCE_ID:
                return hanmiService.getVideoDetailList(videoid, page, pageSize);
            default:
                return null;
        }
    }
 
    public VideoDetailInfo getLatestVideoDetail(String videoid, VideoResource vr) {
 
        int resourceId = Integer.parseInt(vr.getId());
        switch (resourceId) {
            case IqiyiUtil2.RESOURCE_ID:
                return iqiyi2Service.getLatestVideoDetail(videoid);
            case IqiyiUtil.RESOURCE_ID:
                return iqiyiService.getLatestVideoDetail(videoid);
            case FunTVUtil2.RESOURCE_ID:
                return funTV2Service.getLatestVideoDetail(videoid);
            case FunTVUtil.RESOURCE_ID:
                return funTVService.getLatestVideoDetail(videoid);
            case SoHuUtil.RESOURCE_ID:
                return soHuService.getLatestVideoDetail(videoid);
            case YouKuUtil.RESOURCE_ID:
                return soHuService.getLatestVideoDetail(videoid);
            case MogoTVUtil.RESOURCE_ID:
                return soHuService.getLatestVideoDetail(videoid);
            case HanmiUtil.RESOURCE_ID:
                return hanmiService.getLatestVideoDetail(videoid);
            default:
                return null;
        }
    }
 
    public int getShowType(String videoid, VideoResource vr) {
        int resourceId = Integer.parseInt(vr.getId());
        switch (resourceId) {
            case IqiyiUtil2.RESOURCE_ID:
                return iqiyi2Service.getShowType(videoid);
            case IqiyiUtil.RESOURCE_ID:
                return iqiyiUtil.getShowType(videoid);
            case FunTVUtil2.RESOURCE_ID:
                return funTV2Service.getShowType(videoid);
            case FunTVUtil.RESOURCE_ID:
                return funTVService.getShowType(videoid);
            case SoHuUtil.RESOURCE_ID:
                return soHuUtil.getShowType(videoid);
            case YouKuUtil.RESOURCE_ID:
                return soHuUtil.getShowType(videoid);
            case HanmiUtil.RESOURCE_ID:
                return hanmiService.getShowType(videoid);
            default:
                return 1;
        }
    }
 
    @Resource
    private SolrShortVideoDataManager solrShortVideoDataManager;
 
    @Resource
    private VideoResourceService videoResourceService;
 
 
    @Cacheable(value = "homeCache", key = "'getPlayUrl'+'-'+#detailSystemId+'-'+#id+'-'+#type+'-'+#resourceid")
    public PlayUrl getPlayUrl(AcceptData acceptData, String detailSystemId, String id, String type, int resourceid, String videoid) {
        playLogger.info(VideoLogFactory.createPlayUrlLog(detailSystemId, id, type, resourceid, videoid));
        if (VideoUtil.getVideoFromType(id) == HomeVideo.FROM_TYPE_SHORT) {
            VideoResource vr = videoResourceService.getResource(resourceid + "");
            return solrShortVideoDataManager.getPlayUrl(id, vr);
        }
 
        switch (resourceid) {
            case IqiyiUtil2.RESOURCE_ID:
                return iqiyi2Service.getPlayUrl(detailSystemId, resourceid, id, videoid);
            case IqiyiUtil.RESOURCE_ID:
                return iqiyiUtil.getPlayUrl(detailSystemId, resourceid + "", type, id);
            case FunTVUtil2.RESOURCE_ID:
                return funTV2Service.getPlayUrl(acceptData, detailSystemId, resourceid, id, videoid);
            case FunTVUtil.RESOURCE_ID:
                return funTVService.getPlayUrl(detailSystemId, id, type, resourceid, videoid);
            case SoHuUtil.RESOURCE_ID:
                return soHuUtil.getPlayUrl(detailSystemId, resourceid + "", type, id);
            case AcFunUtil.RESOURCE_ID:
                return videoInfoService.getPlayUrl(detailSystemId, id, type, resourceid, videoid);
            case YouKuUtil.RESOURCE_ID:
                return youKuUtil.getPlayUrl(detailSystemId, id, type, resourceid, videoid);
            case MogoTVUtil.RESOURCE_ID:
                return mogoTVUtil.getPlayUrl(detailSystemId, id, type, resourceid, videoid);
            case TencentVideoUtil.RESOURCE_ID:
                return tencentVideoUtil.getPlayUrl(detailSystemId, id, type, resourceid, videoid);
            case BilibiliUtil.RESOURCE_ID:
                return bilibiliUtil.getPlayUrl(detailSystemId, id, type, resourceid, videoid);
            case HanmiUtil.RESOURCE_ID:
                return hanmiService.getPlayUrl(detailSystemId, resourceid, id, videoid);
            default:
                return null;
        }
    }
 
}