Pārlūkot izejas kodu

update:jsoupVideoInfo加入男演员更新v1

tujidelv 2 gadi atpakaļ
vecāks
revīzija
12e9ec64ee

+ 5 - 0
src/main/java/top/lvzhiqiang/entity/VideoInfo.java

@@ -71,6 +71,11 @@ public class VideoInfo implements Serializable {
     private String cast;
 
     /**
+     * 男演员
+     */
+    private String maleCast;
+
+    /**
      * 图片URL
      */
     private String imgUrl;

+ 4 - 1
src/main/java/top/lvzhiqiang/mapper/VideoInfoMapper.java

@@ -104,7 +104,7 @@ public interface VideoInfoMapper {
     @Update("update video_info set delete_flag = 2,modify_time = now() where identification_code = #{identificationCode}")
     void delByCode(String identificationCode);
 
-    @Update("update video_info set name = #{name}, length = #{length}, director = #{director}, maker = #{maker}, issuer = #{issuer}, issue_date = #{issueDate}, genres = #{genres}, cast = #{cast}, status = #{status}, img_url = #{imgUrl}, modify_time = now() where identification_code = #{identificationCode}")
+    @Update("update video_info set name = #{name}, length = #{length}, director = #{director}, maker = #{maker}, issuer = #{issuer}, issue_date = #{issueDate}, genres = #{genres}, cast = #{cast}, male_cast = #{maleCast}, status = #{status}, img_url = #{imgUrl}, modify_time = now() where identification_code = #{identificationCode}")
     void updateJsoupInfoByCode(VideoInfo videoInfo);
 
     /**
@@ -131,4 +131,7 @@ public interface VideoInfoMapper {
 
     @Update("update video_info set delete_flag = 2,modify_time = now() where identification_code = #{identificationCode}")
     void delByIdentificationCode(String identificationCode);
+
+    @Update("update video_info set male_cast = #{maleCast} where identification_code = #{identificationCode}")
+    void updateMaleCast(VideoInfo videoInfo);
 }

+ 9 - 0
src/main/java/top/lvzhiqiang/service/BgService.java

@@ -1,5 +1,7 @@
 package top.lvzhiqiang.service;
 
+import top.lvzhiqiang.entity.VideoInfo;
+
 import java.io.InputStream;
 
 /**
@@ -139,4 +141,11 @@ public interface BgService {
      * 2022/9/27 20:54
      */
     void insertVideoInfo(String identificationCode, String videoName, Integer parentType, String parentName, Integer type);
+
+    /**
+     * 获取男优
+     *
+     * @param videoInfo
+     */
+    void getMaleCast(VideoInfo videoInfo);
 }

+ 60 - 0
src/main/java/top/lvzhiqiang/service/impl/BgServiceImpl.java

@@ -23,12 +23,14 @@ import top.lvzhiqiang.exception.ParameterException;
 import top.lvzhiqiang.mapper.*;
 import top.lvzhiqiang.service.BgService;
 import top.lvzhiqiang.util.DateUtils;
+import top.lvzhiqiang.util.JsoupUtil;
 import top.lvzhiqiang.util.StringUtils;
 
 import javax.annotation.Resource;
 import java.io.*;
 import java.lang.reflect.Field;
 import java.math.BigDecimal;
+import java.net.Proxy;
 import java.nio.charset.StandardCharsets;
 import java.time.Instant;
 import java.time.LocalDate;
@@ -458,6 +460,10 @@ public class BgServiceImpl implements BgService {
                     videoInfo.setIdentificationCode(identificationCode);
                     String picTime = parseDocument4QiBing(document, identificationCode, qibingPath, videoInfo);
                     videoInfo.setStatus(2);
+
+                    // 获取男优
+                    getMaleCast(videoInfo);
+
                     videoInfoMapper.updateJsoupInfoByCode(videoInfo);
                     videoInfoOtherMapper.insertOrUpdate(identificationCode, 2);
 
@@ -480,6 +486,60 @@ public class BgServiceImpl implements BgService {
         log.warn("jsoupVideoInfo 统计:total={},success={}", icodeList.size(), j);
     }
 
+    @Override
+    public void getMaleCast(VideoInfo videoInfo) {
+        Document document;
+        try {
+            Map<String,String> headerMap = new HashMap<>();
+            headerMap.put("referer", "avdanyuwiki.com");
+
+            document = JsoupUtil.requestDocument("https://avdanyuwiki.com/?s=".concat(videoInfo.getName()), JsoupUtil.HTTP_GET, Proxy.NO_PROXY, null, headerMap, null);
+
+            Elements container = document.select("div#header-container-in");
+            if (container.size() == 0) {
+                return;
+            }
+
+            Elements alinks1 = container.select("h4").select("a[rel='bookmark']");
+            if (alinks1 == null || alinks1.size() == 0) {
+                return;
+            }
+
+            String alinkhref = alinks1.first().attr("abs:href");
+            document = JsoupUtil.requestDocument(alinkhref, JsoupUtil.HTTP_GET, Proxy.NO_PROXY, null, headerMap, null);
+
+            Elements entrycontent = document.select("div.entry-content");
+            if (entrycontent.size() == 0) {
+                return;
+            }
+
+            String[] entrycontentArr = entrycontent.html().split("<br>");
+            for (String s : entrycontentArr) {
+                if (s.contains("出演男優")) {
+                    String[] split = s.split(":");
+                    if (split.length < 2) {
+                        return;
+                    }
+                    String maleCasts = s.split(":")[1];
+
+                    List<String> sssss = new ArrayList<>();
+                    String[] split1 = maleCasts.split(",");
+                    for (String s1 : split1) {
+                        String[] split2 = s1.trim().split("\\s+");
+                        for (String s2 : split2) {
+                            sssss.add(s2.replaceAll(" ", "").trim());
+                        }
+                    }
+                    String maleCast = StringUtils.join(sssss, ",");
+                    videoInfo.setMaleCast(maleCast);
+                    break;
+                }
+            }
+        } catch (Exception e) {
+            log.error("getMaleCast error,icode={},name={}={}", videoInfo.getIdentificationCode(), videoInfo.getName(), e);
+        }
+    }
+
     /**
      * 删除影片
      *

+ 4 - 1
src/main/resources/mapper/VideoInfoMapper.xml

@@ -12,7 +12,10 @@
         left join video_info_other vio on vi.identification_code = vio.identification_code and vio.delete_flag = 1
         where vi.delete_flag = 1
         <if test="keyword != null and keyword != ''">
-            and (vi.name like #{keyword} or vi.identification_code like #{keyword})
+            and (vi.name like #{keyword} or vi.identification_code like #{keyword} or vi.male_cast like #{keyword})
+        </if>
+        <if test="maleCastNull != null and maleCastNull != '1'">
+            and (vi.male_cast = '' or vi.male_cast is null)
         </if>
         <if test="genres != null and genres != ''">
             and exists(select 1 from video_info_genres vig where vig.name = #{genres} and vig.identification_code = vi.identification_code)

+ 1 - 1
src/main/resources/static/js/my-video.js

@@ -176,7 +176,7 @@ function search(pageNo, startFlag, searchSelectFlag) {
                         "       </a>" +
                         "       <div class=\"myui-vodlist__detail\">" +
                         "           <h4 class=\"videodetail title text-overflow\" identificationCode='" + videoInfo.identificationCode + "' orginUrl='" + orginUrl + "'><a title=\" " + videoInfo.name + " \">" + videoInfo.name + "</a></h4>" +
-                        "           <p class=\"text text-overflow text-muted hidden-xs\" title='" + videoInfo.mainWho + "'>直属:" + videoInfo.mainWho + "</p>" +
+                        "           <p class=\"text text-overflow text-muted hidden-xs\" title='" + (videoInfo.maleCast === null ? videoInfo.mainWho : videoInfo.maleCast) + "'>直属:" + videoInfo.mainWho + "</p>" +
                         "       </div>" +
                         "   </div>" +
                         "</li>";

+ 8 - 1
src/test/java/Test4.java

@@ -18,11 +18,18 @@
  * 3、刷票。很多投票的网页一个IP只允许投票一次,如果我们借助大量代理IP去投票,结果可想而知....
  */
 
+import top.lvzhiqiang.entity.VideoInfo;
+import top.lvzhiqiang.service.impl.BgServiceImpl;
+
 /**
  * 爬取网上免费代理IP,搭建自己的Ip池
  */
 public class Test4 {
     public static void main(String[] args) {
-
+        BgServiceImpl bgService = new BgServiceImpl();
+        VideoInfo vi = new VideoInfo();
+        vi.setName("欲情した接吻痴女の唾液交換ベロ舐めセックス 三上悠亜");
+        bgService.getMaleCast(vi);
+        System.out.println(vi);
     }
 }

+ 29 - 11
src/test/java/top/lvzhiqiang/Test6.java

@@ -5,20 +5,14 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import top.lvzhiqiang.entity.VideoCast;
-import top.lvzhiqiang.entity.VideoGenres;
-import top.lvzhiqiang.entity.VideoInfoGenres;
-import top.lvzhiqiang.entity.VideoInfoPool;
-import top.lvzhiqiang.mapper.VideoCastMapper;
-import top.lvzhiqiang.mapper.VideoGenresMapper;
-import top.lvzhiqiang.mapper.VideoInfoGenresMapper;
-import top.lvzhiqiang.mapper.VideoInfoPoolMapper;
+import top.lvzhiqiang.entity.*;
+import top.lvzhiqiang.mapper.*;
+import top.lvzhiqiang.service.BgService;
+import top.lvzhiqiang.util.StringUtils;
 
 import javax.annotation.Resource;
 import java.nio.charset.StandardCharsets;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
 
 /**
  * 单元测试类
@@ -47,6 +41,11 @@ public class Test6 {
     @Resource
     private VideoInfoGenresMapper videoInfoGenresMapper;
 
+    @Resource
+    private BgService bgService;
+    @Resource
+    private VideoInfoMapper videoInfoMapper;
+
     @Test
     public void testGetBusinessDeptSummary() {
         List<VideoInfoPool> videoInfoPoolList = videoInfoPoolMapper.findAll();
@@ -94,4 +93,23 @@ public class Test6 {
 
         System.out.println(videoInfoGenresSet);
     }
+
+    @Test
+    public void testGetMaleCast() {
+        Map<String, Object> params = new HashMap<>();
+        params.put("maleCastNull", "1");
+        List<VideoInfo> videoInfoList = videoInfoMapper.getVideoInfoList(params);
+        System.out.println("size:" + videoInfoList.size());
+        int i = 0;
+        for (VideoInfo videoInfo : videoInfoList) {
+            i++;
+            bgService.getMaleCast(videoInfo);
+            if (StringUtils.isNotEmpty(videoInfo.getMaleCast())) {
+                videoInfoMapper.updateMaleCast(videoInfo);
+                System.out.println(i + ":" + videoInfo.getIdentificationCode() + ":success");
+            } else {
+                System.out.println(i + ":" + videoInfo.getIdentificationCode() + ":fail");
+            }
+        }
+    }
 }