-
Notifications
You must be signed in to change notification settings - Fork 24
/
Manganelo.lua
executable file
·103 lines (71 loc) · 2.21 KB
/
Manganelo.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 Manganelo
-- @url https://m.manganelo.com/wwww
-- @author metafates
-- @license MIT
----------------------------------------
----- IMPORTS -----
Html = require("html")
Http = require("http")
--- END IMPORTS ---
----- VARIABLES -----
Client = Http.client()
Base = "https://ww5.manganelo.tv"
--- 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 .. "/search/" .. query)
local result = Client:do_request(request)
local doc = Html.parse(result.body)
local mangas = {}
doc:find(".item-title"):each(function (i, s)
local manga = { name = s:text(), url = Base .. s:attr("href") }
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(".chapter-name"):each(function (i, s)
local chapter = { name = s:text(), url = Base .. s:attr("href") }
chapters[i+1] = chapter
end)
Reverse(chapters)
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)
local request = Http.request("GET", chapterURL)
local result = Client:do_request(request)
local doc = Html.parse(result.body)
local pages = {}
doc:find(".container-chapter-reader img"):each(function (i, s)
local page = { index = i, url = s:attr("data-src") }
pages[i+1] = page
end)
return pages
end
--- END MAIN ---
----- HELPERS -----
function Reverse(t)
local n = #t
local i = 1
while i < n do
t[i],t[n] = t[n],t[i]
i = i + 1
n = n - 1
end
end
--- END HELPERS ---
-- ex: ts=4 sw=4 et filetype=lua