#!/usr/bin/lua --4chan automagical imagegrabber require'lfs' require'socket.http' http = socket.http set = {} set.imgq={} ----------- --DEFINES-- ----------- WAIT_TIME=60 MAX_NO_UPDATES=10 --if we get the page more than 10 times with no new images, stop (10 minutes with default settings) DEFAULT_DIR="/home/jlulian38/store/lol_anime/tsukihime/Type name of new folder/lol_wut/idiot_folder/dump" set.dir="" --current dir set.run=true set.nimgcnt=0 function explode(div,str) if (div=='') then return false end local pos,arr = 0,{} -- for each divider found for st,sp in function() return string.find(str,div,pos,true) end do table.insert(arr,string.sub(str,pos,st-1)) -- Attach chars left of current divider pos = sp + 1 -- Jump past current divider end table.insert(arr,string.sub(str,pos)) -- Attach chars right of last divider return arr end function getName(url) t = explode("/",url) return t[#t-2] , t[#t] end function setupscrape(url) a,b = getName(url) --get purtier name print(a,b) -- quick test set.name = a.."-"..b:gsub(".html","") set.url = url set.time=0 set.imgqp = 1 --image queue position end function checkForDup(t,v) for _,v2 in pairs(t) do if v2==v then return true end end return false end function pLog(s) print(os.date(),s) end function addImage(p,v) imgu = v:sub(p,v:find("\"",p)-1) if not checkForDup(set.imgq,imgu) then pLog("Adding "..imgu.." to image queue") table.insert(set.imgq,imgu) set.nimgcnt = 0 end end function scanpage() local url=set.url set.nimgcnt=set.nimgcnt+1 pLog("Getting page: "..url.." count"..set.nimgcnt) b,c,h = http.request(url) pLog("Got page: "..url.." Status: "..c) if c ~= 200 then set.run=false end links = {} for w in string.gmatch(b,"%b<>") do if w:find("= MAX_NO_UPDATES then set.run=false end end function runscrape(url) setupscrape(url) while set.run do doTask() end end function checkDir() if not lfs.attributes(set.dir) then if not lfs.mkdir(set.dir) then self.run=false --FAILURE end end end if arg[1] then set.dir = DEFAULT_DIR .. "/" .. (arg[2] or "") checkDir() runscrape(arg[1]) else print("Lol need an URL") end