multi,thread = require("multi"):init() THREAD = multi.integration.THREAD local m = {} m.azlist = {} m.init = THREAD:newFunction(function() local http = require("socket.http") local list = http.request("http://www.mangareader.net/alphabetical") return list end,true) -- return title function m.getList() return m.azlist end function m.storeList(list) local go = false local titles = {} for link,title in list:gmatch("
(.-)
]]) tab.Chapters = {} for link,chapter in data:gmatch([[([^<]+)]]) do if link~="/" and link~="/privacy" then table.insert(tab.Chapters,{Link = "http://www.mangareader.net"..link,Lead = chapter}) end end return tab end local queue = multi:newSystemThreadedJobQueue(16) queue:doToAll(function() multi,thread = require("multi"):init() http = require("socket.http") -- This is important end) queue:registerFunction("getImage",function(pageurl) local page = http.request(pageurl) return page:match([[id="imgholder.-src="([^"]*)]]) end) queue:registerFunction("getPages",function(manga,chapter) local tab = {} local page = http.request(manga.Chapters[chapter].Link) tab.pages = {page:match([[id="imgholder.-src="([^"]*)]])} tab.nextChapter = "http://www.mangareader.net"..page:match([[Next Chapter:.-href="([^"]*)]]) for link,page in page:gmatch([[]]) do table.insert(tab.pages,getImage("http://www.mangareader.net"..link)) end return tab end) -- returns pages m.getPages = function(manga,chapter) local http = require("socket.http") local tab = {} local cc = 0 local page = http.request(manga.Chapters[chapter].Link) tab.pages = {page:match([[id="imgholder.-src="([^"]*)]])} tab.nextChapter = "http://www.mangareader.net"..page:match([[Next Chapter:.-href="([^"]*)]]) local conn = queue.OnJobCompleted(function(jid,link) table.insert(tab.pages,link) cc=cc+1 end) local count = 0 for link,page in page:gmatch([[]]) do queue:pushJob("getImage","http://www.mangareader.net"..link) count = count + 1 end thread.hold(function() return count==#tab.pages end) return tab end return m