Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support For MangaReader #21

Open
Ari-03 opened this issue Dec 21, 2023 · 1 comment
Open

Add Support For MangaReader #21

Ari-03 opened this issue Dec 21, 2023 · 1 comment

Comments

@Ari-03
Copy link

Ari-03 commented Dec 21, 2023

https://mangareader.to/home is one of the best places to find manga, and I think that it will be cool if it an be added as one of Mangal's sources.

@Ari-03
Copy link
Author

Ari-03 commented Dec 22, 2023

I had been working on an scraper, and have finished the search and manga chapter functions

---------------------------------------
-- @name    MangaReader 
-- @url     https://mangareader.to/
-- @author  aritradas 
-- @license MIT
---------------------------------------


---@alias manga { name: string, url: string, author: string|nil, genres: string|nil, summary: string|nil }
---@alias chapter { name: string, url: string, volume: string|nil, manga_summary: string|nil, manga_author: string|nil, manga_genres: string|nil }
---@alias page { url: string, index: number }


----- IMPORTS -----
Html = require("html")
Time = require("time")
Http = require("http")
HttpUtil = require("http_util")
--- END IMPORTS ---




----- VARIABLES -----
Client = Http.client()
Base = "https://mangareader.to"
Delay = 1 -- seconds
--- END VARIABLES ---



----- MAIN -----

--- Searches for manga with given query.
-- @param query string Query to search for
-- @return manga[] Table of mangas
function SearchManga(query)
    query = query:gsub("’","'")
	local url = Base .. "/search?keyword=" .. HttpUtil.query_escape(query)
    local request = Http.request("GET", url)
    local result = Client:do_request(request)

	local doc = Html.parse(result.body)

	local mangas = {}

	doc:find(".item.item-spc"):each(function(i, r)
        local s = r:find('.manga-name')
		local manga = { name =  trim(s:text():gsub("’","'")),
			url = Base .. r:find('.manga-name > a'):attr("href")}
		mangas[i + 1] = manga
	end)

	return mangas
end


--- Gets the list of all manga chapters.
-- @param mangaURL string URL of the manga
-- @return chapter[] Table of chapters
function MangaChapters(mangaURL)
	local request = Http.request("GET", mangaURL)
    local result = Client:do_request(request)
    local doc = Html.parse(result.body)

	local chapters = {}

	local doc2 = doc:find("#en-chapters"):first()
    doc2:find("a"):each(function (i, s)
        local chapter = { name = trim(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 string URL of the chapter
-- @return page[]
function ChapterPages(chapterURL)
    local request = Http.request("GET", chapterURL)
    local result = Client:do_request(request)
    local doc = Html.parse(result.body)
    local pages = {}

	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

function trim(s)
    return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
  end
  

--- END HELPERS ---

-- ex: ts=4 sw=4 et filetype=lua

But it seems like MangaReader has a weird scramble on their image files Example
I am attaching the way that Tachiyomi descrables the source if anyone would like to work on this as this seems to be too complicated for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant