-
Notifications
You must be signed in to change notification settings - Fork 24
/
Mangasee.lua
148 lines (115 loc) Β· 3.24 KB
/
Mangasee.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
------------------------------------
-- @name Mangasee
-- @url https://mangasee123.com/
-- @author alperen
-- @license MIT
------------------------------------
----- IMPORTS -----
Html = require("html")
Http = require("http")
HttpUtil = require("http_util")
Headless = require("headless")
Strings = require("strings")
--- END IMPORTS ---
----- VARIABLES -----
Client = Http.client()
Browser = Headless.browser()
Base = "https://mangasee123.com"
--- END VARIABLES ---
----- MAIN -----
--- Searches for manga with given query.
--[[
Manga fields:
name - string, required
url - string, required
author - string, optional
genres - string (multiple genres are divided by comma ','), optional
summary - string, optional
--]]
-- @param query Query to search for
-- @return Table of mangas
function SearchManga(query)
local page = Browser:page()
page:navigate(Base .. "/search/?name=" .. HttpUtil.query_escape(query))
page:waitLoad()
local doc = Html.parse(page:html())
local mangas = {}
doc:find(".top-15.ng-scope"):each(function(i, s)
local manga = { name = s:find('.SeriesName[ng-bind-html="Series.s"]'):first():text(),
url = Base .. s:find('.SeriesName[ng-bind-html="Series.s"]'):first():attr("href") }
mangas[i + 1] = manga
end)
return mangas
end
--- Gets the list of all manga chapters.
--[[
Chapter fields:
name - string, required
url - string, required
volume - string, optional
manga_summary - string, optional (in case you can't get it from search page)
manga_author - string, optional
manga_genres - string (multiple genres are divided by comma ','), optional
--]]
-- @param mangaURL URL of the manga
-- @return Table of chapters
function MangaChapters(mangaURL)
local page = Browser:page()
page:navigate(mangaURL)
page:waitLoad()
if page:has('.ShowAllChapters') == true then
page:element('.ShowAllChapters'):click()
end
local doc = Html.parse(page:html())
local chapters = {}
doc:find(".ChapterLink"):each(function(i, s)
local name = s:find('span'):first():text()
name = Strings.trim(name:gsub("[\r\t\n]+", " "), " ")
local chapter = { name = name, url = Base .. s:attr("href") }
chapters[i + 1] = chapter
end)
Reverse(chapters)
return chapters
end
--- Gets the list of all pages of a chapter.
--[[
Page fields:
url - string, required
index - uint, required
--]]
-- @param chapterURL URL of the chapter
-- @return Table of pages
function ChapterPages(chapterURL)
local page = Browser:page()
page:navigate(chapterURL)
page:waitLoad()
page:element('.DesktopNav > div > div:nth-child(4) > button'):click()
local doc = Html.parse(page:html())
local pages = {}
local images = {}
doc:find('.img-fluid'):each(function(i, s)
images[i+1] = tostring(s:attr('src'))
end)
local modal = doc:find("#PageModal"):first()
modal:find('button[ng-click="vm.GoToPage(Page)"]'):each(function(i, s)
local index = tonumber(Strings.trim(s:text():gsub("[\r\t\n]+", " "), " "))
if index ~= nil then
local chapterPage = { index = index, url = images[index] }
pages[index] = chapterPage
end
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