local curl = require "lcurl.safe"
local json = require "cjson.safe"
script_info = {
["title"] = "KinhDown引擎",
}
function request(url,header)
local r = ""
local c = curl.easy{
url = url,
httpheader = header,
ssl_verifyhost = 0,
ssl_verifypeer = 0,
followlocation = 1,
timeout = 30,
proxy = pd.getProxy(),
writefunction = function(buffer)
r = r .. buffer
return #buffer
end,
}
local _, e = c:perform()
c:close()
return r
end
function getsub(str,as,ae)
local StrLen = string.len(str)
local as_Len = string.len(as)
local ae_Len = string.len(ae)
local as_x = string.find(str, as, 1)
local ae_x = string.find(str, ae, as_x+1)
local rs = (string.sub(str, as_x+as_Len, ae_x-1))
return rs
end
function onInitTask(task, user, file)
if task:getType() == TASK_TYPE_BAIDU or task:getType() == TASK_TYPE_SHARE_BAIDU then
local dlink = ""
if task:getType() == TASK_TYPE_BAIDU then
local header = {}
table.insert(header, "User-Agent: netdisk")
table.insert(header, "Cookie: BDUSS="..user:getBDUSS())
local fsid = string.format("%d",file.id)
local url = "https://pan.baidu.com/rest/2.0/xpan/multimedia?method=filemetas&dlink=1&fsids=%5b"..fsid.."%5d"
local result = request(url,header)
local resultjson = json.decode(result)
if resultjson == nil then
task:setError(-1,"网络错误")
pd.logError('网络超时')
return true
end
local dlink = resultjson.list[1].dlink
Path = string.gsub(string.gsub(dlink, "https://d.pcs.baidu.com/file/", ""),"?fid","&fid")
end
if task:getType() == TASK_TYPE_SHARE_BAIDU then
local uk = getsub(file.dlink,"?fid=","-250528-")
local shareid = getsub(file.dlink,"&shareid=","&")
local md5 = getsub(file.dlink,"https://d.pcs.baidu.com/file/","?fid")
local header = {}
table.insert(header, "User-Agent: netdisk;11.6.3;android-android;11.0;JSbridge4.4.0")
local url = "https://api.kinh.cc/BaiDu/Check/ShUIDSite.php?shareid="..shareid.."&uk="..uk
local result = request(url,header)
local sige = getsub(result,'sige":"','","')
local devuid = getsub(result,'devuid":"','","')
local timestamp = getsub(result,'time":','}')
local url = "https://pan.baidu.com/share/list?app_id=250528&clienttype=1&channel=android_11_netdisk&needsublist=1&version=11.6.3&vip=2&shareid="..shareid.."&uk="..uk.."&fid="..file.id.."&sign="..sige.."×tamp="..timestamp.."&devuid="..devuid.."&time="..timestamp
local result = request(url,header)
local resultjson = json.decode(result)
local dlink = resultjson.list[1].dlink
if dlink == nil then
task:setError(-1,"无法生成PCS链接")
return true
end
Path = string.gsub(string.gsub(dlink, "http://d.pcs.baidu.com/file/", ""),"?fid","&fid")
end
local header = {}
table.insert(header, "User-Agent: Mozilla/5.0 (KinhDown[DP]Web;PD;2021-2-25;14-40)")
local url = "https://pan.kdbaidu.com/Parsing.php?Path="..pd.urlEncode(Path).."&Key="..pd.getConfig("Baidu","accelerateURL")
local result = request(url,header)
local resultjson = json.decode(result)
if resultjson.Code == "-1" then
task:setError(-1,resultjson.Error)
return true
end
if resultjson.Code == "0" then
task:setUris(resultjson.dlink)
task:setOptions("user-agent", resultjson.ua)
task:setOptions("piece-length", resultjson.length.."M")
task:setOptions("max-connection-per-server",resultjson.split)
task:setOptions("split",resultjson.split)
task:setOptions("header","Range: bytes="..resultjson.bytes)
task:setOptions("allow-piece-length-change","true")
task:setOptions("enable-http-pipelining","true")
end
return true
end
转自https://kinhdown.kinh.cc/