Add files via upload

This commit is contained in:
潇洒 2024-04-26 16:43:49 +08:00 committed by GitHub
parent 3849865322
commit 2cf1d8dd8f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 525 additions and 54 deletions

314
JS/drpy.min.js vendored
View File

@ -1,5 +1,6 @@
import cheerio from "assets://js/lib/cheerio.min.js"; import cheerio from "assets://js/lib/cheerio.min.js";
import "assets://js/lib/crypto-js.js"; import "assets://js/lib/crypto-js.js";
import "./jsencrypt.js";
import 模板 from "./模板.js"; import 模板 from "./模板.js";
import { import {
gbkTool gbkTool
@ -29,7 +30,7 @@ function pre() {
} }
let rule = {}; let rule = {};
let vercode = typeof pdfl === "function" ? "drpy2.1" : "drpy2"; let vercode = typeof pdfl === "function" ? "drpy2.1" : "drpy2";
const VERSION = vercode + " 3.9.49beta38 202400414"; const VERSION = vercode + " 3.9.49beta40 202400426";
const MOBILE_UA = "Mozilla/5.0 (Linux; Android 11; M2007J3SC Build/RKQ1.200826.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045714 Mobile Safari/537.36"; const MOBILE_UA = "Mozilla/5.0 (Linux; Android 11; M2007J3SC Build/RKQ1.200826.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045714 Mobile Safari/537.36";
const PC_UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36"; const PC_UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36";
const UA = "Mozilla/5.0"; const UA = "Mozilla/5.0";
@ -62,10 +63,10 @@ const SELECT_REGEX = /:eq|:lt|:gt|#/g;
const SELECT_REGEX_A = /:eq|:lt|:gt/g; const SELECT_REGEX_A = /:eq|:lt|:gt/g;
if (typeof Object.assign != "function") { if (typeof Object.assign != "function") {
Object.assign = function() { Object.assign = function() {
var target = arguments[0]; let target = arguments[0];
for (var i = 1; i < arguments.length; i++) { for (let i = 1; i < arguments.length; i++) {
var source = arguments[i]; let source = arguments[i];
for (var key in source) { for (let key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) { if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key] target[key] = source[key]
} }
@ -168,6 +169,13 @@ if (typeof Array.prototype.join != "function") {
return str return str
} }
} }
if (typeof Array.prototype.toReversed != "function") {
Array.prototype.toReversed = function() {
const clonedList = this.slice();
const reversedList = clonedList.reverse();
return reversedList
}
}
String.prototype.rstrip = function(chars) { String.prototype.rstrip = function(chars) {
let regex = new RegExp(chars + "$"); let regex = new RegExp(chars + "$");
return this.replace(regex, "") return this.replace(regex, "")
@ -348,27 +356,52 @@ function getCryptoJS() {
return 'console.log("CryptoJS已装载");' return 'console.log("CryptoJS已装载");'
} }
const RSA = { const RSA = {
encode: function(data, key, option) { decode: function(data, key, option) {
if (typeof rsaEncrypt === "function") { option = option || {};
if (!option || typeof option !== "object") { if (typeof JSEncrypt === "function") {
return rsaEncrypt(data, key) let chunkSize = option.chunkSize || 117;
} else { let privateKey = this.getPrivateKey(key);
return rsaEncrypt(data, key, option) const decryptor = new JSEncrypt;
} decryptor.setPrivateKey(privateKey);
let uncrypted = "";
uncrypted = decryptor.decryptUnicodeLong(data);
return uncrypted
} else { } else {
return false return false
} }
}, },
decode: function(data, key, option) { encode: function(data, key, option) {
if (typeof rsaDecrypt === "function") { option = option || {};
if (!option || typeof option !== "object") { if (typeof JSEncrypt === "function") {
return rsaDecrypt(data, key) let chunkSize = option.chunkSize || 117;
} else { let publicKey = this.getPublicKey(key);
return rsaDecrypt(data, key, option) const encryptor = new JSEncrypt;
} encryptor.setPublicKey(publicKey);
let encrypted = "";
encrypted = encryptor.encryptUnicodeLong(data);
return encrypted
} else { } else {
return false return false
} }
},
fixKey(key, prefix, endfix) {
if (!key.includes(prefix)) {
key = prefix + key
}
if (!key.includes(endfix)) {
key += endfix
}
return key
},
getPrivateKey(key) {
let prefix = "-----BEGIN RSA PRIVATE KEY-----";
let endfix = "-----END RSA PRIVATE KEY-----";
return this.fixKey(key, prefix, endfix)
},
getPublicKey(key) {
let prefix = "-----BEGIN PUBLIC KEY-----";
let endfix = "-----END PUBLIC KEY-----";
return this.fixKey(key, prefix, endfix)
} }
}; };
@ -379,6 +412,143 @@ function getProxyUrl() {
return "http://127.0.0.1:9978/proxy?do=js" return "http://127.0.0.1:9978/proxy?do=js"
} }
} }
function fixAdM3u8(m3u8_text, m3u8_url, ad_remove) {
if (!m3u8_text && !m3u8_url || !m3u8_text && m3u8_url && !m3u8_url.startsWith("http")) {
return ""
}
if (!m3u8_text) {
log("m3u8_url:" + m3u8_url);
m3u8_text = request(m3u8_url)
}
log("len(m3u8_text):" + m3u8_text.length);
if (!ad_remove) {
return m3u8_text
}
if (ad_remove.startsWith("reg:")) {
ad_remove = ad_remove.slice(4)
} else if (ad_remove.startsWith("js:")) {
ad_remove = ad_remove.slice(3)
}
let m3u8_start = m3u8_text.slice(0, m3u8_text.indexOf("#EXTINF"))
.trim();
let m3u8_body = m3u8_text.slice(m3u8_text.indexOf("#EXTINF"), m3u8_text.indexOf("#EXT-X-ENDLIST"))
.trim();
let m3u8_end = m3u8_text.slice(m3u8_text.indexOf("#EXT-X-ENDLIST"))
.trim();
let murls = [];
let m3_body_list = m3u8_body.split("\n");
let m3_len = m3_body_list.length;
let i = 0;
while (i < m3_len) {
let mi = m3_body_list[i];
let mi_1 = m3_body_list[i + 1];
if (mi.startsWith("#EXTINF")) {
murls.push([mi, mi_1].join("&"));
i += 2
} else if (mi.startsWith("#EXT-X-DISCONTINUITY")) {
let mi_2 = m3_body_list[i + 2];
murls.push([mi, mi_1, mi_2].join("&"));
i += 3
} else {
break
}
}
let new_m3u8_body = [];
for (let murl of murls) {
if (ad_remove && new RegExp(ad_remove)
.test(murl)) {} else {
let murl_list = murl.split("&");
if (!murl_list[murl_list.length - 1].startsWith("http") && m3u8_url.startsWith("http")) {
murl_list[murl_list.length - 1] = urljoin(m3u8_url, murl_list[murl_list.length - 1])
}
murl_list.forEach(it => {
new_m3u8_body.push(it)
})
}
}
new_m3u8_body = new_m3u8_body.join("\n")
.trim();
m3u8_text = [m3u8_start, new_m3u8_body, m3u8_end].join("\n")
.trim();
return m3u8_text
}
function fixAdM3u8Ai(m3u8_url) {
let ts = (new Date)
.getTime();
function b(s1, s2) {
let i = 0;
while (i < s1.length) {
if (s1[i] !== s2[i]) {
break
}
i++
}
return i
}
function reverseString(str) {
return str.split("")
.reverse()
.join("")
}
let m3u8 = request(m3u8_url);
m3u8 = m3u8.trim()
.split("\n")
.map(it => it.startsWith("#") ? it : urljoin(m3u8_url, it))
.join("\n");
let last_url = m3u8.split("\n")
.slice(-1)[0];
if (last_url.includes(".m3u8") && last_url !== m3u8_url) {
m3u8_url = last_url;
m3u8 = request(m3u8_url)
}
let s = m3u8.trim()
.split("\n")
.filter(it => it.trim())
.join("\n");
let ss = s.split("\n");
let firststr = ss.find(x => !x.startsWith("#"));
let maxl = 0;
let firststrlen = firststr.length;
let ml = Math.round(ss.length / 2)
.toString()
.length;
let laststr = ss.toReversed()
.find(x => {
if (!x.startsWith("#")) {
let k = b(reverseString(firststr), reverseString(x));
maxl = b(firststr, x);
if (firststrlen - maxl <= ml + k) {
return true
}
}
return false
});
log("最后一条切片:" + laststr);
let ad_urls = [];
for (let i = 0; i < ss.length; i++) {
let s = ss[i];
if (!s.startsWith("#")) {
if (b(firststr, s) < maxl) {
ad_urls.push(s);
ss.splice(i - 1, 2);
i = i - 2
} else {
ss[i] = urljoin(m3u8_url, s)
}
} else {
ss[i] = s.replace(/URI=\"(.*)\"/, 'URI="' + urljoin(m3u8_url, "$1") + '"')
}
}
log("处理的m3u8地址:" + m3u8_url);
log("----广告地址----");
log(ad_urls);
m3u8 = ss.join("\n");
log("处理耗时:" + ((new Date)
.getTime() - ts)
.toString());
return m3u8
}
function forceOrder(lists, key, option) { function forceOrder(lists, key, option) {
let start = Math.floor(lists.length / 2); let start = Math.floor(lists.length / 2);
let end = Math.min(lists.length - 1, start + 1); let end = Math.min(lists.length - 1, start + 1);
@ -470,7 +640,7 @@ function pd2(html, parse, uri) {
} }
if (DOM_CHECK_ATTR.test(parse) && !SPECIAL_URL.test(ret)) { if (DOM_CHECK_ATTR.test(parse) && !SPECIAL_URL.test(ret)) {
if (/http/.test(ret)) { if (/http/.test(ret)) {
ret = ret.substr(ret.indexOf("http")) ret = ret.slice(ret.indexOf("http"))
} else { } else {
ret = urljoin(MY_URL, ret) ret = urljoin(MY_URL, ret)
} }
@ -858,43 +1028,73 @@ function homeParse(homeObj) {
} }
} }
if (homeObj.class_parse) { if (homeObj.class_parse) {
let p = homeObj.class_parse.split(";"); if (homeObj.class_parse.startsWith("js:")) {
let _ps = parseTags.getParse(p[0]); var input = homeObj.MY_URL;
_pdfa = _ps.pdfa;
_pdfh = _ps.pdfh;
_pd = _ps.pd;
MY_URL = rule.url;
if (p.length >= 3) {
try { try {
let html = getHtml(homeObj.MY_URL); eval(homeObj.class_parse.replace("js:", ""));
if (html) { if (Array.isArray(input)) {
homeHtmlCache = html; classes = input
let list = _pdfa(html, p[0]);
if (list && list.length > 0) {
list.forEach((it, idex) => {
try {
let name = _pdfh(it, p[1]);
if (homeObj.cate_exclude && new RegExp(homeObj.cate_exclude)
.test(name)) {
return
}
let url = _pd(it, p[2]);
if (p.length > 3 && p[3]) {
let exp = new RegExp(p[3]);
url = url.match(exp)[1]
}
classes.push({
type_id: url.trim(),
type_name: name.trim()
})
} catch (e) {
console.log(`分类列表定位第${idex}个元素正常报错:${e.message}`)
}
})
}
} }
} catch (e) { } catch (e) {
console.log(e.message) log("通过js动态获取分类发生了错误:" + e.message)
}
} else {
let p = homeObj.class_parse.split(";");
let p0 = p[0];
let _ps = parseTags.getParse(p0);
let is_json = p0.startsWith("json:");
_pdfa = _ps.pdfa;
_pdfh = _ps.pdfh;
_pd = _ps.pd;
MY_URL = rule.url;
if (is_json) {
try {
let cms_cate_url = homeObj.MY_URL.replace("ac=detail", "ac=list");
let html = getHtml(cms_cate_url);
if (html) {
if (cms_cate_url === homeObj.MY_URL) {
homeHtmlCache = html
}
let list = _pdfa(html, p0.replace("json:", ""));
if (list && list.length > 0) {
classes = list
}
}
} catch (e) {
console.log(e.message)
}
} else if (p.length >= 3 && !is_json) {
try {
let html = getHtml(homeObj.MY_URL);
if (html) {
homeHtmlCache = html;
let list = _pdfa(html, p0);
if (list && list.length > 0) {
list.forEach((it, idex) => {
try {
let name = _pdfh(it, p[1]);
if (homeObj.cate_exclude && new RegExp(homeObj.cate_exclude)
.test(name)) {
return
}
let url = _pd(it, p[2]);
if (p.length > 3 && p[3]) {
let exp = new RegExp(p[3]);
url = url.match(exp)[1]
}
classes.push({
type_id: url.trim(),
type_name: name.trim()
})
} catch (e) {
console.log(`分类列表定位第${idex}个元素正常报错:${e.message}`)
}
})
}
}
} catch (e) {
console.log(e.message)
}
} }
} }
} }
@ -1567,6 +1767,9 @@ function detailParse(detailObj) {
for (let v of vHeader) { for (let v of vHeader) {
let v_title = _pdfh(v, tab_text) let v_title = _pdfh(v, tab_text)
.trim(); .trim();
if (!v_title) {
v_title = "线路空"
}
console.log(v_title); console.log(v_title);
if (tab_exclude && new RegExp(tab_exclude) if (tab_exclude && new RegExp(tab_exclude)
.test(v_title)) { .test(v_title)) {
@ -1879,6 +2082,9 @@ function init(ext) {
rule.detailUrl = rule.detailUrl || ""; rule.detailUrl = rule.detailUrl || "";
rule.searchUrl = rule.searchUrl || ""; rule.searchUrl = rule.searchUrl || "";
rule.homeUrl = rule.host && rule.homeUrl ? urljoin(rule.host, rule.homeUrl) : rule.homeUrl || rule.host; rule.homeUrl = rule.host && rule.homeUrl ? urljoin(rule.host, rule.homeUrl) : rule.homeUrl || rule.host;
rule.homeUrl = cheerio.jinja2(rule.homeUrl, {
rule: rule
});
rule.detailUrl = rule.host && rule.detailUrl ? urljoin(rule.host, rule.detailUrl) : rule.detailUrl; rule.detailUrl = rule.host && rule.detailUrl ? urljoin(rule.host, rule.detailUrl) : rule.detailUrl;
rule.二级访问前 = rule.二级访问前 || ""; rule.二级访问前 = rule.二级访问前 || "";
if (rule.url.includes("[") && rule.url.includes("]")) { if (rule.url.includes("[") && rule.url.includes("]")) {

265
JS/jsencrypt.js Normal file

File diff suppressed because one or more lines are too long