From 12673dbc0e13aadf0f16bf0074f96474f4fed053 Mon Sep 17 00:00:00 2001 From: Carlos Date: Fri, 26 Jan 2018 11:09:51 -0500 Subject: [PATCH] Update changes for mangadex (#170) * fixed latest updates fix genre tags add genre filter when searching added paging for browse * switch search selector to use popular * switched to scanlator to group not user who uploaded * fix some chapters on random manga not loading images * null safety --- src/en/mangadex/build.gradle | 4 +- .../extension/en/mangadex/Mangadex.kt | 101 +++++++++++++++--- 2 files changed, 88 insertions(+), 17 deletions(-) diff --git a/src/en/mangadex/build.gradle b/src/en/mangadex/build.gradle index 9fe36827b..4453d3765 100644 --- a/src/en/mangadex/build.gradle +++ b/src/en/mangadex/build.gradle @@ -6,8 +6,8 @@ ext { appName = 'Tachiyomi: MangaDex' pkgNameSuffix = "en.mangadex" extClass = '.Mangadex' - extVersionCode = 1 - extVersionSuffix = 1 + extVersionCode = 2 + extVersionSuffix = 2 libVersion = '1.2' } diff --git a/src/en/mangadex/src/eu/kanade/tachiyomi/extension/en/mangadex/Mangadex.kt b/src/en/mangadex/src/eu/kanade/tachiyomi/extension/en/mangadex/Mangadex.kt index 6805770c1..444af7a4e 100644 --- a/src/en/mangadex/src/eu/kanade/tachiyomi/extension/en/mangadex/Mangadex.kt +++ b/src/en/mangadex/src/eu/kanade/tachiyomi/extension/en/mangadex/Mangadex.kt @@ -19,16 +19,17 @@ class Mangadex : ParsedHttpSource() { override val lang = "en" - val internalLang = "gb" + private val internalLang = "gb" override val client = network.cloudflareClient - override fun popularMangaSelector() = latestUpdatesSelector() + override fun popularMangaSelector() = ".table-responsive tbody tr" - override fun latestUpdatesSelector() = ".table-responsive tbody tr" + override fun latestUpdatesSelector() = ".table-responsive tbody tr a.manga_title[href*=manga]" override fun popularMangaRequest(page: Int): Request { - return GET("$baseUrl/?page=search", headers) + val pageStr = if (page != 1) "//" + ((page * 100) - 100) else "" + return GET("$baseUrl/titles$pageStr", headers) } override fun latestUpdatesRequest(page: Int): Request { @@ -36,37 +37,51 @@ class Mangadex : ParsedHttpSource() { } override fun popularMangaFromElement(element: Element): SManga { - return latestUpdatesFromElement(element) - } - - override fun latestUpdatesFromElement(element: Element): SManga { val manga = SManga.create() element.select("a[href*=manga]").first().let { manga.setUrlWithoutDomain(it.attr("href")) manga.title = it.text().trim() - manga.author = it.text().trim() + manga.author = it?.text()?.trim() } return manga } - override fun popularMangaNextPageSelector() = null + override fun latestUpdatesFromElement(element: Element): SManga { + val manga = SManga.create() + element.let { + manga.setUrlWithoutDomain(it.attr("href")) + manga.title = it.text().trim() + } + return manga + } + + override fun popularMangaNextPageSelector() = ".pagination li:not(.disabled) span[title*=last page]:not(disabled)" override fun latestUpdatesNextPageSelector() = null override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { val url = HttpUrl.parse("$baseUrl/?page=search")!!.newBuilder().addQueryParameter("title", query) + val genres = mutableListOf() + (if (filters.isEmpty()) getFilterList() else filters).forEach { filter -> when (filter) { is TextField -> url.addQueryParameter(filter.key, filter.state) + is GenreList -> filter.state.forEach { genre -> + when (genre.state) { + true -> genres.add(genre.id) + } + } } } + if (genres.isNotEmpty()) url.addQueryParameter("genre", genres.joinToString(",")) + return GET(url.toString(), headers) } override fun searchMangaSelector() = ".table.table-striped.table-hover.table-condensed tbody tr" override fun searchMangaFromElement(element: Element): SManga { - return latestUpdatesFromElement(element) + return popularMangaFromElement(element) } override fun searchMangaNextPageSelector() = null @@ -75,13 +90,16 @@ class Mangadex : ParsedHttpSource() { val manga = SManga.create() val imageElement = document.select(".table-condensed").first() val infoElement = document.select(".table.table-condensed.edit").first() + val genreElement = infoElement.select("tr:eq(3) td .genre") manga.author = infoElement.select("tr:eq(1) td").first()?.text() manga.artist = infoElement.select("tr:eq(2) td").first()?.text() manga.status = parseStatus(infoElement.select("tr:eq(5) td").first()?.text()) manga.description = infoElement.select("tr:eq(7) td").first()?.text() manga.thumbnail_url = imageElement.select("img").first()?.attr("src").let { baseUrl + "/" + it } - manga.genre = infoElement.select("tr:eq(3) td").first()?.text() + var genres = mutableListOf() + genreElement?.forEach { genres.add(it.text()) } + manga.genre = genres.joinToString(", ") return manga } @@ -91,7 +109,7 @@ class Mangadex : ParsedHttpSource() { override fun chapterFromElement(element: Element): SChapter { val urlElement = element.select("td:eq(0)").first() val dateElement = element.select("td:eq(6)").first() - val scanlatorElement = element.select("td:eq(3)").first() + val scanlatorElement = element.select("td:eq(2)").first() val chapter = SChapter.create() chapter.url = (urlElement.select("a").attr("href")) @@ -114,7 +132,14 @@ class Mangadex : ParsedHttpSource() { return pages } - override fun imageUrlParse(document: Document) = baseUrl + document.select("#current_page").first().attr("src") + override fun imageUrlParse(document: Document): String { + val attr = document.select("#current_page").first().attr("src") + + if (attr.startsWith("http")) { + return attr + } + return baseUrl + attr + } private fun parseStatus(status: String?) = when { status == null -> SManga.UNKNOWN @@ -125,10 +150,56 @@ class Mangadex : ParsedHttpSource() { } private class TextField(name: String, val key: String) : Filter.Text(name) + private class Genre(val id: String, name: String) : Filter.CheckBox(name) + private class GenreList(genres: List) : Filter.Group("Genres", genres) + override fun getFilterList() = FilterList( TextField("Author", "author"), - TextField("Artist", "artist") + TextField("Artist", "artist"), + GenreList(getGenreList()) ) + private fun getGenreList() = listOf( + Genre("1", "4-koma"), + Genre("2", "Action"), + Genre("3", "Adventure"), + Genre("4", "Award Winning"), + Genre("5", "Comedy"), + Genre("6", "Cooking"), + Genre("7", "Doujinshi"), + Genre("8", "Drama"), + Genre("9", "Ecchi"), + Genre("10", "Fantasy"), + Genre("11", "Gender Bender"), + Genre("12", "Harem"), + Genre("13", "Historical"), + Genre("14", "Horror"), + Genre("15", "Josei"), + Genre("16", "Martial Arts"), + Genre("17", "Mecha"), + Genre("18", "Medical"), + Genre("19", "Music"), + Genre("20", "Mystery"), + Genre("21", "Oneshot"), + Genre("22", "Psychological"), + Genre("23", "Romance"), + Genre("24", "School Life"), + Genre("25", "Sci-Fi"), + Genre("26", "Seinen"), + Genre("27", "Shoujo"), + Genre("28", "Shoujo Ai"), + Genre("29", "Shounen"), + Genre("30", "Shounen Ai"), + Genre("31", "Slice of Life"), + Genre("32", "Smut"), + Genre("33", "Sports"), + Genre("34", "Supernatural"), + Genre("35", "Tragedy"), + Genre("36", "Webtoon"), + Genre("37", "Yaoi"), + Genre("38", "Yuri"), + Genre("39", "[no chapters]"), + Genre("40", "Game") + ) } \ No newline at end of file