Skip to content
This repository has been archived by the owner on Dec 5, 2022. It is now read-only.

ReaperScans rewrite #431

Draft
wants to merge 3 commits into
base: dev
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
185 changes: 138 additions & 47 deletions src/en/ReaperScans.lua
Original file line number Diff line number Diff line change
@@ -1,51 +1,142 @@
-- {"id":4223,"ver":"1.0.4","libVer":"1.0.0","author":"MechTechnology","dep":["Madara>=2.3.0"]}
-- {"id":4223,"ver":"2.0.0","libVer":"1.0.0","author":"Doomsdayrs"}

return Require("Madara")("https://reaperscans.com", {
local baseURL = "https://reaperscans.com"

local function shrinkURL(url)
return url:match(baseURL .. "/novels/(.+)/")
end

local function expandURL(url)
return baseURL .. "/novels/" .. url
end

local function getPassage(chapterURL)
local url = baseURL .. "/" .. chapterURL
local document = GETDocument(url)
local htmlElement = document:selectFirst("section.p-2")

return pageOfElem(htmlElement, true)
end

local function parseNovel(novelURL)
local url = baseURL .. "/" .. novelURL
local document = GETDocument(url):selectFirst("article.post")
local novelInfo = NovelInfo()

local headerNChapters = document:selectFirst("div.p-2.space-y-4")

-- Header
local headerElement = headerNChapters:selectFirst("div.mx-auto")

local titleElement = headerNChapters:selectFirst("h1")
novelInfo:setTitle(titleElement:text())

local imageElement = headerElement:selectFirst("img")
novelInfo:setImageURL(imageElement:attr("src"))

-- About
local aboutElement = document:selectFirst("div.lg\:col-span-1")

local descriptionElement = aboutElement:selectFirst("p")
novelInfo:setDescription(descriptionElement:text():gsub("<br>","\n"))

local otherElements = document:selectFirst("dl.mt-2"):select("dd")

local languageElement = otherElements[0]
novelInfo:setLanguage(languageElement:text())

local statusElement = otherElements[1]
local status = statusElement:text()
novelInfo:setStatus(NovelStatus(status == "Completed" and 1 or status == "Ongoing" and 0 or 3))

-- Chapters
local chaptersBoxElement = headerNChapters:selectFirst("pb-4"):selectFirst("ul")

local pages = 0
pages = chaptersBoxElement:selectFirst("div.releative.z-0"):select("button"):size()

-- After the following loop, this array will contain a list of chapters reversed.
local chapterElements = {}
chapterElements.concat(chaptersBoxElement:select("li"))

for page = 0, pages, 1
do
document = GETDocument(url .. "?page=" .. page):selectFirst("article.post")
headerNChapters = document:selectFirst("div.p-2.space-y-4")
chaptersBoxElement = headerNChapters:selectFirst("pb-4"):selectFirst("ul")
chapterElements.concat(chaptersBoxElement:select("li"))
end

local count = 0
local chapters = map(
chapterElements,
function(chapter)
local c = NovelChapter()
c:setTitle(chapter:selectFirst("p"):text())
c:setLink(chapter:selectFirst("a"):attr("href"))

-- count the chapters
count = count + 1
return c
end
)
chapters = map(
chapters,
function(chapter)
chapter:setOrder(count)
count = count - 1
return chapter
end
)
Reverse(chapters)
novelInfo:setChapters(chapters)

return novelInfo
end

return {
id = 4223,
name = "Reaper Scans",
baseURL = baseURL,
imageURL = "https://github.com/shosetsuorg/extensions/raw/dev/icons/ReaperScans.png",
chaptersScriptLoaded = false,
chaptersListSelector= "li.wp-manga-chapter.free-chap",
latestNovelSel = ".col-4.col-md-2.badge-pos-2",
novelListingURLPath = "all-series/novels",
shrinkURLNovel = "series",
searchHasOper = true,

genres = {
"Action",
"Adult",
"Adventure",
"Comedy",
"Crime",
"Drama",
"Ecchi",
"Fantasy",
"Harem",
"Historical",
"Horror",
"Isekai",
"Manhua",
"Manhwa",
"Martial Arts",
"Mature",
"Mecha",
"Mystery",
"Novel",
"Psychological",
"Romance",
"School Life",
"Sci-fi",
"Seinen",
"Shoujo",
"Shounen",
["slice-of-life"] = "Slice of Life",
"Sports",
"Supernatural",
"Tragedy",
["complete"] = "Completed",
["on-going"] = "Ongoing",
"Canceled",
"On Hold",
"On Hold",
}
})
hasSearch = true,
chapterType = ChapterType.HTML,

shrinkURL = shrinkURL,
expandURL = expandURL,

listings = {
Listing("Latest", true, function(data)
local url = baseURL .. "/latest/novels"

local d = GETDocument(url)

return map(d:select("div.relative.flex.space-x-2"), function(v)
local lis = Novel()
lis:setImageURL(v:selectFirst("img"):attr("src"))
local title = v:selectFirst("p.text-sm"):selectFirst("a")
lis:setLink(shrinkURL(title:attr("href")))
lis:setTitle(title:text())
return lis
end)
end),
Listing("All", true, function(data)
local url = baseURL .. "/novels"

local d = GETDocument(url)

return map(d:select("li.col-span-1"), function(v)
local lis = Novel()
lis:setImageURL(v:selectFirst("img"):attr("src"))
local title = v:selectFirst("p.text-sm")
lis:setLink(shrinkURL(title:attr("href")))
lis:setTitle(title:text())
return lis
end)
end),
},
getPassage = getPassage,
parseNovel = parseNovel,
hasSearch = false
--search = search
}