Skip to content

Commit

Permalink
Merge pull request #12 from lushunming/master
Browse files Browse the repository at this point in the history
打工人影院
  • Loading branch information
Greatwallcorner authored Jul 1, 2024
2 parents 310f05c + ffe2c73 commit f7db821
Show file tree
Hide file tree
Showing 4 changed files with 241 additions and 0 deletions.
Binary file modified jar/spider.jar
Binary file not shown.
11 changes: 11 additions & 0 deletions json/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@
"ext": {
}
},
{
"key": "DaGongRen",
"name": "打工人",
"type": 3,
"api": "csp_DaGongRen",
"searchable": "1",
"filterable": "0",
"changeable": 0,
"ext": {
}
},
{
"key": "WuMingMusic",
"name": "无名音乐",
Expand Down
164 changes: 164 additions & 0 deletions src/main/java/com/github/catvod/spider/DaGongRen.java
Original file line number Diff line number Diff line change
@@ -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<String, String> getHeaders() {
HashMap<String, String> headers = new HashMap<>();
headers.put("User-Agent", Utils.CHROME);
return headers;
}

@Override
public String homeContent(boolean filter) throws Exception {
List<Vod> list = new ArrayList<>();
List<Class> 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<String, String> extend) throws Exception {
List<Vod> 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<String> 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<Vod> 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<String> 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();
}
}
66 changes: 66 additions & 0 deletions src/test/java/DaGongRenTest.java
Original file line number Diff line number Diff line change
@@ -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)));

}

}

0 comments on commit f7db821

Please sign in to comment.