diff --git a/jar/spider.jar b/jar/spider.jar index 549c633..dcc2df2 100644 Binary files a/jar/spider.jar and b/jar/spider.jar differ diff --git a/json/config.json b/json/config.json index 4dacd4a..d80fa7f 100644 --- a/json/config.json +++ b/json/config.json @@ -84,6 +84,17 @@ "ext": { } }, + { + "key": "DaGongRen", + "name": "打工人", + "type": 3, + "api": "csp_DaGongRen", + "searchable": "1", + "filterable": "0", + "changeable": 0, + "ext": { + } + }, { "key": "WuMingMusic", "name": "无名音乐", diff --git a/src/main/java/com/github/catvod/spider/DaGongRen.java b/src/main/java/com/github/catvod/spider/DaGongRen.java new file mode 100644 index 0000000..cd2fb73 --- /dev/null +++ b/src/main/java/com/github/catvod/spider/DaGongRen.java @@ -0,0 +1,164 @@ +package com.github.catvod.spider; + +import cn.hutool.core.net.URLEncodeUtil; +import com.github.catvod.bean.Class; +import com.github.catvod.bean.Result; +import com.github.catvod.bean.Vod; +import com.github.catvod.crawler.Spider; +import com.github.catvod.net.OkHttp; +import com.github.catvod.utils.Utils; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; + +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class DaGongRen extends Spider { + + private static final String siteUrl = "https://dagongren1.com"; + private static final String cateUrl = siteUrl + "/list/"; + private static final String detailUrl = siteUrl + "/play/"; + private static final String playUrl = siteUrl + "/play/"; + private static final String searchUrl = siteUrl + "/search--------------.html?wd="; + + private HashMap getHeaders() { + HashMap headers = new HashMap<>(); + headers.put("User-Agent", Utils.CHROME); + return headers; + } + + @Override + public String homeContent(boolean filter) throws Exception { + List list = new ArrayList<>(); + List classes = new ArrayList<>(); + String[] typeIdList = {"dianying", "dianshiju", "zongyi", "dongman", "jilupian", "lunlipian"}; + String[] typeNameList = {"电影", "连续剧", "综艺", "动漫", "纪录片", "福利"}; + for (int i = 0; i < typeNameList.length; i++) { + classes.add(new Class(typeIdList[i], typeNameList[i])); + } + Document doc = Jsoup.parse(OkHttp.string(siteUrl, getHeaders())); + for (Element element : doc.select("a.vodlist_thumb")) { + try { + String pic = element.attr("data-original"); + String url = element.attr("href"); + String name = element.attr("title"); + if (!pic.startsWith("http")) { + pic = siteUrl + pic; + } + String id = url.split("/")[2]; + list.add(new Vod(id, name, pic)); + } catch (Exception ignored) { + } + } + return Result.string(classes, list); + } + + + @Override + public String categoryContent(String tid, String pg, boolean filter, HashMap extend) throws Exception { + List list = new ArrayList<>(); + tid = "/show-" + tid + "--------" + pg + "---.html"; + String target = siteUrl + tid; + Document doc = Jsoup.parse(OkHttp.string(target, getHeaders())); + for (Element element : doc.select("a.vodlist_thumb")) { + try { + String pic = element.attr("data-original"); + String url = element.attr("href"); + String name = element.attr("title"); + if (!pic.startsWith("http")) { + pic = siteUrl + pic; + } + String id = url.split("/")[2]; + list.add(new Vod(id, name, pic)); + } catch (Exception e) { + } + } + + int total = (Integer.parseInt(pg) + 1) * 20; + return Result.get().vod(list).page(Integer.parseInt(pg), Integer.parseInt(pg) + 1, 20, total).string(); + } + + @Override + public String detailContent(List ids) throws Exception { + Document doc = Jsoup.parse(OkHttp.string(detailUrl.concat(ids.get(0)), getHeaders())); + String name = doc.select("h2.title.margin_0").text(); + String pic = doc.select("div.play_vlist_thumb").get(0).attr("data-original"); + // 播放源 + Elements tabs = doc.select("li.tab-play"); + Elements list = doc.select("ul.content_playlist"); + StringBuilder PlayFrom = new StringBuilder(); + StringBuilder PlayUrl = new StringBuilder(); + for (int i = 0; i < tabs.size(); i++) { + String tabName = tabs.get(i).text(); + if (PlayFrom.length() > 0) { + PlayFrom.append("$$$").append(tabName); + } else { + PlayFrom.append(tabName); + } + Elements li = list.get(i).select("a"); + StringBuilder liUrl = new StringBuilder(); + for (int i1 = 0; i1 < li.size(); i1++) { + if (liUrl.length() > 0) { + liUrl.append("#").append(li.get(i1).text()).append("$").append(li.get(i1).attr("href").replace("/play/", "")); + } else { + liUrl.append(li.get(i1).text()).append("$").append(li.get(i1).attr("href").replace("/play/", "")); + } + } + if (PlayUrl.length() > 0) { + PlayUrl.append("$$$").append(liUrl); + } else { + PlayUrl.append(liUrl); + } + } + + Vod vod = new Vod(); + vod.setVodId(ids.get(0)); + vod.setVodPic(siteUrl + pic); + vod.setVodName(name); + vod.setVodPlayFrom(PlayFrom.toString()); + vod.setVodPlayUrl(PlayUrl.toString()); + return Result.string(vod); + } + + @Override + public String searchContent(String key, boolean quick) throws Exception { + List list = new ArrayList<>(); + Document doc = Jsoup.parse(OkHttp.string(searchUrl.concat(URLEncodeUtil.encode(key, StandardCharsets.UTF_8)), getHeaders())); + for (Element element : doc.select("div.searchlist_img")) { + try { + String pic = element.select("a").attr("data-original"); + String url = element.select("a").attr("href"); + String name = element.select("a").attr("title"); + if (!pic.startsWith("http")) { + pic = siteUrl + pic; + } + String id = url.replace("/video/", "").replace(".html", "-1-1.html"); + list.add(new Vod(id, name, pic)); + } catch (Exception e) { + } + } + return Result.string(list); + } + + @Override + public String playerContent(String flag, String id, List vipFlags) throws Exception { + String target = playUrl.concat(id); + Document doc = Jsoup.parse(OkHttp.string(target)); + String regex = "\"url\\\":\\\"(.*?)\\\",\\\"url_next\\\":"; + + Pattern pattern = Pattern.compile(regex); + Matcher matcher = pattern.matcher(doc.html()); + String url = ""; + if (matcher.find()) { + url = URLDecoder.decode(matcher.group(1), "UTF-8").split("&")[0]; + } + return Result.get().url(url).header(getHeaders()).string(); + } +} \ No newline at end of file diff --git a/src/test/java/DaGongRenTest.java b/src/test/java/DaGongRenTest.java new file mode 100644 index 0000000..45e3504 --- /dev/null +++ b/src/test/java/DaGongRenTest.java @@ -0,0 +1,66 @@ +import cn.hutool.json.JSONUtil; +import com.github.catvod.spider.ChangZhang; +import com.github.catvod.spider.DaGongRen; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import org.junit.jupiter.api.Test; + +/** + * @author heatdesert + * @date 2024-01-27 12:51 + * @description + */ +public class DaGongRenTest { + private static DaGongRen douban = new DaGongRen(); + + static { + try { + douban.init(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Test + public void homeTest() throws Exception { + String s = douban.homeContent(false); + System.out.println(JSONUtil.toJsonPrettyStr(JSONUtil.parseObj(s))); + AssertUtil.INSTANCE.assertResult(s); + } + + @Test + public void cateTest() throws Exception { + + //String palyDoc= OkHttp.string("http://www.lzizy9.com/index.php/vod/play/id/79816/sid/1/nid/1.html"); + + String s = douban.categoryContent("dianying", "1", false, Maps.newHashMap()); + System.out.print(JSONUtil.toJsonPrettyStr(JSONUtil.parseObj(s))); + AssertUtil.INSTANCE.assertResult(s); + + } + + @Test + public void detailTest() throws Exception { + + String detail = douban.detailContent(Lists.newArrayList("126323-1-1.html")); + System.out.print(JSONUtil.toJsonPrettyStr(JSONUtil.parseObj(detail))); + + } + + @Test + public void playerTest() throws Exception { + + String palyer = douban.playerContent(null, "126323-2-1.html", null); + System.out.print(JSONUtil.toJsonPrettyStr(JSONUtil.parseObj(palyer))); + + } + + @Test + public void searchTest() throws Exception { + + String detail = douban.searchContent("红海", false); + System.out.print(JSONUtil.toJsonPrettyStr(JSONUtil.parseObj(detail))); + + } + +}