--view http://hentai-chan.me/online/target
--post http://hentai-chan.me/online/%s#page=%d
--full
--thumb http://img4.hentai-chan.me/manganew_webp_thumbs/s/1507470874_shimapan-tachibana-omina-p5-harlem-futaba-hen-/01.webp
--thumb
dofile("base.lua")
task.setThreadCount(35)
--task.setDelay(15000)
baseTimeout = 300
maxErrors = 30
domain = "http://hentai-chan.me/"
oldDomain = domain
jsEmpty = [[]]
index = mutex_open()
mangaIndex = {}
function index_add(link,tags)
index:lock()
local f = io.open("index.txt","ab")
f:write(("%s = "):format(link))
u8.write(f,tags)
f:write("\n")
f:close()
index:unlock()
end
function dumpDataLinks(manga)
local curl = curl_open()
--local url = "http://hentai-chan.me/online/"..manga..".html"
local url = (domain.."online/%s.html"):format(manga)
curl:setOpt(CURLOPT_URL,url)
curl:setOpt(CURLOPT_USERAGENT,"seVII")
curl:setOpt(CURLOPT_COOKIEFILE,"cookies.txt")
curl:setOpt(CURLOPT_COOKIEJAR,"cookies.txt")
curl:setOpt(CURLOPT_REFERER,domain)
local data = nil
local code = 500
local res = 1
local en = 0
repeat
data,res = curl:perform()
if res == 0 then
code = curl:getInfo(CURLINFO_HTTP_CODE)
end
if res ~= 0 or code ~= 200 then
print(string.format("CURL Error %d",res))
en = en + 1
if en > maxErrors then
print("Boolshit happends, %d",res)
return nil
end
end
until res == 0
curl:close()
if data == nil or data == jsEmpty then
local code = curl:getInfo(CURLINFO_HTTP_CODE)
print(res,code)
print"New domain, redirecting.."
_G.oldDomain = domain
domain = "http://exhentaidono.me/"
local ret = dumpDataLinks(manga)
domain = _G.oldDomain
return ret
end
local a = nil
local new = false
if domain ~= _G.oldDomain then
new = true end
if new then
_,a = data:find("\"fullimg\": %[")
else
_,a = data:find("\"fullimg\":%[")
end
if a == nil then
local dbg = io.open("err3.html","wb")
dbg:write(data)
dbg:close()
print("Unspeakable error when parsing "..manga)
return nil
end
local b,_ = (data:sub(a+1)):find("]")
local dat = data:sub(a+1,a+b-2)
if new then
return (dat:gsub('\'', '')):split(", ")
else
return (dat:gsub('"', '')):split(",")
end
end
function download(url)
dofile("base.lua")
local m = task.getGlobal("manga")
local curl = curl_open()
curl:setOpt(CURLOPT_URL,url)
local lst = last(url:split("/"))
local ext = lst:extension()
if ext == nil then
print(string.format("Malformed url %s",url))
curl:close()
return
end
local page,_ = lst:find(ext)
curl:setOpt(CURLOPT_USERAGENT,"seVII")
curl:setOpt(CURLOPT_COOKIEFILE,"cookies.txt")
curl:setOpt(CURLOPT_COOKIEJAR,"cookies.txt")
curl:setOpt(CURLOPT_REFERER,string.format(
task.getGlobal("domain").."online/%s#page=%d",m,page))
curl:setOpt(CURLOPT_TIMEOUT,task.getGlobal("baseTimeout"))
local path = m.."/"..lst
local f = io.open(path,"wb")
if f == nil then
print(("Failed to open %s!"):format(path))
curl:close()
return
end
local code = 500
local res = 1
local en = 0
repeat
f:close()
f = io.open(path,"wb")
res = curl:performFile(f)
if res == 0 then
code = curl:getInfo(CURLINFO_HTTP_CODE)
end
if res ~= 0 or (res == 0 and code ~= 200) then
print("CURL ERROR",res,code)
en = en + 1
end
until code == 200 or en > task.getGlobal("maxErrors")
if res ~= 0 then
print(url)
print"FUCK"
else print(path) end
f:close()
curl:close()
end
function dumpManga(mg)
manga = mg
if mg == nil then
error"SOMETHING WENT VERY VERY WR0000NG"
return
end
if file.exists(manga) then
print(string.format("Manga %s exists!",manga))
return
else file.mkdir(manga) end
local links = {}
local fulls = dumpDataLinks(manga)
if fulls == nil then
print"dumpDataLinks failed"
return
end
for k,v in pairs(fulls) do
if v == nil then
print(("Full %d is nil!"):format(k))
table.remove(fulls,k)
end
end
--for k,v in pairs(fulls) do
-- local i,j = v:find(v:extension())
-- links[k] = v:sub(0,i).."webp"
--end
performMultiTask(download,fulls) --jpg
--performMultiTask(download,links) --webp
end
--