Skip to content

Commit

Permalink
feat: DUB 屏蔽大陆
Browse files Browse the repository at this point in the history
  • Loading branch information
Greatwallcorner committed Dec 11, 2024
1 parent c2d6edb commit 58cbe30
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 13 deletions.
Binary file modified jar/spider.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion json/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"spider": "../jar/spider.jar;md5;198903037572d4d7d5e030a14792ab76",
"spider": "../jar/spider.jar;md5;6930784cd02e174846e05645e5c317f7",
"sites": [
{
"key": "Douban",
Expand Down
2 changes: 1 addition & 1 deletion json/configAll.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"spider": "../jar/spider.jar;md5;198903037572d4d7d5e030a14792ab76",
"spider": "../jar/spider.jar;md5;6930784cd02e174846e05645e5c317f7",
"sites": [
{
"key": "Douban",
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/github/catvod/net/OkHttp.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static String getLocation(Map<String, List<String>> headers) {

public static OkHttpClient.Builder getBuilder() {
return new OkHttpClient.Builder()
// .proxy(new java.net.Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost",8080)))
// .proxy(new java.net.Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost",7890)))
.addInterceptor(new OkhttpInterceptor()).dns(dns()).connectTimeout(3, TimeUnit.SECONDS)
.readTimeout(5, TimeUnit.SECONDS)
.writeTimeout(5, TimeUnit.SECONDS)
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/com/github/catvod/spider/DUB.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.catvod.spider

import cn.hutool.core.codec.Base64
import cn.hutool.core.util.URLUtil
import com.github.catvod.bean.Class
import com.github.catvod.bean.Result
import com.github.catvod.bean.Vod
Expand All @@ -11,18 +12,18 @@ import com.github.catvod.net.OkHttp
import com.github.catvod.utils.Image
import com.github.catvod.utils.Json
import com.github.catvod.utils.Utils
import com.google.common.net.HttpHeaders
import org.jsoup.Jsoup
import org.jsoup.select.Elements
import java.net.URLDecoder
import java.net.URLEncoder
import java.util.*

class DUB: Spider() {
private val host = Utils.base64Decode("aHR0cHM6Ly90di5nYm9rdS5jb20v")

private val cateFormat = "/vodtype/%s.html" // tid-page
private val cateFormat2 = "/vodtype/%s-%s.html" // tid-page
private var referer = Utils.base64Decode("YzNSaGRHbGpMM0JzWVhsbGNpOTJhV1JxY3pJMUxuQm9jQT09")
private var referer = Utils.base64Decode("aHR0cHM6Ly93d3cuZHVib2t1LnR2Lw==")
private val signUrl = Utils.base64Decode("c3RhdGljL3BsYXllci92aWRqczI1LnBocA==")
private val searchUrl = Utils.base64Decode("L3ZvZHNlYXJjaC8tLS0tLS0tLS0tLS0tLmh0bWw/d2Q9JXMmc3VibWl0PQ==")

Expand Down Expand Up @@ -140,7 +141,6 @@ class DUB: Spider() {
return super.searchContent(key, quick, pg)
}

@OptIn(ExperimentalStdlibApi::class)
override fun playerContent(flag: String?, id: String, vipFlags: MutableList<String>?): String {
val string = OkHttp.string("$host$id")
val regex = Regex("var\\s*player_[a-z]{0,4}\\s*=\\s*([^<]+)")
Expand All @@ -164,6 +164,16 @@ class DUB: Spider() {
val find = signRegx.find(signDocument)
if((find?.groupValues?.size ?: 0) > 0){
val sign = find!!.groupValues[1]
val m3u = OkHttp.string("$url?sign=${URLEncoder.encode(sign, "UTF-8")}", Utils.webHeaders(host).apply { put(HttpHeaders.HOST, URLUtil.url(url).host) })
val m3uRegx = Regex("/\\d{8}/[A-Za-z0-9]+/hls/index\\.m3u8\\?sign=[A-Za-z0-9+=%]+")
val matchResult = m3uRegx.find(m3u)
if((matchResult?.groupValues?.size ?: 0) > 0){
val toHttpUrl = URLUtil.url(url)
return Result.get().url(toHttpUrl.protocol + "://" + toHttpUrl.host + "/" + matchResult!!.value).string()
}else{
SpiderDebug.log("DUB 解析m3u地址失败")
}

return Result.get().url("$url?sign=${URLEncoder.encode(sign, "UTF-8")}").string()
}
SpiderDebug.log("DUB 获取签名失败")
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/github/catvod/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.github.catvod.net.OkHttp;
import com.github.catvod.spider.Init;
import com.github.catvod.spider.Proxy;
import io.ktor.http.ContentType;
import okhttp3.Response;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpHeaders;
Expand Down Expand Up @@ -358,8 +357,8 @@ public static HashMap<String, String> webHeaders(String referer) {
synchronized (Utils.class) {
if (webHttpHeaderMap == null || webHttpHeaderMap.isEmpty()) {
webHttpHeaderMap = new HashMap<>();
webHttpHeaderMap.put(HttpHeaders.CONTENT_TYPE, ContentType.Application.INSTANCE.getJson().getContentType());
webHttpHeaderMap.put(HttpHeaders.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");
// webHttpHeaderMap.put(HttpHeaders.CONTENT_TYPE, ContentType.Application.INSTANCE.getJson().getContentType());
// webHttpHeaderMap.put(HttpHeaders.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");
webHttpHeaderMap.put(HttpHeaders.CONNECTION, "keep-alive");
webHttpHeaderMap.put(HttpHeaders.USER_AGENT, CHROME);
webHttpHeaderMap.put(HttpHeaders.ACCEPT, "*/*");
Expand Down
19 changes: 16 additions & 3 deletions src/test/java/DUBTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,32 @@ class DUBTest:TestInterface<DUB> {

@Test
override fun detailTest() {
val detailContent = t.detailContent(mutableListOf("/voddetail/5067.html"))
val detailContent = t.detailContent(mutableListOf("/voddetail/5075.html"))
assert(detailContent)
}

@Test
override fun playTest() {
val playerContent = t.playerContent("", "/vodplay/5067-1-1.html", mutableListOf())
val playerContent = t.playerContent("", "/vodplay/5075-1-1.html", mutableListOf())
assert(playerContent)
}

@Test
override fun searchTest() {
val searchContent = t.searchContent("庆余年", false)
val searchContent = t.searchContent("我和我爸的18岁", false)
assert(searchContent)
}

@Test
fun test(){
val s = """
#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1893000,RESOLUTION=1920x800
/20241206/OCoW5RVT/hls/index.m3u8?sign=PVsk2rfMzhALh4dgnAfOyUG%2B9%2BfweU4WFP%2FADswYaH8%3D
""".trimIndent()
val m3uRegx= Regex("/\\d{8}/[A-Za-z0-9]+/hls/index\\.m3u8\\?sign=[A-Za-z0-9+=]+")
val matchResult = m3uRegx.find(s)
println(matchResult?.value)
}
}
10 changes: 9 additions & 1 deletion src/test/java/common/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void strEncode(){

@Test
public void strDecode(){
String s = "eyJVc2VyLUFnZW50IjoiIERhbHZpay8yLjEuMCAoTGludXg7IFU7IGlQaG9uZSAxMjsgVjQxQSBCdWlsZC9TUDFBLjIxMDgxMi4wMDMpIiwiYWxsb3dDcm9zc1Byb3RvY29sUmVkaXJlY3RzIjoiIHRydWUiLCJBY2NlcHQiOiIgKi8qIiwiQ29udGVudC10eXBlIjoiIHZpZGVvL21wMnQiLCJDb25uZWN0aW9uIjoiIGtlZXAtYWxpdmUifQ==";
String s = "YzNSaGRHbGpMM0JzWVhsbGNpOTJhV1JxY3pJMUxuQm9jQT09";
System.out.println(Utils.base64Decode(s));
}

Expand All @@ -41,6 +41,14 @@ public void decodeTest(){
String s1 = Base64.decodeStr(s);
System.out.println(s1);
}
@Test
public void parseTest(){
String s = "#EXTM3U\n" +
"#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1893000,RESOLUTION=1920x800\n" +
"/20241206/OCoW5RVT/hls/index.m3u8?sign=PVsk2rfMzhALh4dgnAfOyUG%2B9%2BfweU4WFP%2FADswYaH8%3D\n";
String s1 = Base64.decodeStr(s);
System.out.println(s1);
}

@Test
public void htmlEncode(){
Expand Down

0 comments on commit 58cbe30

Please sign in to comment.