From 9e9668931edb23efd80f002b07470eefeb143174 Mon Sep 17 00:00:00 2001 From: yangqiang3504 <412594121@qq.com> Date: Wed, 31 Aug 2022 17:18:42 +0800 Subject: [PATCH] add - bili --- .../com/github/catvod/spider/PushAgent.java | 92 ++++++-- .../com/github/catvod/spider/XBiubiu.java | 209 +++++++++--------- .../java/com/github/catvod/utils/Misc.java | 34 +++ 3 files changed, 220 insertions(+), 115 deletions(-) diff --git a/app/src/main/java/com/github/catvod/spider/PushAgent.java b/app/src/main/java/com/github/catvod/spider/PushAgent.java index b394a4d..a8dd413 100644 --- a/app/src/main/java/com/github/catvod/spider/PushAgent.java +++ b/app/src/main/java/com/github/catvod/spider/PushAgent.java @@ -39,16 +39,14 @@ public class PushAgent extends Spider { private static final String SiteUrl = "https://api.aliyundrive.com"; private static final Pattern AliPLink = Pattern.compile("(https://www.aliyundrive.com/s/[^\"]+)"); public static Pattern Folder = Pattern.compile("www.aliyundrive.com/s/([^/]+)(/folder/([^/]+))?"); - public static String Token="3a49cf29cf20410997247c6eb4509be9"; + public static String Token="http://catvod.fun:8001/tv/ali.txt"; public static JSONObject siteRule = null; public static String jsonUrl = "http://test.xinjun58.com/sp/d.json"; @Override public void init(Context context, String extend) { super.init(context, extend); - if (extend != null) { - getToken(Token); - } + getToken(Token); } public void getToken(String token){ @@ -503,22 +501,44 @@ public class PushAgent extends Spider { Matcher matcher2 = pattern2.matcher(url); Matcher matcher = pattern.matcher(url); List vodItems = new ArrayList<>(); + ArrayList aslist = new ArrayList<>(); JSONArray lists = new JSONArray(); String typeName = Misc.getWebName(url, 0); JSONObject vodAtom = new JSONObject(); - String VodName = ""; + String VodName = "",director = "",actor = "",desc = ""; vodAtom.put("vod_id", url); vodAtom.put("vod_pic", pic); vodAtom.put("type_name", typeName); vodAtom.put("vod_content", url); vodAtom.put("vod_area", type + Token); if (Misc.isVip(url) && !url.contains("qq.com") && !url.contains("mgtv.com")) { + Elements playListA = null; Document doc = Jsoup.parse(OkHttpUtil.string(url, Misc.Headers(0,url))); + String baseUrl = url.replaceAll("(^https?://.*?)(:\\d+)?/.*$", "$1");//https://www.dyk9.com + if (url.contains("bilibili.com/bangumi/play/ep")) {//第一集地址 + String nids = url.replaceAll(".*/ep(\\d+).*", "$1"); + int nid = Integer.parseInt(nids); + Elements el = doc.select(".ep-list-progress"); + if(!el.isEmpty()){ + String ptext = doc.select(".ep-list-progress").text(); + String t = ptext.replaceAll("\\d+/(\\d+)", "$1"); + int z = Integer.parseInt(t); + for (int i = 0; i < z; i++) { + int x = nid+i; + String id = baseUrl+"/bangumi/play/ep"+x+"/"; + String name = i+1+""; + vodItems.add(name + "$" + id); + } + String playList = com.github.catvod.utils.TextUtils.join("#", vodItems); + vodAtom.put("vod_play_url", playList); + } + } else { + vodAtom.put("vod_play_url", "立即播放$" + url); + } VodName = doc.select("head > title").text(); JSONObject result = new JSONObject(); vodAtom.put("vod_name", VodName); vodAtom.put("vod_play_from", "jx"); - vodAtom.put("vod_play_url", "立即播放$" + url); lists.put(vodAtom); result.put("list", lists); return result.toString(); @@ -547,7 +567,7 @@ public class PushAgent extends Spider { vodItems.add(name + "$" + id); } } - String playList = TextUtils.join("#", vodItems); + String playList = com.github.catvod.utils.TextUtils.join("#", vodItems); vodAtom.put("vod_play_url", playList); } else { vodAtom.put("vod_play_url", "立即播放$" + url); @@ -581,7 +601,7 @@ public class PushAgent extends Spider { vodItems.add(VodName + "$" + VodId); } } - String playList = TextUtils.join("#", vodItems); + String playList = com.github.catvod.utils.TextUtils.join("#", vodItems); vodAtom.put("vod_play_url", playList); } else { vodAtom.put("vod_play_url", "立即播放$" + url); @@ -643,6 +663,7 @@ public class PushAgent extends Spider { fb=false; url = baseUrl+mh.group(1); } + setVideoDesc(vodAtom, content); } } @@ -712,17 +733,18 @@ public class PushAgent extends Spider { for (String key : m.keySet()) { vodItems.add(m.get(key) + "$" + key); } - if(fb) playList.add(0, TextUtils.join("#", vodItems)); - else playList.add(TextUtils.join("#", vodItems)); + if(fb) playList.add(0, com.github.catvod.utils.TextUtils.join("#", vodItems)); + else playList.add(com.github.catvod.utils.TextUtils.join("#", vodItems)); } ArrayList playFrom = new ArrayList<>(); for (int i = 0; i < playList.size(); i++) { + String k = playList.get(i); playFrom.add("嗅探列表" + (i + 1)); } - String vod_play_from = TextUtils.join("$$$", playFrom); - String vod_play_url = TextUtils.join("$$$", playList); + String vod_play_from = com.github.catvod.utils.TextUtils.join("$$$", playFrom); + String vod_play_url = com.github.catvod.utils.TextUtils.join("$$$", playList); vodAtom.put("vod_play_from", vod_play_from); vodAtom.put("vod_play_url", vod_play_url); }else{ @@ -734,6 +756,7 @@ public class PushAgent extends Spider { vodAtom.put("vod_id", url); vodAtom.put("vod_name", VodName); vodAtom.put("type_name", "嗅探"); + setVideoDesc(vodAtom, content); lists.put(vodAtom); result.put("list", lists); return result.toString(); @@ -745,6 +768,42 @@ public class PushAgent extends Spider { return ""; } + public static JSONObject setVideoDesc(JSONObject vodAtom, String content) { + try { + if(vodAtom.has("vod_actor"))return vodAtom; + ArrayList aslist = new ArrayList<>(); + String director = "",actor = "",desc = ""; + String directorRegx = "导演:",actorRegx = "主演:",descRegx = "简介:"; + boolean fb = true; + if (!Misc.matcher("actorRegx", content).find()) { + fb=false; + actorRegx = "主演:"; + directorRegx = "导演:"; + } + aslist = Misc.subContent(content, actorRegx, ""); + if(!aslist.isEmpty()) actor = aslist.get(0); + aslist = Misc.subContent(content, directorRegx, ""); + if(!aslist.isEmpty()) director = aslist.get(0); + aslist = Misc.subContent(content, descRegx, ""); + if(!aslist.isEmpty()) { + desc = aslist.get(0); + desc = Misc.trim(desc); + desc = desc.replaceAll("", ""); + desc = Misc.delHTMLTag(desc); + } + if (!fb) { + actor = Misc.delHTMLTag(actor); + director = Misc.delHTMLTag(director); + } + vodAtom.put("vod_actor", actor); + vodAtom.put("vod_director", director); + vodAtom.put("vod_content", desc); + } catch (JSONException e) { + SpiderDebug.log(e); + } + return vodAtom; + } + @Override public String playerContent(String flag, String id, List vipFlags) { JSONObject result = new JSONObject(); @@ -754,7 +813,14 @@ public class PushAgent extends Spider { result.put("parse", 1); result.put("jx", "1"); result.put("url", id); - if(id.contains("bilibili"))result.put("header", Misc.jHeaders(0,id).toString()); + if(id.contains("bilibili")){ + result.put("header", Misc.jHeaders(0,id).toString()); + String bili = fetchRule(false,0).optString("bili", ""); + if (!bili.equals("")) { + result.put("playUrl", bili + id); + }else + result.put("playUrl", ""); + } else result.put("header", Misc.jHeaders(type,id).toString()); return result.toString(); } diff --git a/app/src/main/java/com/github/catvod/spider/XBiubiu.java b/app/src/main/java/com/github/catvod/spider/XBiubiu.java index bc37849..a94a67f 100644 --- a/app/src/main/java/com/github/catvod/spider/XBiubiu.java +++ b/app/src/main/java/com/github/catvod/spider/XBiubiu.java @@ -22,13 +22,14 @@ import java.util.regex.Pattern; import okhttp3.Call; public class XBiubiu extends Spider { - + private PushAgent pushAgent= null; @Override public void init(Context context) { super.init(context); } public void init(Context context, String extend) { + pushAgent= new PushAgent(); super.init(context, extend); this.ext = extend; } @@ -163,124 +164,128 @@ public class XBiubiu extends Spider { public String detailContent(List ids) { try { fetchRule(); - String[] idInfo = ids.get(0).split("\\$\\$\\$"); - String webUrl = getRuleVal("url") + idInfo[2]; - String html = fetch(webUrl); - String parseContent = html; - boolean bfshifouercijiequ = getRuleVal("bfshifouercijiequ").equals("1"); - if (bfshifouercijiequ) { - String jiequqian = getRuleVal("bfjiequqian"); - String jiequhou = getRuleVal("bfjiequhou"); - parseContent = subContent(html, jiequqian, jiequhou).get(0); - } - - ArrayList playList = new ArrayList<>(); - String jiequshuzuqian = getRuleVal("bfjiequshuzuqian"); - String jiequshuzuhou = getRuleVal("bfjiequshuzuhou"); - boolean bfyshifouercijiequ = getRuleVal("bfyshifouercijiequ").equals("1"); - ArrayList jiequContents = subContent(parseContent, jiequshuzuqian, jiequshuzuhou); - for (int i = 0; i < jiequContents.size(); i++) { - try { - String jiequContent = jiequContents.get(i); - String parseJqContent = bfyshifouercijiequ ? subContent(jiequContent, getRuleVal("bfyjiequqian"), getRuleVal("bfyjiequhou")).get(0) : jiequContent; - ArrayList lastParseContents = subContent(parseJqContent, getRuleVal("bfyjiequshuzuqian"), getRuleVal("bfyjiequshuzuhou")); - List vodItems = new ArrayList<>(); - for (int j = 0; j < lastParseContents.size(); j++) { - String title = subContent(lastParseContents.get(j), getRuleVal("bfbiaotiqian"), getRuleVal("bfbiaotihou")).get(0); - String link = subContent(lastParseContents.get(j), getRuleVal("bflianjieqian"), getRuleVal("bflianjiehou")).get(0); - vodItems.add(title + "$" + link); + boolean bfjiequshuzuqian = jiequshuzuqian.equals(""); + if(bfjiequshuzuqian){ + String[] idInfo = ids.get(0).split("\\$\\$\\$"); + String webUrl = getRuleVal("url") + idInfo[0]; + String html = fetch(webUrl); + String parseContent = html; + boolean bfshifouercijiequ = getRuleVal("bfshifouercijiequ").equals("1"); + if (bfshifouercijiequ) { + String jiequqian = getRuleVal("bfjiequqian"); + String jiequhou = getRuleVal("bfjiequhou"); + parseContent = subContent(html, jiequqian, jiequhou).get(0); + } + + ArrayList playList = new ArrayList<>(); + + + String jiequshuzuhou = getRuleVal("bfjiequshuzuhou"); + boolean bfyshifouercijiequ = getRuleVal("bfyshifouercijiequ").equals("1"); + ArrayList jiequContents = subContent(parseContent, jiequshuzuqian, jiequshuzuhou); + for (int i = 0; i < jiequContents.size(); i++) { + try { + String jiequContent = jiequContents.get(i); + String parseJqContent = bfyshifouercijiequ ? subContent(jiequContent, getRuleVal("bfyjiequqian"), getRuleVal("bfyjiequhou")).get(0) : jiequContent; + ArrayList lastParseContents = subContent(parseJqContent, getRuleVal("bfyjiequshuzuqian"), getRuleVal("bfyjiequshuzuhou")); + List vodItems = new ArrayList<>(); + for (int j = 0; j < lastParseContents.size(); j++) { + String title = subContent(lastParseContents.get(j), getRuleVal("bfbiaotiqian"), getRuleVal("bfbiaotihou")).get(0); + String link = subContent(lastParseContents.get(j), getRuleVal("bflianjieqian"), getRuleVal("bflianjiehou")).get(0); + vodItems.add(title + "$" + link); + } + playList.add(0, android.text.TextUtils.join("#", vodItems)); + } catch (Throwable th) { + th.printStackTrace(); + break; } - playList.add(0, TextUtils.join("#", vodItems)); - } catch (Throwable th) { - th.printStackTrace(); - break; } - } - String cover = idInfo[1], title = idInfo[0], area = ""; - String director = ""; - String actor = ""; - String desc = ""; - String remark = ""; - String year = ""; - String category = ""; + String cover = idInfo[1], title = idInfo[2], area = ""; + String director = ""; + String actor = ""; + String desc = ""; + String remark = ""; + String year = ""; + String category = ""; - if (!getRuleVal("leixinqian").isEmpty() && !getRuleVal("leixinhou").isEmpty()) { - try { - category = subContent(html, getRuleVal("leixinqian"), getRuleVal("leixinhou")).get(0).replaceAll("\\s+", "").replaceAll("\\&[a-zA-Z]{1,10};", "").replaceAll("<[^>]*>", "").replaceAll("[(/>)<]", ""); - } catch (Exception e) { - SpiderDebug.log(e); + if (!getRuleVal("leixinqian").isEmpty() && !getRuleVal("leixinhou").isEmpty()) { + try { + category = subContent(html, getRuleVal("leixinqian"), getRuleVal("leixinhou")).get(0).replaceAll("\\s+", "").replaceAll("\\&[a-zA-Z]{1,10};", "").replaceAll("<[^>]*>", "").replaceAll("[(/>)<]", ""); + } catch (Exception e) { + SpiderDebug.log(e); + } } - } - if (!getRuleVal("niandaiqian").isEmpty() && !getRuleVal("niandaihou").isEmpty()) { - try { - year = subContent(html, getRuleVal("niandaiqian"), getRuleVal("niandaihou")).get(0).replaceAll("\\s+", "").replaceAll("\\&[a-zA-Z]{1,10};", "").replaceAll("<[^>]*>", "").replaceAll("[(/>)<]", ""); - } catch (Exception e) { - SpiderDebug.log(e); + if (!getRuleVal("niandaiqian").isEmpty() && !getRuleVal("niandaihou").isEmpty()) { + try { + year = subContent(html, getRuleVal("niandaiqian"), getRuleVal("niandaihou")).get(0).replaceAll("\\s+", "").replaceAll("\\&[a-zA-Z]{1,10};", "").replaceAll("<[^>]*>", "").replaceAll("[(/>)<]", ""); + } catch (Exception e) { + SpiderDebug.log(e); + } } - } - if (!getRuleVal("zhuangtaiqian").isEmpty() && !getRuleVal("zhuangtaihou").isEmpty()) { - try { - remark = subContent(html, getRuleVal("zhuangtaiqian"), getRuleVal("zhuangtaihou")).get(0); - } catch (Exception e) { - SpiderDebug.log(e); + if (!getRuleVal("zhuangtaiqian").isEmpty() && !getRuleVal("zhuangtaihou").isEmpty()) { + try { + remark = subContent(html, getRuleVal("zhuangtaiqian"), getRuleVal("zhuangtaihou")).get(0); + } catch (Exception e) { + SpiderDebug.log(e); + } } - } - if (!getRuleVal("zhuyanqian").isEmpty() && !getRuleVal("zhuyanhou").isEmpty()) { - try { - actor = subContent(html, getRuleVal("zhuyanqian"), getRuleVal("zhuyanhou")).get(0).replaceAll("\\s+", ""); - } catch (Exception e) { - SpiderDebug.log(e); + if (!getRuleVal("zhuyanqian").isEmpty() && !getRuleVal("zhuyanhou").isEmpty()) { + try { + actor = subContent(html, getRuleVal("zhuyanqian"), getRuleVal("zhuyanhou")).get(0).replaceAll("\\s+", ""); + } catch (Exception e) { + SpiderDebug.log(e); + } } - } - if (!getRuleVal("daoyanqian").isEmpty() && !getRuleVal("daoyanhou").isEmpty()) { - try { - director = subContent(html, getRuleVal("daoyanqian"), getRuleVal("daoyanhou")).get(0).replaceAll("\\s+", ""); - } catch (Exception e) { - SpiderDebug.log(e); + if (!getRuleVal("daoyanqian").isEmpty() && !getRuleVal("daoyanhou").isEmpty()) { + try { + director = subContent(html, getRuleVal("daoyanqian"), getRuleVal("daoyanhou")).get(0).replaceAll("\\s+", ""); + } catch (Exception e) { + SpiderDebug.log(e); + } } - } - if (!getRuleVal("juqingqian").isEmpty() && !getRuleVal("juqinghou").isEmpty()) { - try { - desc = subContent(html, getRuleVal("juqingqian"), getRuleVal("juqinghou")).get(0); - if(desc!=null){ - desc = desc.replace("\t", ""); - desc = desc.replaceAll("\\.*>(.*)", "$1"); + if (!getRuleVal("juqingqian").isEmpty() && !getRuleVal("juqinghou").isEmpty()) { + try { + desc = subContent(html, getRuleVal("juqingqian"), getRuleVal("juqinghou")).get(0); + if(desc!=null){ + desc = desc.replace("\t", ""); + desc = desc.replaceAll("\\.*>(.*)", "$1"); + } + } catch (Exception e) { + SpiderDebug.log(e); } - } catch (Exception e) { - SpiderDebug.log(e); } - } - JSONObject vod = new JSONObject(); - vod.put("vod_id", ids.get(0)); - vod.put("vod_name", title); - vod.put("vod_pic", cover); - vod.put("type_name", category); - vod.put("vod_year", year); - vod.put("vod_area", area); - vod.put("vod_remarks", remark); - vod.put("vod_actor", actor); - vod.put("vod_director", director); - vod.put("vod_content", desc); + JSONObject vod = new JSONObject(); + vod.put("vod_id", ids.get(0)); + vod.put("vod_name", title); + vod.put("vod_pic", cover); + vod.put("type_name", category); + vod.put("vod_year", year); + vod.put("vod_area", area); + vod.put("vod_remarks", remark); + vod.put("vod_actor", actor); + vod.put("vod_director", director); + vod.put("vod_content", desc); - ArrayList playFrom = new ArrayList<>(); + ArrayList playFrom = new ArrayList<>(); - for (int i = 0; i < playList.size(); i++) { - playFrom.add("播放列表" + (i + 1)); - } + for (int i = 0; i < playList.size(); i++) { + playFrom.add("播放列表" + (i + 1)); + } - String vod_play_from = TextUtils.join("$$$", playFrom); - String vod_play_url = TextUtils.join("$$$", playList); - vod.put("vod_play_from", vod_play_from); - vod.put("vod_play_url", vod_play_url); + String vod_play_from = android.text.TextUtils.join("$$$", playFrom); + String vod_play_url = TextUtils.join("$$$", playList); + vod.put("vod_play_from", vod_play_from); + vod.put("vod_play_url", vod_play_url); - JSONObject result = new JSONObject(); - JSONArray list = new JSONArray(); - list.put(vod); - result.put("list", list); - return result.toString(); + JSONObject result = new JSONObject(); + JSONArray list = new JSONArray(); + list.put(vod); + result.put("list", list); + return result.toString(); + } else return pushAgent.detailContent(ids); } catch (Exception e) { SpiderDebug.log(e); } diff --git a/app/src/main/java/com/github/catvod/utils/Misc.java b/app/src/main/java/com/github/catvod/utils/Misc.java index 4e35557..fc0389a 100644 --- a/app/src/main/java/com/github/catvod/utils/Misc.java +++ b/app/src/main/java/com/github/catvod/utils/Misc.java @@ -4,6 +4,7 @@ import android.os.Build; import com.github.catvod.crawler.SpiderDebug; import org.json.JSONException; import org.json.JSONObject; +import java.util.ArrayList; import java.util.HashMap; import java.nio.charset.Charset; import java.security.MessageDigest; @@ -223,4 +224,37 @@ public class Misc { } return ""; } + + public static Matcher matcher(String regx, String content) { + Pattern pattern = Pattern.compile(regx); + return pattern.matcher(content); + } + public static String trim(String str) { + return str == null ? str : str.replaceAll("^[\\s |\\s ]*|[\\s |\\s ]*$", ""); + } + + public static String delHTMLTag(String htmlStr){ + String regEx_html="<[^>]+>"; //定义HTML标签的正则表达式 + Pattern p_html=Pattern.compile(regEx_html,Pattern.CASE_INSENSITIVE); + Matcher m_html=p_html.matcher(htmlStr); + htmlStr=m_html.replaceAll(""); //过滤html标签 + htmlStr = htmlStr.replaceAll("&| ", " "); + return htmlStr.trim(); //返回文本字符串 + } + + public static ArrayList subContent(String content, String startFlag, String endFlag) { + ArrayList result = new ArrayList<>(); + if (content != null && content.length() > 1) { + try { + Pattern pattern = Pattern.compile(startFlag + "(.*?)" + endFlag); + Matcher matcher = pattern.matcher(content); + while (matcher.find()) { + result.add(matcher.group(1)); + } + } catch (Throwable th) { + th.printStackTrace(); + } + } + return result; + } } \ No newline at end of file