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("找不到该视频"));
|
}
|
|
}
|
|
}
|