From a66b556036c2b3936a51fd7b7e54a204eb31dc14 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期五, 30 七月 2021 19:13:14 +0800
Subject: [PATCH] 短视频爬虫,短视频搜索

---
 src/main/java/com/yeshi/buwan/controller/admin/api/VideoAdminController.java |  131 +++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 123 insertions(+), 8 deletions(-)

diff --git a/src/main/java/com/yeshi/buwan/controller/admin/api/VideoAdminController.java b/src/main/java/com/yeshi/buwan/controller/admin/api/VideoAdminController.java
index 5ccdcbb..184405a 100644
--- a/src/main/java/com/yeshi/buwan/controller/admin/api/VideoAdminController.java
+++ b/src/main/java/com/yeshi/buwan/controller/admin/api/VideoAdminController.java
@@ -2,16 +2,24 @@
 
 import java.io.PrintWriter;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import javax.annotation.Resource;
 
+import com.google.common.base.Function;
+import com.google.common.collect.Maps;
 import com.google.gson.Gson;
-import com.yeshi.buwan.domain.SolrVideo;
+import com.yeshi.buwan.domain.VideoResource;
+import com.yeshi.buwan.domain.solr.SolrAlbumVideo;
+import com.yeshi.buwan.domain.video.VideoInfoExtra;
 import com.yeshi.buwan.dto.search.SolrResultDTO;
 import com.yeshi.buwan.dto.search.SolrVideoSearchFilter;
 import com.yeshi.buwan.iqiyi.IqiYiNewAPI;
-import com.yeshi.buwan.service.manager.SolrAlbumDataManager;
+import com.yeshi.buwan.service.imp.VideoResourceService;
+import com.yeshi.buwan.service.inter.video.VideoInfoExtraService;
+import com.yeshi.buwan.service.manager.search.SolrAlbumVideoDataManager;
 import com.yeshi.buwan.util.Constant;
 import com.yeshi.buwan.vo.video.VideoAdminInfoVO;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
@@ -28,7 +36,6 @@
 import com.yeshi.buwan.service.imp.VideoManager;
 import com.yeshi.buwan.util.JsonUtil;
 import com.yeshi.buwan.util.StringUtil;
-import com.yeshi.buwan.util.TimeUtil;
 import com.yeshi.buwan.web.tag.PageEntity;
 
 import net.sf.json.JSONArray;
@@ -48,6 +55,9 @@
     private ResourceVideoService resourceVideoService;
 
     @Resource
+    private VideoResourceService videoResourceService;
+
+    @Resource
     private IqiyiUtil iqiyiUtil;
 
     @Resource
@@ -57,7 +67,10 @@
     private ThreadPoolTaskExecutor taskExecutor;
 
     @Resource
-    private SolrAlbumDataManager solrAlbumDataManager;
+    private SolrAlbumVideoDataManager solrAlbumDataManager;
+
+    @Resource
+    private VideoInfoExtraService videoInfoExtraService;
 
     @RequestMapping(value = "/changevideoshow", method = RequestMethod.POST)
     public void changeVideoShow(String id, int show, PrintWriter out) {
@@ -85,7 +98,17 @@
     }
 
     @RequestMapping(value = "/videolist", method = RequestMethod.POST)
