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/parser/HomeParser.java |   38 ++++++++++++++++++++++++++++----------
 1 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/src/main/java/com/yeshi/buwan/controller/parser/HomeParser.java b/src/main/java/com/yeshi/buwan/controller/parser/HomeParser.java
index efa472e..1c443a9 100644
--- a/src/main/java/com/yeshi/buwan/controller/parser/HomeParser.java
+++ b/src/main/java/com/yeshi/buwan/controller/parser/HomeParser.java
@@ -41,6 +41,7 @@
 import com.yeshi.buwan.util.log.LoggerUtil;
 import com.yeshi.buwan.util.log.UserActiveLogFactory;
 import com.yeshi.buwan.util.log.VideoLogFactory;
+import com.yeshi.buwan.videos.bilibili.BilibiliUtil;
 import com.yeshi.buwan.vo.AcceptData;
 import com.yeshi.buwan.vo.video.VideoDetailVO;
 import com.yeshi.buwan.youku.YouKuUtil;
@@ -199,7 +200,7 @@
         DetailSystem detailSystem = systemService.getDetailSystemByPackage(acceptData.getPackageName());
         JSONObject object = new JSONObject();
 
-        List<Long> resourceList = videoResouceUtil.getAvailableResourceIds(acceptData.getDetailSystem(), acceptData.getVersion());
+        List<Long> resourceList = videoResouceUtil.getAvailableResourceIds(acceptData.getDetailSystem(), acceptData.getVersion(),acceptData.getChannel());
         List<HomeType> list1 = homeTypeService.getHomeType(detailSystem.getId(), acceptData.getPlatform(), acceptData.getVersion(), resourceList,
                 CacheUtil.getMD5Long(resourceList), -1, special != null ? special.getDataKey() : null);
         List<HomeType> list = new ArrayList<>();
@@ -306,7 +307,7 @@
 
         long count = homeTypeService.countHomeType(acceptData.getDetailSystem().getId(), acceptData.getVersion(), dataKey);
 
-        List<Long> resourceList = videoResouceUtil.getAvailableResourceIds(acceptData.getDetailSystem(), acceptData.getVersion());
+        List<Long> resourceList = videoResouceUtil.getAvailableResourceIds(acceptData.getDetailSystem(), acceptData.getVersion(),acceptData.getChannel());
         List<HomeType> homeTypeList = homeTypeService.getHomeTypeList(acceptData.getDetailSystem().getId(), acceptData.getVersion(), dataKey, Integer.parseInt(page), Integer.parseInt(pageSize));
 
         if (homeTypeList != null)
@@ -329,7 +330,7 @@
                 homeType.setCount((int) videoCount);
                 List<HomeVideo> tempHomeVideoList = new ArrayList<>();
                 tempHomeVideoList.addAll(homeVideoList);
-                while (tempHomeVideoList != null && (tempHomeVideoList.size() - bigPictureCount) % homeType.getColumns() != 0)
+                while (tempHomeVideoList != null && tempHomeVideoList.size() > 0 && (tempHomeVideoList.size() - bigPictureCount) % homeType.getColumns() != 0)
                     tempHomeVideoList.remove(tempHomeVideoList.size() - 1);
 
                 homeType.setHomeVideoList(tempHomeVideoList);
@@ -397,7 +398,7 @@
             return;
         }
 
-        List<Long> resourceList = videoResouceUtil.getAvailableResourceIds(acceptData.getDetailSystem(), acceptData.getVersion());
+        List<Long> resourceList = videoResouceUtil.getAvailableResourceIds(acceptData.getDetailSystem(), acceptData.getVersion(),acceptData.getChannel());
         //鏌ヨ澶у浘
         List<HomeVideo> bigPictureVideos = new ArrayList<>();
 
@@ -522,6 +523,9 @@
     private TencentVideoUtil tencentVideoUtil;
 
     @Resource
+    private BilibiliUtil bilibiliUtil;
+
+    @Resource
     private VideoPlayStatisticManager videoPlayStatisticManager;
 
 
