From d626d48038f412b8c597837478dbb472984fc9f3 Mon Sep 17 00:00:00 2001 From: dlgt7 <102397160+dlgt7@users.noreply.github.com> Date: Mon, 15 Aug 2022 15:25:01 +0800 Subject: [PATCH] Add files via upload --- .../java/com/github/catvod/spider/Juhi.java | 472 +++++++++++++++++ .../java/com/github/catvod/spider/N0ys.java | 471 +++++++++++++++++ .../java/com/github/catvod/spider/Nekk.java | 489 ++++++++++++++++++ .../java/com/github/catvod/spider/Nfx.java | 449 ++++++++++++++++ 4 files changed, 1881 insertions(+) create mode 100644 app/src/main/java/com/github/catvod/spider/Juhi.java create mode 100644 app/src/main/java/com/github/catvod/spider/N0ys.java create mode 100644 app/src/main/java/com/github/catvod/spider/Nekk.java create mode 100644 app/src/main/java/com/github/catvod/spider/Nfx.java diff --git a/app/src/main/java/com/github/catvod/spider/Juhi.java b/app/src/main/java/com/github/catvod/spider/Juhi.java new file mode 100644 index 0000000..8d33a94 --- /dev/null +++ b/app/src/main/java/com/github/catvod/spider/Juhi.java @@ -0,0 +1,472 @@ +package com.github.catvod.spider; + +import android.content.Context; +import android.text.TextUtils; + +import com.github.catvod.crawler.Spider; +import com.github.catvod.crawler.SpiderDebug; +import com.github.catvod.utils.Misc; +import com.github.catvod.utils.okhttp.OkHttpUtil; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; + +import java.net.URLEncoder; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class Juhi extends Spider { + + private static final String siteUrl = "https://www.juhi.cc/"; + private static final String siteHost = "juhi.cc"; + + protected JSONObject playerConfig; + protected JSONObject filterConfig; + + protected Pattern regexCategory = Pattern.compile("/vodtype/(\\d+)/"); + protected Pattern regexVid = Pattern.compile("/voddetail/(\\d+)/"); + protected Pattern regexPlay = Pattern.compile("/vodplay/(\\d+)-(\\d+)-(\\d+)/"); + protected Pattern regexPage = Pattern.compile("/vodshow/(\\S+)/"); + + @Override + public void init(Context context) { + super.init(context); + try { + playerConfig = new JSONObject("{\"tkm3u8\":{\"sh\":\"✦剧嗨专线\",\"pu\":\"https://jx.huishij.com/yun/?url=\",\"sn\":1,\"or\":999},\"if101\":{\"sh\":\"✦蓝光超清\",\"pu\":\"\",\"sn\":0,\"or\":999},\"dbm3u8\":{\"sh\":\"北美高清①\",\"pu\":\"\",\"sn\":0,\"or\":999},\"dbyun\":{\"sh\":\"北美高清②\",\"pu\":\"\",\"sn\":0,\"or\":999},\"wjm3u8\":{\"sh\":\"北美高清③\",\"pu\":\"\",\"sn\":0,\"or\":999},\"kbm3u8\":{\"sh\":\"全球线路①\",\"pu\":\"\",\"sn\":0,\"or\":999},\"hnyun\":{\"sh\":\"全球线路②\",\"pu\":\"\",\"sn\":0,\"or\":999},\"hnm3u8\":{\"sh\":\"全球线路③\",\"pu\":\"\",\"sn\":0,\"or\":999},\"kbzy\":{\"sh\":\"全球线路④\",\"pu\":\"\",\"sn\":0,\"or\":999},\"fanqie\":{\"sh\":\"全球线路⑤\",\"pu\":\"\",\"sn\":0,\"or\":999},\"kuaiyun\":{\"sh\":\"快速线路\",\"pu\":\"https://qimihe.com/?url=\",\"sn\":1,\"or\":999},\"leyum3u8\":{\"sh\":\"午夜专线1\",\"pu\":\"\",\"sn\":0,\"or\":999},\"lym3u8\":{\"sh\":\"午夜专线2\",\"pu\":\"\",\"sn\":0,\"or\":999},\"dplayer\":{\"sh\":\"DPlayer-H5播放器\",\"pu\":\"\",\"sn\":0,\"or\":999},\"videojs\":{\"sh\":\"videojs-H5播放器\",\"pu\":\"\",\"sn\":0,\"or\":999},\"iva\":{\"sh\":\"iva-H5播放器\",\"pu\":\"\",\"sn\":0,\"or\":999},\"iframe\":{\"sh\":\"iframe外链数据\",\"pu\":\"\",\"sn\":0,\"or\":999},\"link\":{\"sh\":\"外链数据\",\"pu\":\"\",\"sn\":0,\"or\":999},\"swf\":{\"sh\":\"Flash文件\",\"pu\":\"\",\"sn\":0,\"or\":999},\"flv\":{\"sh\":\"Flv文件\",\"pu\":\"\",\"sn\":0,\"or\":999},\"bjyun\":{\"sh\":\"bjyun\",\"pu\":\"\",\"sn\":0,\"or\":999},\"bjm3u8\":{\"sh\":\"bjm3u8\",\"pu\":\"\",\"sn\":0,\"or\":999},\"wasu\":{\"sh\":\"华数直连\",\"pu\":\"\",\"sn\":0,\"or\":999},\"funshion\":{\"sh\":\"风行直连\",\"pu\":\"\",\"sn\":0,\"or\":999},\"pptv\":{\"sh\":\"PPTV直连\",\"pu\":\"https://jx.m3u8.tv/jiexi/?url=\",\"sn\":1,\"or\":999},\"letv\":{\"sh\":\"乐视直连\",\"pu\":\"https://jx.m3u8.tv/jiexi/?url=\",\"sn\":1,\"or\":999},\"mgtv\":{\"sh\":\"芒果直连\",\"pu\":\"https://jx.m3u8.tv/jiexi/?url=\",\"sn\":1,\"or\":999},\"youku\":{\"sh\":\"优酷直连\",\"pu\":\"https://jx.m3u8.tv/jiexi/?url=\",\"sn\":1,\"or\":999},\"qiyi\":{\"sh\":\"爱奇艺直连\",\"pu\":\"https://jx.m3u8.tv/jiexi/?url=\",\"sn\":1,\"or\":999},\"qq\":{\"sh\":\"腾讯直连\",\"pu\":\"https://jx.m3u8.tv/jiexi/?url=\",\"sn\":1,\"or\":999},\"m1905\":{\"sh\":\"M1905直连\",\"pu\":\"https://jx.m3u8.tv/jiexi/?url=\",\"sn\":1,\"or\":999},\"sohu\":{\"sh\":\"搜狐直连\",\"pu\":\"https://jx.m3u8.tv/jiexi/?url=\",\"sn\":1,\"or\":999}}"); + filterConfig = new JSONObject("{\"20\":[{\"key\":\"0\",\"name\":\"类型\",\"value\":[{\"n\":\"全部\",\"v\":\"20\"},{\"n\":\"动作片\",\"v\":\"24\"},{\"n\":\"喜剧片\",\"v\":\"25\"},{\"n\":\"愛情片\",\"v\":\"26\"},{\"n\":\"科幻片\",\"v\":\"27\"},{\"n\":\"恐怖片\",\"v\":\"28\"},{\"n\":\"劇情片\",\"v\":\"11\"},{\"n\":\"戰爭片\",\"v\":\"30\"},{\"n\":\"动画电影\",\"v\":\"33\"}]},{\"key\":1,\"name\":\"地区\",\"value\":[{\"n\":\"全部\",\"v\":\"\"},{\"n\":\"大陆\",\"v\":\"大陆\"},{\"n\":\"香港\",\"v\":\"香港\"},{\"n\":\"台湾\",\"v\":\"台湾\"},{\"n\":\"美国\",\"v\":\"美国\"},{\"n\":\"法国\",\"v\":\"法国\"},{\"n\":\"英国\",\"v\":\"英国\"},{\"n\":\"日本\",\"v\":\"日本\"},{\"n\":\"韩国\",\"v\":\"韩国\"},{\"n\":\"德国\",\"v\":\"德国\"},{\"n\":\"泰国\",\"v\":\"泰国\"},{\"n\":\"印度\",\"v\":\"印度\"},{\"n\":\"意大利\",\"v\":\"意大利\"},{\"n\":\"西班牙\",\"v\":\"西班牙\"},{\"n\":\"加拿大\",\"v\":\"加拿大\"},{\"n\":\"其他\",\"v\":\"其他\"}]},{\"key\":11,\"name\":\"年份\",\"value\":[{\"n\":\"全部\",\"v\":\"\"},{\"n\":\"2021\",\"v\":\"2021\"},{\"n\":\"2020\",\"v\":\"2020\"},{\"n\":\"2019\",\"v\":\"2019\"},{\"n\":\"2018\",\"v\":\"2018\"},{\"n\":\"2017\",\"v\":\"2017\"},{\"n\":\"2016\",\"v\":\"2016\"},{\"n\":\"2015\",\"v\":\"2015\"},{\"n\":\"2014\",\"v\":\"2014\"},{\"n\":\"2013\",\"v\":\"2013\"},{\"n\":\"2012\",\"v\":\"2012\"},{\"n\":\"2011\",\"v\":\"2011\"},{\"n\":\"2010\",\"v\":\"2010\"}]},{\"key\":2,\"name\":\"排序\",\"value\":[{\"n\":\"时间\",\"v\":\"time\"},{\"n\":\"人气\",\"v\":\"hits\"},{\"n\":\"评分\",\"v\":\"score\"}]}],\"21\":[{\"key\":\"tid\",\"name\":\"类型\",\"value\":[{\"n\":\"全部\",\"v\":\"\"},{\"n\":\"国产剧\",\"v\":\"34\"},{\"n\":\"港剧\",\"v\":\"35\"},{\"n\":\"韩剧\",\"v\":\"37\"},{\"n\":\"欧美剧\",\"v\":\"36\"},{\"n\":\"日本剧\",\"v\":\"38\"},{\"n\":\"台湾剧\",\"v\":\"39\"},{\"n\":\"海外剧\",\"v\":\"40\"}]},{\"key\":11,\"name\":\"年份\",\"value\":[{\"n\":\"全部\",\"v\":\"\"},{\"n\":\"2021\",\"v\":\"2021\"},{\"n\":\"2020\",\"v\":\"2020\"},{\"n\":\"2019\",\"v\":\"2019\"},{\"n\":\"2018\",\"v\":\"2018\"},{\"n\":\"2017\",\"v\":\"2017\"},{\"n\":\"2016\",\"v\":\"2016\"},{\"n\":\"2015\",\"v\":\"2015\"},{\"n\":\"2014\",\"v\":\"2014\"},{\"n\":\"2013\",\"v\":\"2013\"},{\"n\":\"2012\",\"v\":\"2012\"},{\"n\":\"2011\",\"v\":\"2011\"},{\"n\":\"2010\",\"v\":\"2010\"},{\"n\":\"2009\",\"v\":\"2009\"},{\"n\":\"2008\",\"v\":\"2008\"},{\"n\":\"2007\",\"v\":\"2007\"},{\"n\":\"2006\",\"v\":\"2006\"},{\"n\":\"2005\",\"v\":\"2005\"},{\"n\":\"2004\",\"v\":\"2004\"}]},{\"key\":2,\"name\":\"排序\",\"value\":[{\"n\":\"时间\",\"v\":\"time\"},{\"n\":\"人气\",\"v\":\"hits\"},{\"n\":\"评分\",\"v\":\"score\"}]}],\"22\":[{\"key\":0,\"name\":\"类型\",\"value\":[{\"n\":\"全部\",\"v\":\"22\"},{\"n\":\"大陆综艺\",\"v\":\"41\"},{\"n\":\"港台综艺\",\"v\":\"42\"},{\"n\":\"日韩综艺\",\"v\":\"43\"},{\"n\":\"欧美综艺\",\"v\":\"44\"}]},{\"key\":11,\"name\":\"年份\",\"value\":[{\"n\":\"全部\",\"v\":\"\"},{\"n\":\"2021\",\"v\":\"2021\"},{\"n\":\"2020\",\"v\":\"2020\"},{\"n\":\"2019\",\"v\":\"2019\"},{\"n\":\"2018\",\"v\":\"2018\"},{\"n\":\"2017\",\"v\":\"2017\"},{\"n\":\"2016\",\"v\":\"2016\"},{\"n\":\"2015\",\"v\":\"2015\"},{\"n\":\"2014\",\"v\":\"2014\"},{\"n\":\"2013\",\"v\":\"2013\"},{\"n\":\"2012\",\"v\":\"2012\"},{\"n\":\"2011\",\"v\":\"2011\"},{\"n\":\"2010\",\"v\":\"2010\"},{\"n\":\"2009\",\"v\":\"2009\"},{\"n\":\"2008\",\"v\":\"2008\"},{\"n\":\"2007\",\"v\":\"2007\"},{\"n\":\"2006\",\"v\":\"2006\"},{\"n\":\"2005\",\"v\":\"2005\"},{\"n\":\"2004\",\"v\":\"2004\"}]},{\"key\":2,\"name\":\"排序\",\"value\":[{\"n\":\"时间\",\"v\":\"time\"},{\"n\":\"人气\",\"v\":\"hits\"},{\"n\":\"评分\",\"v\":\"score\"}]}],\"23\":[{\"key\":0,\"name\":\"类型\",\"value\":[{\"n\":\"全部\",\"v\":\"23\"},{\"n\":\"国产动漫\",\"v\":\"45\"},{\"n\":\"日本动漫\",\"v\":\"46\"},{\"n\":\"欧美动漫\",\"v\":\"47\"}]},{\"key\":11,\"name\":\"年份\",\"value\":[{\"n\":\"全部\",\"v\":\"\"},{\"n\":\"2021\",\"v\":\"2021\"},{\"n\":\"2020\",\"v\":\"2020\"},{\"n\":\"2019\",\"v\":\"2019\"},{\"n\":\"2018\",\"v\":\"2018\"},{\"n\":\"2017\",\"v\":\"2017\"},{\"n\":\"2016\",\"v\":\"2016\"},{\"n\":\"2015\",\"v\":\"2015\"},{\"n\":\"2014\",\"v\":\"2014\"},{\"n\":\"2013\",\"v\":\"2013\"},{\"n\":\"2012\",\"v\":\"2012\"},{\"n\":\"2011\",\"v\":\"2011\"},{\"n\":\"2010\",\"v\":\"2010\"},{\"n\":\"2009\",\"v\":\"2009\"},{\"n\":\"2008\",\"v\":\"2008\"},{\"n\":\"2007\",\"v\":\"2007\"},{\"n\":\"2006\",\"v\":\"2006\"},{\"n\":\"2005\",\"v\":\"2005\"},{\"n\":\"2004\",\"v\":\"2004\"}]},{\"key\":2,\"name\":\"排序\",\"value\":[{\"n\":\"时间\",\"v\":\"time\"},{\"n\":\"人气\",\"v\":\"hits\"},{\"n\":\"评分\",\"v\":\"score\"}]}]}"); + } catch (JSONException e) { + SpiderDebug.log(e); + } + } + + /** + * 爬虫headers + * + * @param url + * @return + */ + protected HashMap getHeaders(String url) { + HashMap headers = new HashMap<>(); + headers.put("method", "GET"); + headers.put("Host", siteHost); + headers.put("Upgrade-Insecure-Requests", "1"); + headers.put("DNT", "1"); + headers.put("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36"); + headers.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"); + headers.put("Accept-Language", "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2"); + return headers; + } + + /** + * 获取分类数据 + 首页最近更新视频列表数据 + * + * @param filter 是否开启筛选 关联的是 软件设置中 首页数据源里的筛选开关 + * @return + */ + @Override + public String homeContent(boolean filter) { + try { + Document doc = Jsoup.parse(OkHttpUtil.string(siteUrl, getHeaders(siteUrl))); + // 分类节点 + Elements elements = doc.select("ul.nav-menu > li > a"); + JSONArray classes = new JSONArray(); + for (Element ele : elements) { + //分类名 + String name = ele.text(); + boolean show = name.equals("电影") || + name.equals("电视剧") || + name.equals("综艺") || + name.equals("动漫"); + if (show) { + Matcher mather = regexCategory.matcher(ele.attr("href")); + if (!mather.find()) + continue; + // 把分类的id和名称取出来加到列表里 + String id = mather.group(1).trim(); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("type_id", id); + jsonObject.put("type_name", name); + classes.put(jsonObject); + } + } + JSONObject result = new JSONObject(); + if (filter) { + result.put("filters", filterConfig); + } + result.put("class", classes); + try { + // 取首页推荐视频列表 + Element homeList = doc.select("ul.myui-vodlist").get(0); + Elements list = homeList.select("li > div > a"); + JSONArray videos = new JSONArray(); + for (int i = 0; i < list.size(); i++) { + Element vod = list.get(i); + String title = vod.attr("title"); + String cover = vod.attr("data-original"); + String remark = vod.selectFirst("span.pic-text").text(); + Matcher matcher = regexVid.matcher(vod.attr("href")); + if (!matcher.find()) + continue; + String id = matcher.group(1); + JSONObject v = new JSONObject(); + v.put("vod_id", id); + v.put("vod_name", title); + v.put("vod_pic", cover); + v.put("vod_remarks", remark); + videos.put(v); + } + result.put("list", videos); + } catch (Exception e) { + SpiderDebug.log(e); + } + return result.toString(); + } catch (Exception e) { + SpiderDebug.log(e); + } + return ""; + } + + /** + * 获取分类信息数据 + * + * @param tid 分类id + * @param pg 页数 + * @param filter 同homeContent方法中的filter + * @param extend 筛选参数{k:v, k1:v1} + * @return + */ + @Override + public String categoryContent(String tid, String pg, boolean filter, HashMap extend) { + try { + String[] urlParams = new String[]{"", "", "", "", "", "", "", "", "", "", "", ""}; + urlParams[0] = tid; + urlParams[8] = pg; + if (extend != null && extend.size() > 0) { + for (Iterator it = extend.keySet().iterator(); it.hasNext(); ) { + String key = it.next(); + String value = extend.get(key); + urlParams[Integer.parseInt(key)] = URLEncoder.encode(value); + } + } + // 获取分类数据的url + String url = siteUrl + "/vodshow/" + TextUtils.join("-", urlParams) + "/"; + String html = OkHttpUtil.string(url, getHeaders(url)); + Document doc = Jsoup.parse(html); + JSONObject result = new JSONObject(); + int pageCount = 0; + int page = -1; + + + // 取页码相关信息 + Elements pageInfo = doc.select("ul.myui-page>li"); + if (pageInfo.size() == 0) { + page = Integer.parseInt(pg); + pageCount = page; + } else { + for (int i = 0; i < pageInfo.size(); i++) { + Element li = pageInfo.get(i); + Element a = li.selectFirst("a"); + if (a == null) + continue; + String name = a.text(); + if (page == -1 && a.hasClass("btn-warm")) { + Matcher matcher = regexPage.matcher(a.attr("href")); + if (matcher.find()) { + page = Integer.parseInt(matcher.group(1).split("-")[8]); + } else { + page = 0; + } + } + if (name.equals("尾页")) { + Matcher matcher = regexPage.matcher(a.attr("href")); + if (matcher.find()) { + pageCount = Integer.parseInt(matcher.group(1).split("-")[8]); + } else { + pageCount = 0; + } + break; + } + } + } + + JSONArray videos = new JSONArray(); + if (!html.contains("没有找到您想要的结果哦")) { + // 取当前分类页的视频列表 + Elements list = doc.select("ul.myui-vodlist > li > div > a"); + for (int i = 0; i < list.size(); i++) { + Element vod = list.get(i); + String title = vod.attr("title"); + String cover = vod.attr("data-original"); + String remark = vod.selectFirst("span.pic-text").text(); + Matcher matcher = regexVid.matcher(vod.attr("href")); + if (!matcher.find()) + continue; + String id = matcher.group(1); + JSONObject v = new JSONObject(); + v.put("vod_id", id); + v.put("vod_name", title); + v.put("vod_pic", cover); + v.put("vod_remarks", remark); + videos.put(v); + } + } + result.put("page", page); + result.put("pagecount", pageCount); + result.put("limit", 48); + result.put("total", pageCount <= 1 ? videos.length() : pageCount * 48); + + result.put("list", videos); + return result.toString(); + } catch (Exception e) { + SpiderDebug.log(e); + } + return ""; + } + + /** + * 视频详情信息 + * + * @param ids 视频id + * @return + */ + @Override + public String detailContent(List ids) { + try { + // 视频详情url + String url = siteUrl + "/voddetail/" + ids.get(0) + "/"; + //System.out.println(url); + Document doc = Jsoup.parse(OkHttpUtil.string(url, getHeaders(url))); + JSONObject result = new JSONObject(); + JSONObject vodList = new JSONObject(); + + // 取基本数据 + String cover = doc.selectFirst("div.myui-content__thumb > a > img").attr("src"); + String title = doc.selectFirst("div.myui-content__thumb > a").attr("title"); + String desc = Jsoup.parse(doc.selectFirst("meta[name=description]").attr("content")).text(); + String category = "", area = "", year = "", remark = "", director = "", actor = ""; + Elements span_text_muted = doc.select("div.myui-content__detail span.text-muted"); + for (int i = 0; i < span_text_muted.size(); i++) { + Element text = span_text_muted.get(i); + String info = text.text(); + if (info.equals("分类:")) { + category = text.nextElementSibling().text(); + } else if (info.equals("年份:")) { + year = text.nextElementSibling().text(); + } else if (info.equals("地区:")) { + area = text.nextElementSibling().text(); + } else if (info.equals("更新:")) { + remark = text.nextElementSibling().text(); + } else if (info.equals("导演:")) { + List directors = new ArrayList<>(); + Elements aa = text.parent().select("a"); + for (int j = 0; j < aa.size(); j++) { + directors.add(aa.get(j).text()); + } + director = TextUtils.join(",", directors); + } else if (info.equals("主演:")) { + List actors = new ArrayList<>(); + Elements aa = text.parent().select("a"); + for (int j = 0; j < aa.size(); j++) { + actors.add(aa.get(j).text()); + } + actor = TextUtils.join(",", actors); + } + } + + vodList.put("vod_id", ids.get(0)); + vodList.put("vod_name", title); + vodList.put("vod_pic", cover); + vodList.put("type_name", category); + vodList.put("vod_year", year); + vodList.put("vod_area", area); + vodList.put("vod_remarks", remark); + vodList.put("vod_actor", actor); + vodList.put("vod_director", director); + vodList.put("vod_content", desc); + //System.out.println(vodList.toString()); + Map vod_play = new TreeMap<>(new Comparator() { + @Override + public int compare(String o1, String o2) { + try { + int sort1 = playerConfig.getJSONObject(o1).getInt("or"); + int sort2 = playerConfig.getJSONObject(o2).getInt("or"); + + if (sort1 == sort2) { + return 1; + } + return sort1 - sort2 > 0 ? 1 : -1; + } catch (JSONException e) { + SpiderDebug.log(e); + } + return 1; + } + }); + + // 取播放列表数据 + Elements sources = doc.select("ul.nav-btn > li > a"); + //System.out.println(sources.size()); + Elements sourceList = doc.select("div.tab-content > div"); + //System.out.println(sourceList.size()); + for (int i = 0; i < sources.size(); i++) { + Element source = sources.get(i); + //System.out.println(sources.text().split(":")[0].split("』")[1]); + String sourceName = source.text(); + boolean found = false; + for (Iterator it = playerConfig.keys(); it.hasNext(); ) { + String flag = it.next(); + if (playerConfig.getJSONObject(flag).getString("sh").equals(sourceName)) { + sourceName = flag; + found = true; + break; + } + } + if (!found) + continue; + String playList = ""; + Elements playListA = sourceList.get(i).select("ul > li > a"); + //System.out.println(playListA.size()); + List vodItems = new ArrayList<>(); + + for (int j = 0; j < playListA.size(); j++) { + Element vod = playListA.get(j); + Matcher matcher = regexPlay.matcher(vod.attr("href")); + if (!matcher.find()) + continue; + String playURL = matcher.group(1) + "-" + matcher.group(2) + "-" + matcher.group(3); + vodItems.add(vod.text() + "$" + playURL); + } + if (vodItems.size() > 0) + playList = TextUtils.join("#", vodItems); + + if (playList.length() == 0) + continue; + + vod_play.put(sourceName, playList); + } + + if (vod_play.size() > 0) { + String vod_play_from = TextUtils.join("$$$", vod_play.keySet()); + String vod_play_url = TextUtils.join("$$$", vod_play.values()); + vodList.put("vod_play_from", vod_play_from); + vodList.put("vod_play_url", vod_play_url); + } + JSONArray list = new JSONArray(); + list.put(vodList); + result.put("list", list); + return result.toString(); + } catch (Exception e) { + SpiderDebug.log(e); + } + return ""; + } + + + /** + * 获取视频播放信息 + * + * @param flag 播放源 + * @param id 视频id + * @param vipFlags 所有可能需要vip解析的源 + * @return + */ + @Override + public String playerContent(String flag, String id, List vipFlags) { + try { + //定义播放用的headers + JSONObject headers = new JSONObject(); + //headers.put("Host", " cokemv.co"); + //headers.put("origin", " https://juhi.cc"); + //headers.put("User-Agent", " Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36"); + //headers.put("Accept", " */*"); + //headers.put("Accept-Language", " zh-CN,zh;q=0.9,en-US;q=0.3,en;q=0.7"); + //headers.put("Accept-Encoding", " gzip, deflate, br"); + + + // 播放页 url + String url = siteUrl + "/vodplay/" + id + "/"; + Document doc = Jsoup.parse(OkHttpUtil.string(url, getHeaders(url))); + Elements allScript = doc.select("script"); + JSONObject result = new JSONObject(); + for (int i = 0; i < allScript.size(); i++) { + String scContent = allScript.get(i).html().trim(); + if (scContent.startsWith("var player_")) { // 取直链 + int start = scContent.indexOf('{'); + int end = scContent.lastIndexOf('}') + 1; + String json = scContent.substring(start, end); + JSONObject player = new JSONObject(json); + if (playerConfig.has(player.getString("from"))) { + JSONObject pCfg = playerConfig.getJSONObject(player.getString("from")); + String videoUrl = player.getString("url"); + String playUrl = pCfg.getString("pu"); + if (Misc.isVip(videoUrl)) { // 使用jx:1 + try { + result.put("parse", 1); + result.put("jx", "1"); + result.put("url", videoUrl); + return result.toString(); + } catch (Exception e) { + SpiderDebug.log(e); + } + } + result.put("parse", pCfg.getInt("sn")); + result.put("playUrl", playUrl); + result.put("url", videoUrl); + result.put("header", headers.toString()); + } + break; + } + } + return result.toString(); + } catch (Exception e) { + SpiderDebug.log(e); + } + return ""; + } + + + @Override + public String searchContent(String key, boolean quick) { + try { + if (quick) + return ""; + long currentTime = System.currentTimeMillis(); + String url = siteUrl + "/index.php/ajax/suggest?mid=1&wd=" + URLEncoder.encode(key) + "&limit=10×tamp=" + currentTime; + //Document doc = Jsoup.parse(srr.content); + JSONObject searchResult = new JSONObject(OkHttpUtil.string(url, getHeaders(url))); + JSONObject result = new JSONObject(); + JSONArray videos = new JSONArray(); + if (searchResult.getInt("total") > 0) { + JSONArray lists = new JSONArray(searchResult.getString("list")); + for (int i = 0; i < lists.length(); i++) { + JSONObject vod = lists.getJSONObject(i); + String id = vod.getString("id"); + String title = vod.getString("name"); + String cover = vod.getString("pic"); + JSONObject v = new JSONObject(); + v.put("vod_id", id); + v.put("vod_name", title); + v.put("vod_pic", cover); + v.put("vod_remarks", ""); + videos.put(v); + } + } + result.put("list", videos); + return result.toString(); + } catch (Exception e) { + SpiderDebug.log(e); + } + return ""; + } +} diff --git a/app/src/main/java/com/github/catvod/spider/N0ys.java b/app/src/main/java/com/github/catvod/spider/N0ys.java new file mode 100644 index 0000000..4e63721 --- /dev/null +++ b/app/src/main/java/com/github/catvod/spider/N0ys.java @@ -0,0 +1,471 @@ +package com.github.catvod.spider; + +import android.content.Context; +import android.net.Uri; +import android.text.TextUtils; + +import com.github.catvod.crawler.Spider; +import com.github.catvod.crawler.SpiderDebug; +import com.github.catvod.utils.okhttp.OkHttpUtil; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; + +import java.net.URLEncoder; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * 90影视 + *

+ * Author: 小黄瓜 + */ +public class N0ys extends Spider { + private static final String siteUrl = "http://1090ys8.com"; + private static final String siteHost = "1090ys8.com"; + private static final String ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.54 Safari/537.36"; + + /** + * 播放源配置 + */ + private JSONObject playerConfig; + + private Pattern regexCategory = Pattern.compile("/whole/(\\w+).html"); + private Pattern regexVid = Pattern.compile("/show/(\\w+).html"); + private Pattern regexPlay = Pattern.compile("/play/(\\w+)-(\\d+)-(\\d+).html"); + private Pattern regexPage = Pattern.compile("/whole/\\d+/page/(\\d+).html"); + + @Override + public void init(Context context) { + super.init(context); + try { + playerConfig = new JSONObject("{\"youbo\":{\"sh\":\"高速1\",\"sn\":\"0\",\"pu\":\"http://jx1090ys5.hongfanedu.top/x2.php?id=\",\"or\":999},\"wanpan\":{\"sh\":\"高速备用\",\"sn\":\"0\",\"pu\":\"\",\"or\":999},\"niuxyun\":{\"sh\":\"高速2\",\"sn\":\"1\",\"pu\":\"http://1090ys2.com/nxjx/jx.php?id=\",\"or\":999},\"bjm3u8\":{\"sh\":\"备用2\",\"sn\":\"0\",\"pu\":\"\",\"or\":999},\"dbm3u8\":{\"sh\":\"备用3\",\"sn\":\"0\",\"pu\":\"\",\"or\":999},\"nfmp4\":{\"sh\":\"高速3\",\"sn\":\"0\",\"pu\":\"\",\"or\":999},\"tkm3u8\":{\"sh\":\"备用1\",\"sn\":\"0\",\"pu\":\"\",\"or\":999},\"wjm3u8\":{\"sh\":\"备用4\",\"sn\":\"0\",\"pu\":\"\",\"or\":999}}"); + } catch (JSONException e) { + SpiderDebug.log(e); + } + } + + /** + * 爬虫headers + * + * @param url + * @return + */ + protected HashMap getHeaders(String url) { + HashMap headers = new HashMap<>(); + headers.put("method", "GET"); + headers.put("Host", siteHost); + headers.put("Upgrade-Insecure-Requests", "1"); + headers.put("DNT", "1"); + headers.put("User-Agent", ua); + headers.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"); + headers.put("Accept-Language", "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2"); + return headers; + } + + /** + * 获取分类数据 + 首页最近更新视频列表数据 + * + * @param filter 是否开启筛选 关联的是 软件设置中 首页数据源里的筛选开关 + * @return + */ + @Override + public String homeContent(boolean filter) { + try { + Document doc = Jsoup.parse(OkHttpUtil.string(siteUrl, getHeaders(siteUrl))); + // 分类节点 + Elements elements = doc.select("ul.type-slide > li a"); + JSONArray classes = new JSONArray(); + for (Element ele : elements) { + String name = ele.text(); + Matcher mather = regexCategory.matcher(ele.attr("href")); + if (!mather.find()) + continue; + String id = mather.group(1).trim(); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("type_id", id); + jsonObject.put("type_name", name); + classes.put(jsonObject); + } + JSONObject result = new JSONObject(); + result.put("class", classes); + try { + Elements list = doc.select("div.stui-pannel_bd ul.stui-vodlist li div.stui-vodlist__box"); + JSONArray videos = new JSONArray(); + for (int i = 0; i < list.size(); i++) { + Element vod = list.get(i); + Matcher matcher = regexVid.matcher(vod.selectFirst(".stui-vodlist__thumb").attr("href")); + if (!matcher.find()) + continue; + String title = vod.selectFirst(".title").text(); + String cover = vod.selectFirst(".stui-vodlist__thumb").attr("data-original"); + String remark = vod.selectFirst("span.pic-text").text(); + String id = matcher.group(1); + JSONObject v = new JSONObject(); + v.put("vod_id", id); + v.put("vod_name", title); + v.put("vod_pic", cover); + v.put("vod_remarks", remark); + videos.put(v); + } + result.put("list", videos); + } catch (Exception e) { + SpiderDebug.log(e); + } + return result.toString(); + } catch (Exception e) { + SpiderDebug.log(e); + } + return ""; + } + + /** + * 获取分类信息数据 + * + * @param tid 分类id + * @param pg 页数 + * @param filter 同homeContent方法中的filter + * @param extend 筛选参数{k:v, k1:v1} + * @return + */ + @Override + public String categoryContent(String tid, String pg, boolean filter, HashMap extend) { + try { + // 获取分类数据的url + String url = siteUrl + "/whole/" + tid + "/page/" + pg + ".html"; + String html = OkHttpUtil.string(url, getHeaders(url)); + Document doc = Jsoup.parse(html); + JSONObject result = new JSONObject(); + int pageCount = 0; + int page = -1; + + Elements pageInfo = doc.select(".stui-page li"); + if (pageInfo.size() == 0) { + page = Integer.parseInt(pg); + pageCount = page; + } else { + for (int i = 0; i < pageInfo.size(); i++) { + Element li = pageInfo.get(i); + Element a = li.selectFirst("a"); + if (a == null) + continue; + String name = a.text(); + if (page == -1 && li.hasClass("active")) { + Matcher matcher = regexPage.matcher(a.attr("href")); + if (matcher.find()) { + page = Integer.parseInt(matcher.group(1)); + } else { + page = 0; + } + } + if (name.equals("尾页")) { + Matcher matcher = regexPage.matcher(a.attr("href")); + if (matcher.find()) { + pageCount = Integer.parseInt(matcher.group(1)); + } else { + pageCount = 0; + } + break; + } + } + } + + JSONArray videos = new JSONArray(); + if (!html.contains("没有找到您想要的结果哦")) { + Elements list = doc.select("ul.stui-vodlist li div.stui-vodlist__box"); + for (int i = 0; i < list.size(); i++) { + Element vod = list.get(i); + String title = vod.selectFirst(".title").text(); + String cover = vod.selectFirst(".stui-vodlist__thumb").attr("data-original"); + String remark = vod.selectFirst("span.pic-text").text(); + Matcher matcher = regexVid.matcher(vod.selectFirst(".stui-vodlist__thumb").attr("href")); + if (!matcher.find()) + continue; + String id = matcher.group(1); + JSONObject v = new JSONObject(); + v.put("vod_id", id); + v.put("vod_name", title); + v.put("vod_pic", cover); + v.put("vod_remarks", remark); + videos.put(v); + } + } + result.put("page", page); + result.put("pagecount", pageCount); + result.put("limit", 30); + result.put("total", pageCount <= 1 ? videos.length() : pageCount * 30); + + result.put("list", videos); + return result.toString(); + } catch (Exception e) { + SpiderDebug.log(e); + } + return ""; + } + + /** + * 视频详情信息 + * + * @param ids 视频id + * @return + */ + @Override + public String detailContent(List ids) { + try { + // 视频详情url + String url = siteUrl + "/show/" + ids.get(0) + ".html"; + Document doc = Jsoup.parse(OkHttpUtil.string(url, getHeaders(url))); + JSONObject result = new JSONObject(); + JSONObject vodList = new JSONObject(); + + // 取基本数据 + String cover = doc.selectFirst("a.stui-vodlist__thumb img").attr("data-original"); + String title = doc.selectFirst("a.stui-vodlist__thumb").attr("title"); + String desc = Jsoup.parse(doc.selectFirst("meta[name=description]").attr("content")).text(); + String category = "", area = "", year = "", remark = "", director = "", actor = ""; + Elements span_text_muted = doc.select("div.stui-content__detail span.text-muted"); + for (int i = 0; i < span_text_muted.size(); i++) { + Element text = span_text_muted.get(i); + String info = text.text(); + if (info.equals("类型:")) { + category = text.nextSibling().outerHtml().trim(); + } else if (info.equals("年份:")) { + year = text.nextSibling().outerHtml().trim(); + } else if (info.equals("地区:")) { + area = text.nextSibling().outerHtml().trim(); + } else if (info.equals("更新:")) { + remark = text.nextSibling().outerHtml().trim(); + } else if (info.equals("导演:")) { + director = text.nextSibling().outerHtml().trim(); + } else if (info.equals("主演:")) { + actor = text.nextSibling().outerHtml().trim(); + } + } + + vodList.put("vod_id", ids.get(0)); + vodList.put("vod_name", title); + vodList.put("vod_pic", cover); + vodList.put("type_name", category); + vodList.put("vod_year", year); + vodList.put("vod_area", area); + vodList.put("vod_remarks", remark); + vodList.put("vod_actor", actor); + vodList.put("vod_director", director); + vodList.put("vod_content", desc); + + Map vod_play = new TreeMap<>(new Comparator() { + @Override + public int compare(String o1, String o2) { + try { + int sort1 = playerConfig.getJSONObject(o1).getInt("or"); + int sort2 = playerConfig.getJSONObject(o2).getInt("or"); + + if (sort1 == sort2) { + return 1; + } + return sort1 - sort2 > 0 ? 1 : -1; + } catch (JSONException e) { + SpiderDebug.log(e); + } + return 1; + } + }); + + Elements sources = doc.select("div.playlist"); + + for (int i = 0; i < sources.size(); i++) { + Element source = sources.get(i); + String sourceName = source.selectFirst("h3.title").text().trim(); + String tabHref = source.attr("href"); + boolean found = false; + for (Iterator it = playerConfig.keys(); it.hasNext(); ) { + String flag = it.next(); + if (playerConfig.getJSONObject(flag).getString("sh").equals(sourceName)) { + sourceName = flag; + found = true; + break; + } + } + if (!found) + continue; + String playList = ""; + Elements playListA = source.select("ul.stui-content__playlist > li > a"); + List vodItems = new ArrayList<>(); + + for (int j = 0; j < playListA.size(); j++) { + Element vod = playListA.get(j); + Matcher matcher = regexPlay.matcher(vod.attr("href")); + if (!matcher.find()) + continue; + String playURL = matcher.group(1) + "-" + matcher.group(2) + "-" + matcher.group(3); + vodItems.add(vod.text() + "$" + playURL); + } + if (vodItems.size() > 0) + playList = TextUtils.join("#", vodItems); + + if (playList.length() == 0) + continue; + + vod_play.put(sourceName, playList); + } + + if (vod_play.size() > 0) { + String vod_play_from = TextUtils.join("$$$", vod_play.keySet()); + String vod_play_url = TextUtils.join("$$$", vod_play.values()); + vodList.put("vod_play_from", vod_play_from); + vodList.put("vod_play_url", vod_play_url); + } + JSONArray list = new JSONArray(); + list.put(vodList); + result.put("list", list); + return result.toString(); + } catch (Exception e) { + SpiderDebug.log(e); + } + return ""; + } + + /** + * 获取视频播放信息 + * + * @param flag 播放源 + * @param id 视频id + * @param vipFlags 所有可能需要vip解析的源 + * @return + */ + @Override + public String playerContent(String flag, String id, List vipFlags) { + try { + // 播放页 url + String url = "http://1090ys8.com/play/" + id + ".html"; + Document doc = Jsoup.parse(OkHttpUtil.string(url, getHeaders(url))); + Elements allScript = doc.select("script"); + JSONObject result = new JSONObject(); + for (int i = 0; i < allScript.size(); i++) { + String scContent = allScript.get(i).html().trim(); + if (scContent.startsWith("var player_")) { + int start = scContent.indexOf('{'); + int end = scContent.lastIndexOf('}') + 1; + String json = scContent.substring(start, end); + JSONObject player = new JSONObject(json); + if (playerConfig.has(player.getString("from"))) { + JSONObject pCfg = playerConfig.getJSONObject(player.getString("from")); + String videoUrl = player.getString("url"); + String playUrl = pCfg.getString("pu"); + String from = player.getString("from"); + if (from.equals("youbo")) { + // 感谢猫大神的直连解密代码 + HashMap hds = getHeaders(url); + hds.put("Host", "jx1090ys5.hongfanedu.top"); + hds.put("Referer", url); + String content1 = OkHttpUtil.string(playUrl + videoUrl, hds); + Document doc1 = Jsoup.parse(content1); + String url2 = doc1.selectFirst("iframe#WANG").attr("src"); + String url2host = Uri.parse(url2).getHost(); + hds.put("Host", url2host); + hds.put("Referer", "http://jx1090ys5.hongfanedu.top/"); + String content2 = OkHttpUtil.string(url2, hds); + String finder = "var id=\""; + start = content2.indexOf(finder) + finder.length(); + end = content2.indexOf('\"', start); + String vvid = content2.substring(start, end); + finder = "var sk=\""; + start = content2.indexOf(finder) + finder.length(); + end = content2.indexOf('\"', start); + String skey = content2.substring(start, end); + finder = "var pt=\""; + start = content2.indexOf(finder) + finder.length(); + end = content2.indexOf('\"', start); + String pt = content2.substring(start, end); + finder = "var ti=\""; + start = content2.indexOf(finder) + finder.length(); + end = content2.indexOf('\"', start); + String time = content2.substring(start, end); + int bkn = 0x195c; + for (int j = 0x0, all = skey.length(); all > j; ++j) { + bkn += ((bkn << 5) + (byte) skey.charAt(j)); + } + bkn = 0x7fffffff & bkn; + int gtk1 = 0x0; + for (int j = 0x0; j < pt.length(); j += 0x4) { + gtk1 += Integer.parseInt(String.format("%c%c%c%c", pt.charAt(j), pt.charAt(j + 0x1), pt.charAt(j + 0x2), pt.charAt(j + 0x3)), 0x10); + gtk1 %= 0x400a; + } + int offset = gtk1 % 10; + int gtk = 0x0; + for (int j = 0x0; j < pt.length(); j++) { + gtk += ((byte) pt.charAt(j)) * (j + offset); + gtk %= gtk1; + } + String finalVideoUrl = "http://" + url2host + "/hls/play/" + vvid + "%7C" + time + "%7C" + skey + "%7C" + pt + "%7C" + bkn + "%7C" + gtk + ".m3u8"; + result.put("parse", pCfg.getInt("sn")); + result.put("playUrl", ""); + result.put("url", finalVideoUrl); + result.put("header", "{\"Referer\":\" " + url2 + "\"}"); + } else { + result.put("parse", pCfg.getInt("sn")); + result.put("playUrl", playUrl); + result.put("url", videoUrl); + result.put("header", ""); + } + } + break; + } + } + return result.toString(); + } catch (Exception e) { + SpiderDebug.log(e); + } + return ""; + } + + /** + * 搜索 + * + * @param key + * @param quick 是否播放页的快捷搜索 + * @return + */ + @Override + public String searchContent(String key, boolean quick) { + try { + long currentTime = System.currentTimeMillis(); + String url = siteUrl + "/index.php/ajax/suggest?mid=1&wd=" + URLEncoder.encode(key) + "&limit=10×tamp=" + currentTime; + JSONObject searchResult = new JSONObject(OkHttpUtil.string(url, getHeaders(url))); + JSONObject result = new JSONObject(); + JSONArray videos = new JSONArray(); + if (searchResult.getInt("total") > 0) { + JSONArray lists = new JSONArray(searchResult.getString("list")); + for (int i = 0; i < lists.length(); i++) { + JSONObject vod = lists.getJSONObject(i); + String id = vod.getString("id"); + String title = vod.getString("name"); + String cover = vod.getString("pic"); + JSONObject v = new JSONObject(); + v.put("vod_id", id); + v.put("vod_name", title); + v.put("vod_pic", cover); + v.put("vod_remarks", ""); + videos.put(v); + } + } + result.put("list", videos); + return result.toString(); + } catch (Exception e) { + SpiderDebug.log(e); + } + return ""; + } +} diff --git a/app/src/main/java/com/github/catvod/spider/Nekk.java b/app/src/main/java/com/github/catvod/spider/Nekk.java new file mode 100644 index 0000000..1c21002 --- /dev/null +++ b/app/src/main/java/com/github/catvod/spider/Nekk.java @@ -0,0 +1,489 @@ +package com.github.catvod.spider; + +import android.content.Context; +import android.text.TextUtils; +import android.util.Base64; + +import com.github.catvod.crawler.Spider; +import com.github.catvod.crawler.SpiderDebug; +import com.github.catvod.utils.okhttp.OKCallBack; +import com.github.catvod.utils.okhttp.OkHttpUtil; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.net.URLEncoder; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import okhttp3.Call; +import okhttp3.Headers; +import okhttp3.Response; + + +public class Nekk extends Spider { + + private static final String siteUrl = "https://www.9ela.com"; + private static final String siteHost = "www.9ela.com"; + + protected JSONObject playerConfig; + protected JSONObject filterConfig; + + protected Pattern regexCategory = Pattern.compile("/vodshow/(\\S+).html"); + protected Pattern regexVid = Pattern.compile("/voddetail/(\\d+).html"); + protected Pattern regexPlay = Pattern.compile("/vodplay/(\\d+)-(\\d+)-(\\d+).html"); + protected Pattern regexPage = Pattern.compile("\\S+/page/(\\d+)\\S+"); + + @Override + public void init(Context context) { + super.init(context); + try { + playerConfig = new JSONObject("{\"9ekk\":{\"sh\":\"手机线路\",\"sn\":0,\"pu\":\"\",\"or\":999},\"ttee\":{\"sh\":\"9亿超清\",\"sn\":0,\"pu\":\"\",\"or\":999},\"9999ku\":{\"sh\":\"手机线路2\",\"sn\":0,\"pu\":\"\",\"or\":999},\"gsyun\":{\"sh\":\"九亿超清\",\"sn\":0,\"pu\":\"\",\"or\":999},\"kkyun\":{\"sh\":\"HD超清线路\",\"sn\":0,\"pu\":\"\",\"or\":999},\"ty01\":{\"sh\":\"超清线路\",\"sn\":0,\"pu\":\"\",\"or\":999},\"ppayun\":{\"sh\":\"九亿线路\",\"sn\":0,\"pu\":\"https://wy.mlkioiy.cn/api/GetDownUrlWy/d91ea50eb7eb4932b92aa8bb3c61560d/\",\"or\":999},\"8kdm\":{\"sh\":\"九亿动漫\",\"sn\":0,\"pu\":\"\",\"or\":999},\"jsyun\":{\"sh\":\"九亿备用\",\"sn\":0,\"pu\":\"\",\"or\":999},\"9evip\":{\"sh\":\"九亿解析-弃用\",\"sn\":0,\"pu\":\"\",\"or\":999},\"189pan\":{\"sh\":\"九亿超清11\",\"sn\":0,\"pu\":\"http://1987s.com/api/dp.php?url=\",\"or\":999},\"VIP\":{\"sh\":\"VIP线路\",\"sn\":0,\"pu\":\"\",\"or\":999},\"qq\":{\"sh\":\"九亿解析\",\"sn\":1,\"pu\":\"\",\"or\":999},\"mgtv\":{\"sh\":\"九亿解析\",\"sn\":1,\"pu\":\"\",\"or\":999},\"bjm3u8\":{\"sh\":\"线路三\",\"sn\":0,\"pu\":\"\",\"or\":999},\"dbm3u8\":{\"sh\":\"线路四\",\"sn\":0,\"pu\":\"\",\"or\":999},\"ckm3u8\":{\"sh\":\"线路二\",\"sn\":0,\"pu\":\"\",\"or\":999},\"mahua\":{\"sh\":\"线路四\",\"sn\":0,\"pu\":\"\",\"or\":999},\"123kum3u8\":{\"sh\":\"123kum3u8\",\"sn\":1,\"pu\":\"https://jx.123ku.com/123kudpbfq/?url=\",\"or\":999},\"pqc\":{\"sh\":\"测试\",\"sn\":1,\"pu\":\"https://jx.qiuzeqi.top/jx1/dp/index.php?url=\",\"or\":999},\"test\":{\"sh\":\"test\",\"sn\":1,\"pu\":\"https//1987s.com/api/dp.php?url=\",\"or\":999}}"); + filterConfig = new JSONObject("{\"dianying\":[{\"key\":\"tid\",\"name\":\"类型\",\"value\":[{\"n\":\"全部\",\"v\":\"\"},{\"n\":\"国语配音电影\",\"v\":\"gypy\"},{\"n\":\"最近热播电影\",\"v\":\"zuijinrebodianying\"},{\"n\":\"动作片\",\"v\":\"dongzuopian\"},{\"n\":\"喜剧片\",\"v\":\"xijupian\"},{\"n\":\"爱情片\",\"v\":\"aiqingpian\"},{\"n\":\"科幻片\",\"v\":\"kehuanpian\"},{\"n\":\"恐怖片\",\"v\":\"kongbupian\"},{\"n\":\"剧情片\",\"v\":\"juqingpian\"},{\"n\":\"战争片\",\"v\":\"zhanzhengpian\"}]},{\"key\":\"class\",\"name\":\"剧情\",\"value\":[{\"n\":\"全部\",\"v\":\"\"},{\"n\":\"喜剧\",\"v\":\"喜剧\"},{\"n\":\"爱情\",\"v\":\"爱情\"},{\"n\":\"恐怖\",\"v\":\"恐怖\"},{\"n\":\"动作\",\"v\":\"动作\"},{\"n\":\"科幻\",\"v\":\"科幻\"},{\"n\":\"剧情\",\"v\":\"剧情\"},{\"n\":\"战争\",\"v\":\"战争\"},{\"n\":\"警匪\",\"v\":\"警匪\"},{\"n\":\"犯罪\",\"v\":\"犯罪\"},{\"n\":\"动画\",\"v\":\"动画\"},{\"n\":\"奇幻\",\"v\":\"奇幻\"},{\"n\":\"武侠\",\"v\":\"武侠\"},{\"n\":\"冒险\",\"v\":\"冒险\"},{\"n\":\"枪战\",\"v\":\"枪战\"},{\"n\":\"恐怖\",\"v\":\"恐怖\"},{\"n\":\"悬疑\",\"v\":\"悬疑\"},{\"n\":\"惊悚\",\"v\":\"惊悚\"},{\"n\":\"经典\",\"v\":\"经典\"},{\"n\":\"青春\",\"v\":\"青春\"},{\"n\":\"文艺\",\"v\":\"文艺\"},{\"n\":\"微电影\",\"v\":\"微电影\"},{\"n\":\"古装\",\"v\":\"古装\"},{\"n\":\"历史\",\"v\":\"历史\"},{\"n\":\"运动\",\"v\":\"运动\"},{\"n\":\"农村\",\"v\":\"农村\"},{\"n\":\"儿童\",\"v\":\"儿童\"},{\"n\":\"网络电影\",\"v\":\"网络电影\"}]},{\"key\":\"area\",\"name\":\"地区\",\"value\":[{\"n\":\"全部\",\"v\":\"\"},{\"n\":\"中国大陆\",\"v\":\"中国大陆\"},{\"n\":\"中国香港\",\"v\":\"中国香港\"},{\"n\":\"中国台湾\",\"v\":\"中国台湾\"},{\"n\":\"美国\",\"v\":\"美国\"},{\"n\":\"法国\",\"v\":\"法国\"},{\"n\":\"英国\",\"v\":\"英国\"},{\"n\":\"日本\",\"v\":\"日本\"},{\"n\":\"韩国\",\"v\":\"韩国\"},{\"n\":\"德国\",\"v\":\"德国\"},{\"n\":\"泰国\",\"v\":\"泰国\"},{\"n\":\"印度\",\"v\":\"印度\"},{\"n\":\"意大利\",\"v\":\"意大利\"},{\"n\":\"西班牙\",\"v\":\"西班牙\"},{\"n\":\"加拿大\",\"v\":\"加拿大\"},{\"n\":\"其他\",\"v\":\"其他\"},{\"n\":\"热门\",\"v\":\"热门\"}]},{\"key\":\"year\",\"name\":\"年份\",\"value\":[{\"n\":\"全部\",\"v\":\"\"},{\"n\":\"2021\",\"v\":\"2021\"},{\"n\":\"2020\",\"v\":\"2020\"},{\"n\":\"2019\",\"v\":\"2019\"},{\"n\":\"2018\",\"v\":\"2018\"},{\"n\":\"2017\",\"v\":\"2017\"},{\"n\":\"2016\",\"v\":\"2016\"},{\"n\":\"2015\",\"v\":\"2015\"},{\"n\":\"2014\",\"v\":\"2014\"},{\"n\":\"2013\",\"v\":\"2013\"},{\"n\":\"2012\",\"v\":\"2012\"},{\"n\":\"2011\",\"v\":\"2011\"},{\"n\":\"2010\",\"v\":\"2010\"}]},{\"key\":\"by\",\"name\":\"排序\",\"value\":[{\"n\":\"时间\",\"v\":\"\"},{\"n\":\"人气\",\"v\":\"hits\"},{\"n\":\"评分\",\"v\":\"score\"}]}],\"lianxuju\":[{\"key\":\"tid\",\"name\":\"类型\",\"value\":[{\"n\":\"全部\",\"v\":\"\"},{\"n\":\"最近热播电视剧\",\"v\":\"zuijinrebodianshiju\"},{\"n\":\"国语配音剧集\",\"v\":\"guoyupeiyinhanju\"},{\"n\":\"热播美剧\",\"v\":\"rebomeiju\"},{\"n\":\"电视剧\",\"v\":\"guochanju\"},{\"n\":\"港台剧\",\"v\":\"gangtaiju\"},{\"n\":\"日韩剧\",\"v\":\"rihanju\"},{\"n\":\"欧美剧\",\"v\":\"oumeiju\"}]},{\"key\":\"class\",\"name\":\"剧情\",\"value\":[{\"n\":\"全部\",\"v\":\"\"},{\"n\":\"古装\",\"v\":\"古装\"},{\"n\":\"战争\",\"v\":\"战争\"},{\"n\":\"青春偶像\",\"v\":\"青春偶像\"},{\"n\":\"喜剧\",\"v\":\"喜剧\"},{\"n\":\"家庭\",\"v\":\"家庭\"},{\"n\":\"犯罪\",\"v\":\"犯罪\"},{\"n\":\"动作\",\"v\":\"动作\"},{\"n\":\"奇幻\",\"v\":\"奇幻\"},{\"n\":\"剧情\",\"v\":\"剧情\"},{\"n\":\"历史\",\"v\":\"历史\"},{\"n\":\"经典\",\"v\":\"经典\"},{\"n\":\"乡村\",\"v\":\"乡村\"},{\"n\":\"情景\",\"v\":\"情景\"},{\"n\":\"商战\",\"v\":\"商战\"},{\"n\":\"网剧\",\"v\":\"网剧\"},{\"n\":\"其他\",\"v\":\"其他\"}]},{\"key\":\"area\",\"name\":\"地区\",\"value\":[{\"n\":\"全部\",\"v\":\"\"},{\"n\":\"中国大陆\",\"v\":\"中国大陆\"},{\"n\":\"韩国\",\"v\":\"韩国\"},{\"n\":\"香港\",\"v\":\"香港\"},{\"n\":\"台湾\",\"v\":\"台湾\"},{\"n\":\"日本\",\"v\":\"日本\"},{\"n\":\"美国\",\"v\":\"美国\"},{\"n\":\"泰国\",\"v\":\"泰国\"},{\"n\":\"英国\",\"v\":\"英国\"},{\"n\":\"新加坡\",\"v\":\"新加坡\"},{\"n\":\"其他\",\"v\":\"其他\"}]},{\"key\":\"year\",\"name\":\"年份\",\"value\":[{\"n\":\"全部\",\"v\":\"\"},{\"n\":\"2021\",\"v\":\"2021\"},{\"n\":\"2020\",\"v\":\"2020\"},{\"n\":\"2019\",\"v\":\"2019\"},{\"n\":\"2018\",\"v\":\"2018\"},{\"n\":\"2017\",\"v\":\"2017\"},{\"n\":\"2016\",\"v\":\"2016\"},{\"n\":\"2015\",\"v\":\"2015\"},{\"n\":\"2014\",\"v\":\"2014\"},{\"n\":\"2013\",\"v\":\"2013\"},{\"n\":\"2012\",\"v\":\"2012\"},{\"n\":\"2011\",\"v\":\"2011\"},{\"n\":\"2010\",\"v\":\"2010\"},{\"n\":\"2009\",\"v\":\"2009\"},{\"n\":\"2008\",\"v\":\"2008\"},{\"n\":\"2007\",\"v\":\"2007\"},{\"n\":\"2006\",\"v\":\"2006\"},{\"n\":\"2005\",\"v\":\"2005\"},{\"n\":\"2004\",\"v\":\"2004\"}]},{\"key\":\"by\",\"name\":\"排序\",\"value\":[{\"n\":\"时间\",\"v\":\"\"},{\"n\":\"人气\",\"v\":\"hits\"},{\"n\":\"评分\",\"v\":\"score\"}]}],\"zongyi\":[{\"key\":\"class\",\"name\":\"剧情\",\"value\":[{\"n\":\"全部\",\"v\":\"\"},{\"n\":\"选秀\",\"v\":\"选秀\"},{\"n\":\"情感\",\"v\":\"情感\"},{\"n\":\"访谈\",\"v\":\"访谈\"},{\"n\":\"播报\",\"v\":\"播报\"},{\"n\":\"旅游\",\"v\":\"旅游\"},{\"n\":\"音乐\",\"v\":\"音乐\"},{\"n\":\"美食\",\"v\":\"美食\"},{\"n\":\"纪实\",\"v\":\"纪实\"},{\"n\":\"曲艺\",\"v\":\"曲艺\"},{\"n\":\"生活\",\"v\":\"生活\"},{\"n\":\"游戏互动\",\"v\":\"游戏互动\"},{\"n\":\"财经\",\"v\":\"财经\"},{\"n\":\"求职\",\"v\":\"求职\"}]},{\"key\":\"area\",\"name\":\"地区\",\"value\":[{\"n\":\"全部\",\"v\":\"\"},{\"n\":\"中国大陆\",\"v\":\"中国大陆\"},{\"n\":\"大陆\",\"v\":\"大陆\"},{\"n\":\"港台\",\"v\":\"港台\"},{\"n\":\"日韩\",\"v\":\"日韩\"},{\"n\":\"欧美\",\"v\":\"欧美\"}]},{\"key\":\"year\",\"name\":\"年份\",\"value\":[{\"n\":\"全部\",\"v\":\"\"},{\"n\":\"2021\",\"v\":\"2021\"},{\"n\":\"2020\",\"v\":\"2020\"},{\"n\":\"2019\",\"v\":\"2019\"},{\"n\":\"2018\",\"v\":\"2018\"},{\"n\":\"2017\",\"v\":\"2017\"},{\"n\":\"2016\",\"v\":\"2016\"},{\"n\":\"2015\",\"v\":\"2015\"},{\"n\":\"2014\",\"v\":\"2014\"},{\"n\":\"2013\",\"v\":\"2013\"},{\"n\":\"2012\",\"v\":\"2012\"},{\"n\":\"2011\",\"v\":\"2011\"},{\"n\":\"2010\",\"v\":\"2010\"},{\"n\":\"2009\",\"v\":\"2009\"},{\"n\":\"2008\",\"v\":\"2008\"},{\"n\":\"2007\",\"v\":\"2007\"},{\"n\":\"2006\",\"v\":\"2006\"},{\"n\":\"2005\",\"v\":\"2005\"},{\"n\":\"2004\",\"v\":\"2004\"}]},{\"key\":\"by\",\"name\":\"排序\",\"value\":[{\"n\":\"时间\",\"v\":\"\"},{\"n\":\"人气\",\"v\":\"hits\"},{\"n\":\"评分\",\"v\":\"score\"}]}],\"dongman\":[{\"key\":\"class\",\"name\":\"剧情\",\"value\":[{\"n\":\"全部\",\"v\":\"\"},{\"n\":\"情感\",\"v\":\"情感\"},{\"n\":\"科幻\",\"v\":\"科幻\"},{\"n\":\"热血\",\"v\":\"热血\"},{\"n\":\"推理\",\"v\":\"推理\"},{\"n\":\"搞笑\",\"v\":\"搞笑\"},{\"n\":\"冒险\",\"v\":\"冒险\"},{\"n\":\"萝莉\",\"v\":\"萝莉\"},{\"n\":\"校园\",\"v\":\"校园\"},{\"n\":\"动作\",\"v\":\"动作\"},{\"n\":\"机战\",\"v\":\"机战\"},{\"n\":\"运动\",\"v\":\"运动\"},{\"n\":\"战争\",\"v\":\"战争\"},{\"n\":\"少年\",\"v\":\"少年\"},{\"n\":\"少女\",\"v\":\"少女\"},{\"n\":\"社会\",\"v\":\"社会\"},{\"n\":\"原创\",\"v\":\"原创\"},{\"n\":\"亲子\",\"v\":\"亲子\"},{\"n\":\"益智\",\"v\":\"益智\"},{\"n\":\"励志\",\"v\":\"励志\"},{\"n\":\"其他\",\"v\":\"其他\"}]},{\"key\":\"area\",\"name\":\"地区\",\"value\":[{\"n\":\"全部\",\"v\":\"\"},{\"n\":\"国产\",\"v\":\"国产\"},{\"n\":\"日本\",\"v\":\"日本\"},{\"n\":\"欧美\",\"v\":\"欧美\"},{\"n\":\"其他\",\"v\":\"其他\"}]},{\"key\":\"year\",\"name\":\"年份\",\"value\":[{\"n\":\"全部\",\"v\":\"\"},{\"n\":\"2021\",\"v\":\"2021\"},{\"n\":\"2020\",\"v\":\"2020\"},{\"n\":\"2019\",\"v\":\"2019\"},{\"n\":\"2018\",\"v\":\"2018\"},{\"n\":\"2017\",\"v\":\"2017\"},{\"n\":\"2016\",\"v\":\"2016\"},{\"n\":\"2015\",\"v\":\"2015\"},{\"n\":\"2014\",\"v\":\"2014\"},{\"n\":\"2013\",\"v\":\"2013\"},{\"n\":\"2012\",\"v\":\"2012\"},{\"n\":\"2011\",\"v\":\"2011\"},{\"n\":\"2010\",\"v\":\"2010\"},{\"n\":\"2009\",\"v\":\"2009\"},{\"n\":\"2008\",\"v\":\"2008\"},{\"n\":\"2007\",\"v\":\"2007\"},{\"n\":\"2006\",\"v\":\"2006\"},{\"n\":\"2005\",\"v\":\"2005\"},{\"n\":\"2004\",\"v\":\"2004\"}]},{\"key\":\"by\",\"name\":\"排序\",\"value\":[{\"n\":\"时间\",\"v\":\"\"},{\"n\":\"人气\",\"v\":\"hits\"},{\"n\":\"评分\",\"v\":\"score\"}]}]}"); + } catch (JSONException e) { + SpiderDebug.log(e); + } + } + + /** + * 爬虫headers + * + * @param url + * @return + */ + protected HashMap getHeaders(String url) { + HashMap headers = new HashMap<>(); + headers.put("method", "GET"); + headers.put("Host", siteHost); + headers.put("Upgrade-Insecure-Requests", "1"); + headers.put("DNT", "1"); + headers.put("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.54 Safari/537.36"); + headers.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"); + headers.put("Accept-Language", "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2"); + return headers; + } + + + @Override + public String homeContent(boolean filter) { + try { + String url = siteUrl + '/'; + Document doc = Jsoup.parse(OkHttpUtil.string(url, getHeaders(url))); + Elements elements = doc.select("ul.nav-list > li a"); + JSONArray classes = new JSONArray(); + ArrayList allClass = new ArrayList<>(); + for (Element ele : elements) { + String name = ele.text(); + boolean show = !filter || (name.equals("电影") || name.equals("连续剧") || name.equals("综艺") || name.equals("动漫")); + if (allClass.contains(name)) + show = false; + if (show) { + allClass.add(name); + Matcher mather = regexCategory.matcher(ele.attr("href")); + if (!mather.find()) + continue; + String id = mather.group(1).trim(); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("type_id", id); + jsonObject.put("type_name", name); + classes.put(jsonObject); + } + } + JSONObject result = new JSONObject(); + if (filter) { + result.put("filters", filterConfig); + } + result.put("class", classes); + try { + Elements list = doc.select("div.col-lg-wide-75 > ul.myui-vodlist li div.myui-vodlist__box"); + JSONArray videos = new JSONArray(); + for (int i = 0; i < list.size(); i++) { + Element vod = list.get(i); + String title = vod.selectFirst(".title").text(); + String cover = fixCover(vod.selectFirst(".myui-vodlist__thumb").attr("data-original")); + String remark = vod.selectFirst("span.pic-text").text(); + + Matcher matcher = regexVid.matcher(vod.selectFirst(".myui-vodlist__thumb").attr("href")); + if (!matcher.find()) + continue; + String id = matcher.group(1); + JSONObject v = new JSONObject(); + v.put("vod_id", id); + v.put("vod_name", title); + v.put("vod_pic", cover); + v.put("vod_remarks", remark); + videos.put(v); + } + result.put("list", videos); + } catch (Exception e) { + SpiderDebug.log(e); + } + return result.toString(); + } catch (Exception e) { + SpiderDebug.log(e); + } + return ""; + } + + @Override + public String categoryContent(String tid, String pg, boolean filter, HashMap extend) { + try { + String url = siteUrl + "/vodshow/"; + if (extend != null && extend.size() > 0 && extend.containsKey("tid") && extend.get("tid").length() > 0) { + url += extend.get("tid"); + } else { + url += tid; + } + if (extend != null && extend.size() > 0) { + for (Iterator it = extend.keySet().iterator(); it.hasNext(); ) { + String key = it.next(); + String value = extend.get(key); + if (value.length() > 0) { + url += "/" + key + "/" + URLEncoder.encode(value); + } + } + } + url += "/page/" + pg + ".html"; + String html = OkHttpUtil.string(url, getHeaders(url)); + Document doc = Jsoup.parse(html); + JSONObject result = new JSONObject(); + int pageCount = 0; + int page = -1; + + Elements pageInfo = doc.select(".myui-page li a"); + if (pageInfo.size() == 0) { + page = Integer.parseInt(pg); + pageCount = page; + } else { + for (int i = 0; i < pageInfo.size(); i++) { + Element a = pageInfo.get(i); + String name = a.text(); + if (page == -1 && a.hasClass("btn-warm")) { + Matcher matcher = regexPage.matcher(a.attr("href")); + if (matcher.find()) { + page = Integer.parseInt(matcher.group(1).trim()); + } else { + page = 0; + } + } + if (name.equals("尾页")) { + Matcher matcher = regexPage.matcher(a.attr("href")); + if (matcher.find()) { + pageCount = Integer.parseInt(matcher.group(1).trim()); + } else { + pageCount = 0; + } + break; + } + } + } + + JSONArray videos = new JSONArray(); + if (!html.contains("没有找到您想要的结果哦")) { + Elements list = doc.select("ul.myui-vodlist li div.myui-vodlist__box"); + for (int i = 0; i < list.size(); i++) { + Element vod = list.get(i); + String title = vod.selectFirst(".title").text(); + String cover = fixCover(vod.selectFirst(".myui-vodlist__thumb").attr("data-original")); + String remark = vod.selectFirst("span.pic-text").text(); + + Matcher matcher = regexVid.matcher(vod.selectFirst(".myui-vodlist__thumb").attr("href")); + if (!matcher.find()) + continue; + String id = matcher.group(1); + JSONObject v = new JSONObject(); + v.put("vod_id", id); + v.put("vod_name", title); + v.put("vod_pic", cover); + v.put("vod_remarks", remark); + videos.put(v); + } + } + result.put("page", page); + result.put("pagecount", pageCount); + result.put("limit", 48); + result.put("total", pageCount <= 1 ? videos.length() : pageCount * 48); + + result.put("list", videos); + return result.toString(); + } catch (Exception e) { + SpiderDebug.log(e); + } + return ""; + } + + @Override + public String detailContent(List ids) { + try { + String url = siteUrl + "/voddetail/" + ids.get(0) + ".html"; + Document doc = Jsoup.parse(OkHttpUtil.string(url, getHeaders(url))); + JSONObject result = new JSONObject(); + JSONObject vodList = new JSONObject(); + + String vid = doc.selectFirst("span.mac_hits").attr("data-id"); + + String cover = fixCover(doc.selectFirst("a.myui-vodlist__thumb img").attr("data-original")); + String title = doc.selectFirst("div.myui-content__detail h1.title").text(); + String desc = Jsoup.parse(doc.selectFirst("meta[name=description]").attr("content")).text(); + String category = "", area = "", year = "", remark = "", director = "", actor = ""; + Elements span_text_muted = doc.select("div.myui-content__detail span.text-muted"); + for (int i = 0; i < span_text_muted.size(); i++) { + Element text = span_text_muted.get(i); + String info = text.text(); + if (info.equals("分类:")) { + category = text.nextElementSibling().text(); + } else if (info.equals("年份:")) { + year = text.nextElementSibling().text(); + } else if (info.equals("地区:")) { + area = text.nextElementSibling().text(); + } else if (info.equals("更新:")) { + remark = text.nextElementSibling().text(); + } else if (info.equals("导演:")) { + List directors = new ArrayList<>(); + Elements aa = text.parent().select("a"); + for (int j = 0; j < aa.size(); j++) { + directors.add(aa.get(j).text()); + } + director = TextUtils.join(",", directors); + } else if (info.equals("主演:")) { + List actors = new ArrayList<>(); + Elements aa = text.parent().select("a"); + for (int j = 0; j < aa.size(); j++) { + actors.add(aa.get(j).text()); + } + actor = TextUtils.join(",", actors); + } + } + + vodList.put("vod_id", vid); + vodList.put("vod_name", title); + vodList.put("vod_pic", cover); + vodList.put("type_name", category); + vodList.put("vod_year", year); + vodList.put("vod_area", area); + vodList.put("vod_remarks", remark); + vodList.put("vod_actor", actor); + vodList.put("vod_director", director); + vodList.put("vod_content", desc); + + Map vod_play = new TreeMap<>(new Comparator() { + @Override + public int compare(String o1, String o2) { + try { + int sort1 = playerConfig.getJSONObject(o1).getInt("or"); + int sort2 = playerConfig.getJSONObject(o2).getInt("or"); + + if (sort1 == sort2) { + return 1; + } + return sort1 - sort2 > 0 ? 1 : -1; + } catch (JSONException e) { + SpiderDebug.log(e); + } + return 1; + } + }); + + Elements sources = doc.select("a[data-toggle=tab]"); + + for (int i = 0; i < sources.size(); i++) { + Element source = sources.get(i); + String sourceName = source.text(); + String tabHref = source.attr("href"); + boolean found = false; + for (Iterator it = playerConfig.keys(); it.hasNext(); ) { + String flag = it.next(); + if (playerConfig.getJSONObject(flag).getString("sh").equals(sourceName)) { + sourceName = flag; + found = true; + break; + } + } + if (!found) + continue; + String playList = ""; + Elements playListA = doc.select("div" + tabHref + " ul > li a"); + List vodItems = new ArrayList<>(); + + for (int j = 0; j < playListA.size(); j++) { + Element vod = playListA.get(j); + Matcher matcher = regexPlay.matcher(vod.attr("href")); + if (!matcher.find()) + continue; + String playURL = matcher.group(1) + "-" + matcher.group(2) + "-" + matcher.group(3); + vodItems.add(vod.text() + "$" + playURL); + } + if (vodItems.size() > 0) + playList = TextUtils.join("#", vodItems); + + if (playList.length() == 0) + continue; + + vod_play.put(sourceName, playList); + } + + if (vod_play.size() > 0) { + String vod_play_from = TextUtils.join("$$$", vod_play.keySet()); + String vod_play_url = TextUtils.join("$$$", vod_play.values()); + vodList.put("vod_play_from", vod_play_from); + vodList.put("vod_play_url", vod_play_url); + } + JSONArray list = new JSONArray(); + list.put(vodList); + result.put("list", list); + return result.toString(); + } catch (Exception e) { + SpiderDebug.log(e); + } + return ""; + } + + @Override + public String playerContent(String flag, String id, List vipFlags) { + try { + String url = siteUrl + "/vodplay/" + id + ".html"; + Document doc = Jsoup.parse(OkHttpUtil.string(url, getHeaders(url))); + Elements allScript = doc.select("script"); + JSONObject result = new JSONObject(); + for (int i = 0; i < allScript.size(); i++) { + String scContent = allScript.get(i).html().trim(); + if (scContent.startsWith("var player_")) { + int start = scContent.indexOf('{'); + int end = scContent.lastIndexOf('}') + 1; + String json = scContent.substring(start, end); + JSONObject player = new JSONObject(json); + if (playerConfig.has(player.getString("from"))) { + JSONObject pCfg = playerConfig.getJSONObject(player.getString("from")); + String videoUrl = player.getString("url"); + if (player.has("encrypt")) { + int encrypt = player.getInt("encrypt"); + if (encrypt == 1) { + videoUrl = URLDecoder.decode(videoUrl); + } else if (encrypt == 2) { + videoUrl = new String(Base64.decode(videoUrl, Base64.DEFAULT)); + videoUrl = URLDecoder.decode(videoUrl); + } + } + String playUrl = pCfg.getString("pu"); + result.put("parse", pCfg.getInt("sn")); + result.put("playUrl", playUrl); + result.put("url", videoUrl); + if (flag.equals("9ekk")) { + JSONObject headers = new JSONObject(); + headers.put("User-Agent", " Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.54 Safari/537.36"); + headers.put("Accept", " */*"); + headers.put("Connection", " keep-alive"); + result.put("header", headers.toString()); + } else { + result.put("header", ""); + } + } + break; + } + } + return result.toString(); + } catch (Exception e) { + SpiderDebug.log(e); + } + return ""; + } + + @Override + public String searchContent(String key, boolean quick) { + try { + if (quick) + return ""; + long currentTime = System.currentTimeMillis(); + String url = siteUrl + "/index.php/ajax/suggest?mid=1&wd=" + URLEncoder.encode(key) + "&limit=10×tamp=" + currentTime; + JSONObject searchResult = new JSONObject(OkHttpUtil.string(url, getHeaders(url))); + JSONObject result = new JSONObject(); + JSONArray videos = new JSONArray(); + if (searchResult.getInt("total") > 0) { + JSONArray lists = new JSONArray(searchResult.getString("list")); + for (int i = 0; i < lists.length(); i++) { + JSONObject vod = lists.getJSONObject(i); + String id = vod.getString("id"); + String title = vod.getString("name"); + String cover = fixCover(vod.getString("pic")); + JSONObject v = new JSONObject(); + v.put("vod_id", id); + v.put("vod_name", title); + v.put("vod_pic", cover); + v.put("vod_remarks", ""); + videos.put(v); + } + } + result.put("list", videos); + return result.toString(); + } catch (Exception e) { + SpiderDebug.log(e); + } + return ""; + } + + protected String fixCover(String cover) { + try { + return "proxy://do=nekk&pic=" + Base64.encodeToString(cover.getBytes("UTF-8"), Base64.DEFAULT | Base64.URL_SAFE | Base64.NO_WRAP); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return cover; + } + + private static HashMap nekkPicHeader = null; + + public static Object[] loadPic(String pic) { + try { + pic = new String(Base64.decode(pic, Base64.DEFAULT | Base64.URL_SAFE | Base64.NO_WRAP), "UTF-8"); + + if (nekkPicHeader == null) { + nekkPicHeader = new HashMap<>(); + nekkPicHeader.put("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.54 Safari/537.36"); + nekkPicHeader.put("referer", siteUrl + "/"); + } + OKCallBack.OKCallBackDefault callBack = new OKCallBack.OKCallBackDefault() { + @Override + protected void onFailure(Call call, Exception e) { + + } + + @Override + protected void onResponse(Response response) { + + } + }; + OkHttpUtil.get(OkHttpUtil.defaultClient(), pic, null, nekkPicHeader, callBack); + if (callBack.getResult().code() == 200) { + Headers headers = callBack.getResult().headers(); + String type = headers.get("Content-Type"); + if (type == null) { + type = "application/octet-stream"; + } + Object[] result = new Object[3]; + result[0] = 200; + result[1] = type; + System.out.println(pic); + System.out.println(type); + result[2] = callBack.getResult().body().byteStream(); + return result; + } + } catch (Throwable th) { + th.printStackTrace(); + } + return null; + } +} diff --git a/app/src/main/java/com/github/catvod/spider/Nfx.java b/app/src/main/java/com/github/catvod/spider/Nfx.java new file mode 100644 index 0000000..ed70d51 --- /dev/null +++ b/app/src/main/java/com/github/catvod/spider/Nfx.java @@ -0,0 +1,449 @@ +package com.github.catvod.spider; + +import android.content.Context; +import android.text.TextUtils; + +import com.github.catvod.crawler.Spider; +import com.github.catvod.crawler.SpiderDebug; +import com.github.catvod.utils.okhttp.OkHttpUtil; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; + +import java.net.URLEncoder; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Demo for self study + *

+ * Source from Author: CatVod + */ + +public class Nfx extends Spider { + + private static final String siteUrl = "https://nfxhd.com/"; + private static final String siteHost = "nfxhd.com"; + + protected JSONObject playerConfig; + + protected Pattern regexCategory = Pattern.compile("/vodtype/(\\w+)/"); + protected Pattern regexVid = Pattern.compile("/voddetail/(\\w+)/"); + protected Pattern regexPlay = Pattern.compile("/vodplay/(\\w+)-(\\d+)-(\\d+)/"); + protected Pattern regexPage = Pattern.compile("/vodshow/(\\S+)/"); + + @Override + public void init(Context context) { + super.init(context); + try { + playerConfig = new JSONObject("{\"adaplay\":{\"sh\":\"菜逼播放器\",\"sn\":\"1\",\"pu\":\"https://nfxhd.com/dp.php/?url=\",\"or\":999},\"xigua\":{\"sh\":\"手动点播放才能播放的播放器\",\"sn\":\"1\",\"pu\":\"https://nfxhd.com/dp.php/?url=\",\"or\":999},\"danmuku\":{\"sh\":\"海王播放器\",\"sn\":\"1\",\"pu\":\"\",\"or\":999},\"dplayer\":{\"sh\":\"冥王星播放器\",\"sn\":\"0\",\"pu\":\"\",\"or\":999},\"bdxm3u8\":{\"sh\":\"北斗星m3u8\",\"sn\":\"1\",\"pu\":\"https://player.bdxzym3u8.com/dplayer/?url=\",\"or\":999},\"bdxyun\":{\"sh\":\"北斗星云播放\",\"sn\":\"1\",\"pu\":\"\",\"or\":999},\"gangtiexia\":{\"sh\":\"土星播放器\",\"sn\":\"1\",\"pu\":\"https://wy.bigmao.top/api/ShowVideoWy/3bb24322f78b47dfb8723c13d46d45ee/\",\"or\":999},\"tt10\":{\"sh\":\"木星播放器\",\"sn\":\"1\",\"pu\":\"https://wy.bigmao.top/api/ShowVideoMu/3bb24322f78b47dfb8723c13d46d45ee/\",\"or\":999},\"docker\":{\"sh\":\"彗星播放器\",\"sn\":\"1\",\"pu\":\"https://wy.bigmao.top/api/ShowVideoDoc/3bb24322f78b47dfb8723c13d46d45ee/\",\"or\":999},\"qq\":{\"sh\":\"腾讯视频\",\"sn\":\"1\",\"pu\":\"\",\"or\":999},\"youku\":{\"sh\":\"优酷\",\"sn\":\"1\",\"pu\":\"\",\"or\":999},\"qiyi\":{\"sh\":\"爱奇艺\",\"sn\":\"1\",\"pu\":\"\",\"or\":999},\"mgtv\":{\"sh\":\"仅限APP播放\",\"sn\":\"1\",\"pu\":\"\",\"or\":999},\"m3u8\":{\"sh\":\"m3u8\",\"sn\":\"1\",\"pu\":\"\",\"or\":999},\"mx771\":{\"sh\":\"站长采集的播放器\",\"sn\":\"0\",\"pu\":\"\",\"or\":999},\"ppayun2\":{\"sh\":\"白鸟座播放器\",\"sn\":\"1\",\"pu\":\"https://wy.bigmao.top/api/ShowVideoMu/3bb24322f78b47dfb8723c13d46d45ee/\",\"or\":999},\"sohu\":{\"sh\":\"搜狐\",\"sn\":\"1\",\"pu\":\"\",\"or\":999},\"iframe\":{\"sh\":\"iframe外链数据\",\"sn\":\"0\",\"pu\":\"\",\"or\":999}}"); + } catch (JSONException e) { + SpiderDebug.log(e); + } + } + + /** + * 爬虫headers + * + * @param url + * @return + */ + protected HashMap getHeaders(String url) { + HashMap headers = new HashMap<>(); + headers.put("method", "GET"); + headers.put("Host", siteHost); + headers.put("Upgrade-Insecure-Requests", "1"); + headers.put("DNT", "1"); + headers.put("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36"); + headers.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"); + headers.put("Accept-Language", "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2"); + return headers; + } + + /** + * 获取分类数据 + 首页最近更新视频列表数据 + * + * @param filter 是否开启筛选 关联的是 软件设置中 首页数据源里的筛选开关 + * @return + */ + @Override + public String homeContent(boolean filter) { + try { + String url = siteUrl; + Document doc = Jsoup.parse(OkHttpUtil.string(url, getHeaders(url))); + Elements elements = doc.select("ul.nav-menu>li>a"); + JSONArray classes = new JSONArray(); + ArrayList allClass = new ArrayList<>(); + for (Element ele : elements) { + String name = ele.text(); + boolean show = !filter || (name.equals("电影") || name.equals("美剧") || name.equals("日韩") || name.equals("动漫")); + if (allClass.contains(name)) + show = false; + if (show) { + allClass.add(name); + Matcher mather = regexCategory.matcher(ele.attr("href")); + if (!mather.find()) + continue; + // 把分类的id和名称取出来加到列表里 + String id = mather.group(1).trim(); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("type_id", id); + jsonObject.put("type_name", name); + classes.put(jsonObject); + } + } + JSONObject result = new JSONObject(); + result.put("class", classes); + try { + // 取首页推荐视频列表 + Elements list = doc.select("ul.myui-vodlist>li>div"); + JSONArray videos = new JSONArray(); + for (int i = 0; i < list.size(); i++) { + Element vod = list.get(i); + String title = vod.selectFirst(".title").text(); + String cover = vod.selectFirst(".myui-vodlist__thumb").attr("data-original"); + String remark = vod.selectFirst("span.pic-text").text(); + + Matcher matcher = regexVid.matcher(vod.selectFirst(".myui-vodlist__thumb").attr("href")); + if (!matcher.find()) + continue; + String id = matcher.group(1); + JSONObject v = new JSONObject(); + v.put("vod_id", id); + v.put("vod_name", title); + v.put("vod_pic", cover); + v.put("vod_remarks", remark); + videos.put(v); + } + result.put("list", videos); + } catch (Exception e) { + SpiderDebug.log(e); + } + return result.toString(); + } catch (Exception e) { + SpiderDebug.log(e); + } + return ""; + } + + + /** + * 获取分类信息数据 + * + * @param tid 分类id + * @param pg 页数 + * @param filter 同homeContent方法中的filter + * @param extend 筛选参数{k:v, k1:v1} + * @return + */ + @Override + public String categoryContent(String tid, String pg, boolean filter, HashMap extend) { + try { + // 获取分类数据的url + String url = siteUrl + "/vodtype/" + tid + "-" + pg + "/"; + String html = OkHttpUtil.string(url, getHeaders(url)); + Document doc = Jsoup.parse(html); + JSONObject result = new JSONObject(); + int pageCount = 0; + int page = -1; + + // 取页码相关信息 + Elements pageInfo = doc.select("ul.myui-page>li"); + if (pageInfo.size() == 0) { + page = Integer.parseInt(pg); + pageCount = page; + } else { + for (int i = 0; i < pageInfo.size(); i++) { + Element li = pageInfo.get(i); + Element a = li.selectFirst("a"); + if (a == null) + continue; + String name = a.text(); + if (page == -1 && a.hasClass("btn-warm")) { + Matcher matcher = regexPage.matcher(a.attr("href")); + if (matcher.find()) { + page = Integer.parseInt(matcher.group(1).split("-")[8]); + } else { + page = 0; + } + } + if (name.equals("尾页")) { + Matcher matcher = regexPage.matcher(a.attr("href")); + if (matcher.find()) { + pageCount = Integer.parseInt(matcher.group(1).split("-")[8]); + } else { + pageCount = 0; + } + break; + } + } + } + + + JSONArray videos = new JSONArray(); + if (!html.contains("没有找到您想要的结果哦")) { + // 取当前分类页的视频列表 + Elements list = doc.select("div.myui-panel_bd>ul>li>div"); + for (int i = 0; i < list.size(); i++) { + Element vod = list.get(i); + String title = vod.selectFirst(".title").text(); + String cover = vod.selectFirst(".myui-vodlist__thumb").attr("data-original"); + String remark = vod.selectFirst("span.pic-text").text(); + + Matcher matcher = regexVid.matcher(vod.selectFirst(".myui-vodlist__thumb").attr("href")); + if (!matcher.find()) + continue; + String id = matcher.group(1); + JSONObject v = new JSONObject(); + v.put("vod_id", id); + v.put("vod_name", title); + v.put("vod_pic", cover); + v.put("vod_remarks", remark); + videos.put(v); + } + } + result.put("page", page); + result.put("pagecount", pageCount); + result.put("limit", 48); + result.put("total", pageCount <= 1 ? videos.length() : pageCount * 48); + + result.put("list", videos); + return result.toString(); + } catch (Exception e) { + SpiderDebug.log(e); + } + return ""; + } + + /** + * 视频详情信息 + * + * @param ids 视频id + * @return + */ + @Override + public String detailContent(List ids) { + try { + // 视频详情url + String url = siteUrl + "/voddetail/" + ids.get(0) + "/"; + Document doc = Jsoup.parse(OkHttpUtil.string(url, getHeaders(url))); + JSONObject result = new JSONObject(); + JSONObject vodList = new JSONObject(); + + // 取基本数据 + String vid = doc.selectFirst("span.mac_hits").attr("data-id"); + + String cover = doc.selectFirst("a.myui-vodlist__thumb img").attr("data-original"); + String title = doc.selectFirst("div.myui-content__detail h1.title").text(); + String desc = doc.selectFirst("div.col-pd>span.sketch").text(); + String category = "", area = "", year = "", remark = "", director = "", actor = ""; + Elements span_text_muted = doc.select("div.myui-content__detail span.text-muted"); + for (int i = 0; i < span_text_muted.size(); i++) { + Element text = span_text_muted.get(i); + String info = text.text(); + if (info.equals("分类:")) { + category = text.nextElementSibling().text(); + } else if (info.equals("年份:")) { + year = text.nextElementSibling().text(); + } else if (info.equals("地区:")) { + area = text.nextElementSibling().text(); + } else if (info.equals("更新:")) { + remark = text.nextElementSibling().text(); + } else if (info.equals("导演:")) { + List directors = new ArrayList<>(); + Elements aa = text.parent().select("a"); + for (int j = 0; j < aa.size(); j++) { + directors.add(aa.get(j).text()); + } + } else if (info.equals("主演:")) { + List actors = new ArrayList<>(); + Elements aa = text.parent().select("a"); + for (int j = 0; j < aa.size(); j++) { + actors.add(aa.get(j).text()); + } + actor = TextUtils.join(",", actors); + } + } + + vodList.put("vod_id", vid); + vodList.put("vod_name", title); + vodList.put("vod_pic", cover); + vodList.put("type_name", category); + vodList.put("vod_year", year); + vodList.put("vod_area", area); + vodList.put("vod_remarks", remark); + vodList.put("vod_actor", actor); + vodList.put("vod_director", director); + vodList.put("vod_content", desc); + + Map vod_play = new TreeMap<>(new Comparator() { + @Override + public int compare(String o1, String o2) { + try { + int sort1 = playerConfig.getJSONObject(o1).getInt("or"); + int sort2 = playerConfig.getJSONObject(o2).getInt("or"); + + if (sort1 == sort2) { + return 1; + } + return sort1 - sort2 > 0 ? 1 : -1; + } catch (JSONException e) { + SpiderDebug.log(e); + } + return 1; + } + }); + + // 取播放列表数据 + Elements sources = doc.select("div.myui-panel__head").get(1).select("h3"); + Elements sourceList = doc.select("ul.myui-content__list"); + + for (int i = 0; i < sources.size(); i++) { + Element source = sources.get(i); + String sourceName = source.text(); + boolean found = false; + for (Iterator it = playerConfig.keys(); it.hasNext(); ) { + String flag = it.next(); + if (playerConfig.getJSONObject(flag).getString("sh").equals(sourceName)) { + sourceName = flag; + found = true; + break; + } + } + if (!found) + continue; + String playList = ""; + Elements playListA = sourceList.get(i).select("li>a"); + List vodItems = new ArrayList<>(); + + for (int j = 0; j < playListA.size(); j++) { + Element vod = playListA.get(j); + Matcher matcher = regexPlay.matcher(vod.attr("href")); + if (!matcher.find()) + continue; + String playURL = matcher.group(1) + "-" + matcher.group(2) + "-" + matcher.group(3); + vodItems.add(vod.text() + "$" + playURL); + } + if (vodItems.size() > 0) + playList = TextUtils.join("#", vodItems); + + if (playList.length() == 0) + continue; + + vod_play.put(sourceName, playList); + } + + if (vod_play.size() > 0) { + String vod_play_from = TextUtils.join("$$$", vod_play.keySet()); + String vod_play_url = TextUtils.join("$$$", vod_play.values()); + vodList.put("vod_play_from", vod_play_from); + vodList.put("vod_play_url", vod_play_url); + } + JSONArray list = new JSONArray(); + list.put(vodList); + result.put("list", list); + return result.toString(); + } catch (Exception e) { + SpiderDebug.log(e); + } + return ""; + } + + /** + * 获取视频播放信息 + * + * @param flag 播放源 + * @param id 视频id + * @param vipFlags 所有可能需要vip解析的源 + * @return + */ + @Override + public String playerContent(String flag, String id, List vipFlags) { + try { + //定义播放用的headers + JSONObject headers = new JSONObject(); + //headers.put("Host", " cokemv.co"); + headers.put("origin", " https://nfxhd.com"); + headers.put("User-Agent", " Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36"); + headers.put("Accept", " */*"); + headers.put("Accept-Language", " zh-CN,zh;q=0.9,en-US;q=0.3,en;q=0.7"); + headers.put("Accept-Encoding", " gzip, deflate"); + + + // 播放页 url + String url = siteUrl + "/vodplay/" + id + "/"; + Document doc = Jsoup.parse(OkHttpUtil.string(url, getHeaders(url))); + Elements allScript = doc.select("script"); + JSONObject result = new JSONObject(); + for (int i = 0; i < allScript.size(); i++) { + String scContent = allScript.get(i).html().trim(); + if (scContent.startsWith("var player_")) { // 取直链 + int start = scContent.indexOf('{'); + int end = scContent.lastIndexOf('}') + 1; + String json = scContent.substring(start, end); + JSONObject player = new JSONObject(json); + if (playerConfig.has(player.getString("from"))) { + JSONObject pCfg = playerConfig.getJSONObject(player.getString("from")); + String videoUrl = player.getString("url"); + String playUrl = pCfg.getString("pu"); + result.put("parse", pCfg.getInt("sn")); + result.put("playUrl", playUrl); + result.put("url", videoUrl); + result.put("header", headers.toString()); + } + break; + } + } + return result.toString(); + } catch (Exception e) { + SpiderDebug.log(e); + } + return ""; + } + + + @Override + public String searchContent(String key, boolean quick) { + try { + if (quick) + return ""; + long currentTime = System.currentTimeMillis(); + String url = siteUrl + "/index.php/ajax/suggest?mid=1&wd=" + URLEncoder.encode(key) + "&limit=10×tamp=" + currentTime; + JSONObject searchResult = new JSONObject(OkHttpUtil.string(url, getHeaders(url))); + JSONObject result = new JSONObject(); + JSONArray videos = new JSONArray(); + if (searchResult.getInt("total") > 0) { + JSONArray lists = new JSONArray(searchResult.getString("list")); + for (int i = 0; i < lists.length(); i++) { + JSONObject vod = lists.getJSONObject(i); + String id = vod.getString("id"); + String title = vod.getString("name"); + String cover = vod.getString("pic"); + JSONObject v = new JSONObject(); + v.put("vod_id", id); + v.put("vod_name", title); + v.put("vod_pic", cover); + v.put("vod_remarks", ""); + videos.put(v); + } + } + result.put("list", videos); + return result.toString(); + } catch (Exception e) { + SpiderDebug.log(e); + } + return ""; + } +}