-    public void videoList(int videotype, int page, String key, String resourceIds, int contenttype, PrintWriter out) {
+    public void videoList(int videotype, int page, String key, String type, String resourceIds, int contenttype, String freeType, String area, PrintWriter out) {
+
+        if (StringUtil.isNullOrEmpty(type)) {
+            type = "name";
+        }
+
+        Integer freeTypeInt = null;
+        if (!StringUtil.isNullOrEmpty(freeType)) {
+            freeTypeInt = Integer.parseInt(freeType);
+        }
+
 
         List<VideoInfo> list = null;
         long count = 0;
@@ -93,7 +116,20 @@
         //姝g墖鎼滅储
         if (contenttype == 1) {
             SolrVideoSearchFilter filter = new SolrVideoSearchFilter();
-            filter.setKey(key);
+
+            switch (type) {
+                case "name":
+                    filter.setKey(key);
+                    break;
+                case "actor":
+                    filter.setActor(key);
+                    break;
+                case "director":
+                    filter.setDirector(key);
+                    break;
+            }
+
+
             filter.setVideoType(videotype == 0 ? null : videotype);
             filter.setContentType(1);
             if (!StringUtil.isNullOrEmpty(resourceIds)) {
@@ -107,10 +143,20 @@
 
             filter.setSortKey("updateTime");
 
+            filter.setFreeType(freeTypeInt);
+
+            filter.setArea(StringUtil.isNullOrEmpty(area) ? null : area.trim());
+
+            List<VideoResource> resourceList = videoResourceService.getResourceList();
+            Map<Long, String> resourceMap = new HashMap<>();
+            for (VideoResource vr : resourceList) {
+                resourceMap.put(Long.parseLong(vr.getId()), vr.getName());
+            }
+
             SolrResultDTO dto = solrAlbumDataManager.find(filter, page, Constant.pageCount);
             if (dto.getVideoList() != null)
-                for (SolrVideo videoInfo : dto.getVideoList())
-                    voList.add(VideoAdminInfoVO.create(videoInfo));
+                for (SolrAlbumVideo videoInfo : (List<SolrAlbumVideo>) dto.getVideoList())
+                    voList.add(VideoAdminInfoVO.create(videoInfo,resourceMap));
             count = dto.getTotalCount();
         } else {
             list = classService.getTypeVideoListAdmin(videotype == 0 ? "" : videotype + "", page, key,
@@ -120,6 +166,38 @@
                 for (VideoInfo videoInfo : list)
                     voList.add(VideoAdminInfoVO.create(videoInfo));
         }
+
+        List<String> ids = new ArrayList<>();
+        for (VideoAdminInfoVO a : voList) {
+            ids.add(a.getId());
+        }
+
+        List<VideoInfoExtra> extraList = videoInfoExtraService.listByIds(ids);
+
+        Map<String, VideoInfoExtra> maps = Maps.uniqueIndex(extraList.iterator(), new Function<VideoInfoExtra, String>() {
+            @Override
+            public String apply(VideoInfoExtra extra) {
+                return extra.getId();
+            }
+        });
+        //杩囨护鍥剧墖
+        for (VideoAdminInfoVO a : voList) {
+            VideoInfoExtra extra = maps.get(a.getId());
+            if (extra != null) {
+
+                if (a.getHpicture() != null) {
+                    if (!StringUtil.isNullOrEmpty(extra.gethPosterPicture()))
+                        a.setHpicture(extra.gethPosterPicture());
+                }
+
+                if (a.getVpicture() != null) {
+                    if (!StringUtil.isNullOrEmpty(extra.getvPosterPicture()))
+                        a.setVpicture(extra.getvPosterPicture());
+                }
+            }
+        }
+
+
         JSONObject object = new JSONObject();
         object.put("code", 0);
         JSONObject data = new JSONObject();
@@ -188,5 +266,42 @@
         out.print(data);
     }
 
+    @RequestMapping("getVideoInfoExtra")
+    public void getVideoInfoExtra(String id, PrintWriter out) {
+        VideoInfoExtra extra = videoInfoExtraService.getById(id);
+        JSONObject object = new JSONObject();
+        if (extra != null) {
+            object.put("code", 0);
+            object.put("data", new Gson().toJson(extra));
+        } else {
+            object.put("code", 1);
+            object.put("msg", "鏃犻檮鍔犱俊鎭�");
+        }
+        out.print(object);
+    }
+
+    @RequestMapping("updateVideoInfoExtra")
+    public void updateVideoInfoExtra(String id, String vPicture, String hPicture, PrintWriter out) {
+        VideoInfoExtra extra = new VideoInfoExtra();
+        extra.setId(id);
+        if (StringUtil.isNullOrEmpty(vPicture)) {
+            vPicture = "";
+        }
+
+        extra.setvPosterPicture(vPicture);
+
+        if (StringUtil.isNullOrEmpty(hPicture)) {
+            hPicture = "";
+        }
+
+        extra.sethPosterPicture(hPicture);
+
+        videoInfoExtraService.save(extra);
+
+        JSONObject object = new JSONObject();
+        object.put("code", 0);
+        out.print(object);
+    }
+
 
 }

--
Gitblit v1.8.0