diff --git a/jar/spider.jar b/jar/spider.jar index 94f3043..6a606fa 100644 Binary files a/jar/spider.jar and b/jar/spider.jar differ diff --git a/json/config.json b/json/config.json index 6e4468a..9419450 100644 --- a/json/config.json +++ b/json/config.json @@ -1,5 +1,5 @@ { - "spider": "../jar/spider.jar;md5;92ca9354dbc6a80563a500663ed2491e", + "spider": "../jar/spider.jar;md5;198903037572d4d7d5e030a14792ab76", "sites": [ { "key": "Douban", @@ -37,6 +37,15 @@ "changeable": 0, "ext": {} }, + { + "key": "DUB", + "name": "DUB", + "type": 3, + "api": "csp_DUB", + "searchable": 0, + "changeable": 0, + "ext": {} + }, { "key": "QxiTv", "name": "七喜 | 影视", diff --git a/json/configAll.json b/json/configAll.json index 5f76213..802bbe0 100644 --- a/json/configAll.json +++ b/json/configAll.json @@ -1,5 +1,5 @@ { - "spider": "../jar/spider.jar;md5;92ca9354dbc6a80563a500663ed2491e", + "spider": "../jar/spider.jar;md5;198903037572d4d7d5e030a14792ab76", "sites": [ { "key": "Douban", diff --git a/src/main/java/com/github/catvod/spider/DUB.kt b/src/main/java/com/github/catvod/spider/DUB.kt index 75b9f7b..ca9cc3e 100644 --- a/src/main/java/com/github/catvod/spider/DUB.kt +++ b/src/main/java/com/github/catvod/spider/DUB.kt @@ -1,25 +1,35 @@ +package com.github.catvod.spider + +import cn.hutool.core.codec.Base64 import com.github.catvod.bean.Class import com.github.catvod.bean.Result import com.github.catvod.bean.Vod import com.github.catvod.bean.Vod.VodPlayBuilder.PlayUrl import com.github.catvod.crawler.Spider +import com.github.catvod.crawler.SpiderDebug 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 org.jsoup.Jsoup import org.jsoup.select.Elements -import java.util.HashMap +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 = "duboku.tv" + private var referer = Utils.base64Decode("YzNSaGRHbGpMM0JzWVhsbGNpOTJhV1JxY3pJMUxuQm9jQT09") + private val signUrl = Utils.base64Decode("c3RhdGljL3BsYXllci92aWRqczI1LnBocA==") + private val searchUrl = Utils.base64Decode("L3ZvZHNlYXJjaC8tLS0tLS0tLS0tLS0tLmh0bWw/d2Q9JXMmc3VibWl0PQ==") // private val classList = Class.parseFromFormatStr("") override fun homeContent(filter: Boolean): String { - val result = OkHttp.string("https://tv.gboku.com/vodtype/1.html", Utils.webHeaders("duboku.tv")) -// val result = OkHttp.string("$host/vodtype/2.html", Utils.webHeaders("duboku.tv")) +// val result = OkHttp.string("https://tv.gboku.com/vodtype/1.html", Utils.webHeaders("duboku.tv")) + val result = OkHttp.string("$host/vodtype/2.html", Utils.webHeaders("duboku.tv")) val document = Jsoup.parse(result) val select = document.select("ul.nav-list > li") @@ -32,7 +42,7 @@ class DUB: Spider() { } override fun categoryContent(tid: String?, pg: String?, filter: Boolean, extend: HashMap?): String { - var url = "" + var url: String if(pg == "1"){ url = cateFormat.format(tid) }else{ @@ -50,7 +60,7 @@ class DUB: Spider() { vod.apply { setVodRemarks(fa.text()) setVodId(fa.attr("href")) - setVodPic(fa.attr("data-original")) + setVodPic(Image.UrlHeaderBuilder(fa.attr("data-original")).referer(referer).build()) setVodName(fa.attr("title")) } vodList.add(vod) @@ -59,7 +69,9 @@ class DUB: Spider() { } override fun detailContent(ids: MutableList): String { - val string = OkHttp.string("$host${ids[0]}", Utils.webHeaders(referer)) + val u = "$host${ids[0]}" + val string = OkHttp.string(u, Utils.webHeaders(referer)) + referer = u val document = Jsoup.parse(string) val detail = document.select(".myui-content__detail") val vod = Vod() @@ -106,15 +118,56 @@ class DUB: Spider() { override fun searchContent(key: String?, quick: Boolean): String { - return super.searchContent(key, quick) + val string = + OkHttp.string("$host${searchUrl.format(URLEncoder.encode(key, "UTF-8"))}", Utils.webHeaders(referer)) + val document = Jsoup.parse(string) + val select = document.select("ul#searchList > li") + val vodList = mutableListOf() + for (element in select) { + vodList.add(Vod().apply { + val text = element.select("a.searchKey") + setVodName(text.text()) + setVodId(text.attr("href")) + val thumb = element.select(".thumb > a") + setVodPic(Image.UrlHeaderBuilder(thumb.attr("data-original")).referer(referer).build()) + setVodRemarks(thumb.select(".tag").text()) + }) + } + return Result.string(vodList) } override fun searchContent(key: String?, quick: Boolean, pg: String?): String { return super.searchContent(key, quick, pg) } - override fun playerContent(flag: String?, id: String?, vipFlags: MutableList?): String { - return super.playerContent(flag, id, vipFlags) + @OptIn(ExperimentalStdlibApi::class) + override fun playerContent(flag: String?, id: String, vipFlags: MutableList?): String { + val string = OkHttp.string("$host$id") + val regex = Regex("var\\s*player_[a-z]{0,4}\\s*=\\s*([^<]+)") + val data = regex.find(string) + var url = "" + if((data?.groupValues?.size ?: 0) > 0){ + val parse = Json.parse(data!!.groupValues[1]) + val rst = parse.asJsonObject + val encrypt = rst.get("encrypt").asInt + url = if(encrypt == 2){ + URLDecoder.decode(Base64.decodeStr(rst.get("url").asString), "UTF-8") + }else{ + URLDecoder.decode(rst.get("url").asString, "UTF-8") + } + }else{ + SpiderDebug.log("DUB 获取播放链接失败 $string") + } + + val signDocument = OkHttp.string("$host$signUrl", Utils.webHeaders(referer)) + val signRegx = Regex("encodeURIComponent\\s*\\(\\s*[\"']([^\"']+)[\"']\\s*\\)") + val find = signRegx.find(signDocument) + if((find?.groupValues?.size ?: 0) > 0){ + val sign = find!!.groupValues[1] + return Result.get().url("$url?sign=${URLEncoder.encode(sign, "UTF-8")}").string() + } + SpiderDebug.log("DUB 获取签名失败") + return Result.error("获取播放链接失败") } } \ No newline at end of file diff --git a/src/test/java/DUBTest.kt b/src/test/java/DUBTest.kt index cf3520d..f0cc166 100644 --- a/src/test/java/DUBTest.kt +++ b/src/test/java/DUBTest.kt @@ -1,5 +1,6 @@ import cn.hutool.core.lang.Assert import com.github.catvod.bean.Result +import com.github.catvod.spider.DUB import common.TestInterface import org.junit.jupiter.api.Test @@ -32,12 +33,15 @@ class DUBTest:TestInterface { assert(detailContent) } + @Test override fun playTest() { val playerContent = t.playerContent("", "/vodplay/5067-1-1.html", mutableListOf()) assert(playerContent) } + @Test override fun searchTest() { - TODO("Not yet implemented") + val searchContent = t.searchContent("庆余年", false) + assert(searchContent) } } \ No newline at end of file diff --git a/src/test/java/common/Util.java b/src/test/java/common/Util.java index 0a03cf2..9782dd2 100644 --- a/src/test/java/common/Util.java +++ b/src/test/java/common/Util.java @@ -1,5 +1,6 @@ package common; +import cn.hutool.core.codec.Base64; import cn.hutool.core.io.FileUtil; import cn.hutool.http.HtmlUtil; import com.github.catvod.utils.Utils; @@ -14,7 +15,7 @@ public class Util { @Test public void strEncode(){ - String s = "/api.php/provide/search_result"; + String s = "/vodsearch/-------------.html?wd=%s&submit="; System.out.println(Utils.base64Encode(s)); } @@ -34,6 +35,13 @@ public void md5Test(){ System.out.println(s1); } + @Test + public void decodeTest(){ + String s = "JTY4JTc0JTc0JTcwJTczJTNBJTJGJTJGJTc0JTMyJTMwJTZEJTJFJTZFJTYyJTZGJTZCJTc1JTJFJTYzJTZGJTZEJTJGJTMyJTMwJTMyJTM0JTMxJTMyJTMwJTM2JTJGJTRGJTQzJTZGJTU3JTM1JTUyJTU2JTU0JTJGJTY5JTZFJTY0JTY1JTc4JTJFJTZEJTMzJTc1JTM4"; + String s1 = Base64.decodeStr(s); + System.out.println(s1); + } + @Test public void htmlEncode(){ String html = FileUtil.readString(new File("E:\\Archives\\compose-mutiplatform-workspace\\Test\\https __www.yjys.me_.htm"), "utf-8");