@@ -584,6 +588,14 @@
         } else if (Integer.parseInt(resourceId) == TencentVideoUtil.RESOURCE_ID) {
             try {
                 info = tencentVideoUtil.getVideoInfo(internetSearchVideo, pageSize);
+            } catch (Exception e) {
+                logger.error("鍏ㄧ綉鎼滆棰戣鎯呭嚭閿欙細" + videoId);
+                out.print(JsonUtil.loadFalseAdmin(e.getMessage()));
+                return;
+            }
+        } else if (Integer.parseInt(resourceId) == BilibiliUtil.RESOURCE_ID) {
+            try {
+                info = bilibiliUtil.getVideoInfo(internetSearchVideo, pageSize);
             } catch (Exception e) {
                 logger.error("鍏ㄧ綉鎼滆棰戣鎯呭嚭閿欙細" + videoId);
                 out.print(JsonUtil.loadFalseAdmin(e.getMessage()));
@@ -660,7 +672,7 @@
 
         DetailSystem detailSystem = systemService.getDetailSystemByPackage(acceptData.getPackageName());
 
-        List<Long> resourceList = videoResouceUtil.getAvailableResourceIds(acceptData.getDetailSystem(), acceptData.getVersion());
+        List<Long> resourceList = videoResouceUtil.getAvailableResourceIds(acceptData.getDetailSystem(), acceptData.getVersion(),acceptData.getChannel());
 
         //鑾峰彇浼樺厛灞曠ず鐨勬笭閬�
         if (StringUtil.isNullOrEmpty(resourceId)) {
@@ -735,10 +747,8 @@
             ThreadUtil.run(new Runnable() {
                 @Override
                 public void run() {
-                    //姣忓ぉ灞曠ず涓�娆″箍鍛�
-                    long showTime = TimeUtil.convertGernalTime(TimeUtil.getGernalTime(System.currentTimeMillis() + 1000 * 60 * 60 * 24L, "yyyy-MM-dd"), "yyyy-MM-dd");
-
-                    deviceAdStrategyService.setVideoDetailAdStrategy(acceptData.getUtdId(), acceptData.getDetailSystem().getId(), showTime, null);
+                    //鐪婸P瑙嗛
+                    deviceAdStrategyService.watchPPTVVideo(acceptData.getUtdId(), acceptData.getDetailSystem().getId());
                 }
             });
             return;
@@ -800,12 +810,20 @@
         if (VersionUtil.isGraterThan390(acceptData.getPlatform(), acceptData.getVersion())) {
             String sessionId = createVideoDetailSessionId(acceptData, loginUid, info.getName(), videoId, resourceId);
 
-            out.print(JsonUtil.loadTrueJson(StringUtil.outPutResultJson(new VideoDetailVO(Utils.convertVideo(info), deviceAdStrategyService.getVideoDetailAdStrategy(acceptData.getUtdId(), acceptData.getDetailSystem().getId(), loginUid,videoId,from), attention, sessionId)), array.toString(),
+            out.print(JsonUtil.loadTrueJson(StringUtil.outPutResultJson(new VideoDetailVO(Utils.convertVideo(info), deviceAdStrategyService.getVideoDetailAdStrategy(acceptData.getUtdId(), acceptData.getDetailSystem().getId(), loginUid, videoId, from), attention, sessionId)), array.toString(),
                     obj.toString()));
         } else {
             out.print(JsonUtil.loadTrueJson(StringUtil.outPutResultJson(Utils.convertVideo(info)), array.toString(),
                     obj.toString()));
         }
+
+        ThreadUtil.run(new Runnable() {
+            @Override
+            public void run() {
+                long showTime = TimeUtil.convertGernalTime(TimeUtil.getGernalTime(System.currentTimeMillis() + 1000 * 60 * 60 * 24L, "yyyy-MM-dd"), "yyyy-MM-dd");
+                deviceAdStrategyService.setShortVideoAdStrategy(acceptData.getUtdId(), acceptData.getDetailSystem().getId(), videoId, from, showTime, null);
+            }
+        });
     }
 
 

--
Gitblit v1.8.0