forked from metafates/mangal-scrapers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LuminousScans.lua
103 lines (70 loc) · 2.22 KB
/
LuminousScans.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
-------------------------------------
-- @name LuminousScans
-- @url https://luminousscans.com
-- @author metafates
-- @license MIT
-------------------------------------
----- IMPORTS -----
Http = require("http")
Headless = require("headless")
Html = require("html")
Time = require("time")
--- END IMPORTS ---
----- VARIABLES -----
Client = Http.client()
Browser = Headless.browser()
Page = Browser:page()
Base = "https://luminousscans.com"
--- END VARIABLES ---
----- MAIN -----
--- Searches for manga with given query.
-- @param query Query to search for
-- @return Table of tables with the following fields: name, url
function SearchManga(query)
local request = Http.request("GET", Base .. "/?s=" .. query)
local result = Client:do_request(request)
local doc = Html.parse(result.body)
local mangas = {}
doc:find(".bsx > a"):each(function(i, s)
local manga = { url = s:attr("href"), name = s:attr("title") }
mangas[i+1] = manga
end)
return mangas
end
--- Gets the list of all manga chapters.
-- @param mangaURL URL of the manga
-- @return Table of tables with the following fields: name, url
function MangaChapters(mangaURL)
local request = Http.request("GET", mangaURL)
local result = Client:do_request(request)
local doc = Html.parse(result.body)
local chapters = {}
doc:find("#chapterlist ul li"):each(function(_, s)
local n, _ = s:attr("data-num")
local index = tonumber(n)
local url = s:find("a"):first():attr("href")
local name = s:find("span"):first():text()
local chapter = { url = url, name = name }
if index == nil then
return
end
chapters[index] = chapter
end)
return chapters
end
--- Gets the list of all pages of a chapter.
-- @param chapterURL URL of the chapter
-- @return Table of tables with the following fields: url, index
function ChapterPages(chapterURL)
Page:navigate(chapterURL)
Time.sleep(1)
local pages = {}
for i, v in ipairs(Page:elements("#readerarea p > img")) do
pages[i+1] = { index = i, url = v:attribute("src") }
end
return pages
end
--- END MAIN ---
----- HELPERS -----
--- END HELPERS ---
-- ex: ts=4 sw=4 et filetype=lua