From 8fee151ffae0c3818694b7318583814bf92663e2 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期五, 27 八月 2021 18:52:28 +0800
Subject: [PATCH] 聚合视频资源包调整,接入韩迷

---
 src/main/java/com/yeshi/buwan/util/video/web/TencentWebUtil.java |   61 ++++++++++++++++++++++++++----
 1 files changed, 53 insertions(+), 8 deletions(-)

diff --git a/src/main/java/com/yeshi/buwan/util/video/shortvideo/TencentWebUtil.java b/src/main/java/com/yeshi/buwan/util/video/web/TencentWebUtil.java
similarity index 63%
rename from src/main/java/com/yeshi/buwan/util/video/shortvideo/TencentWebUtil.java
rename to src/main/java/com/yeshi/buwan/util/video/web/TencentWebUtil.java
index 7ff10f1..1f7f87f 100644
--- a/src/main/java/com/yeshi/buwan/util/video/shortvideo/TencentWebUtil.java
+++ b/src/main/java/com/yeshi/buwan/util/video/web/TencentWebUtil.java
@@ -1,16 +1,15 @@
-package com.yeshi.buwan.util.video.shortvideo;
+package com.yeshi.buwan.util.video.web;
 
 import org.jsoup.Jsoup;
 import org.jsoup.nodes.Document;
 import org.jsoup.nodes.Element;
 import org.jsoup.select.Elements;
 import org.yeshi.utils.HttpUtil;
+import org.yeshi.utils.StringUtil;
 
+import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 public class TencentWebUtil {
 
@@ -105,7 +104,21 @@
         String result = HttpUtil.get(url, params, headers);
         Document document = Jsoup.parse(result);
         Elements els = document.getElementsByClass("list_item");
+        return parseVideoList(els);
+    }
 
+
+    public static List<TencentWebVideoInfo> getVideoList(String url) throws Exception {
+        Map<String, String> headers = new HashMap<>();
+        headers.put("referer", "https://v.qq.com/channel/ent");
+        headers.put("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36");
+        String result = HttpUtil.get(url, new HashMap<>(), headers);
+        Document document = Jsoup.parse(result);
+        Elements els = document.getElementsByClass("list_item");
+        return parseVideoList(els);
+    }
+
+    private static List<TencentWebVideoInfo> parseVideoList(Elements els) throws UnsupportedEncodingException {
         List<TencentWebVideoInfo> list = new ArrayList<>();
         for (int i = 0; i < els.size(); i++) {
             Element ele = els.get(i);
@@ -115,9 +128,20 @@
             title = new String(title.getBytes("ISO-8859-1"), "UTF-8");
             String picture = ele.getElementsByTag("img").get(0).attr("src");
             picture = picture.startsWith("http") ? picture : "https:" + picture;
-            String duration = ele.getElementsByClass("figure_caption").get(0).ownText();
-            System.out.println(duration);
-
+            String duration = null;
+            try {
+                duration = ele.getElementsByClass("figure_caption").get(0).ownText();
+                duration = duration.trim();
+                for (int j = 0; j < duration.length(); j++) {
+                    char ca = duration.charAt(j);
+                    if (!(ca >= 48 && ca < 59)) {
+                        duration = null;
+                        break;
+                    }
+                }
+                System.out.println(duration);
+            } catch (Exception e) {
+            }
             TencentWebVideoInfo videoInfo = new TencentWebVideoInfo();
             videoInfo.setDuration(duration);
             videoInfo.setId(id);
@@ -129,6 +153,27 @@
         return list;
     }
 
+    public static String getApiUrl(String webUrl, int page) {
+        Map<String, String> params = parseParams(webUrl);
+        int pageSize = 30;
+        params.put("append", "1");
+        params.put("listpage", page + "");
+        params.put("offset", (page - 1) * pageSize + "");
+        params.put("pagesize", pageSize + "");
+        String url = "https://v.qq.com/x/bu/pagesheet/list";
+        List<String> paramsList = new ArrayList<>();
+        for (Iterator<String> its = params.keySet().iterator(); its.hasNext(); ) {
+            String key = its.next();
+            String value = params.get(key);
+            try {
+                paramsList.add(key + "=" + URLDecoder.decode(value, "UTF-8"));
+            } catch (UnsupportedEncodingException e) {
+                e.printStackTrace();
+            }
+        }
+        return url + "?" + StringUtil.concat(paramsList, "&");
+    }
+
 
     public static void main(String[] args) throws Exception {
         List<TencentWebVideoInfo> videoInfos = getVideoList(parseParams("https://v.qq.com/channel/ent?_all=1&channel=ent&iarea=2&itype=-1&listpage=1&sort=40"), 1);

--
Gitblit v1.8.0