[RU] MangaClub: Rework the extension (#10544)

* [RU] MangaClub: Fixed the incorrect title appearing

* [RU] MangaClub: Rework the extension
This commit is contained in:
Román 2022-01-22 14:51:08 +00:00 committed by GitHub
parent ca9645288f
commit e75475b1dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 135 additions and 112 deletions

View File

@ -5,7 +5,8 @@ ext {
extName = 'MangaClub' extName = 'MangaClub'
pkgNameSuffix = 'ru.mangaclub' pkgNameSuffix = 'ru.mangaclub'
extClass = '.Mangaclub' extClass = '.Mangaclub'
extVersionCode = 4 extVersionCode = 5
isNsfw = true
} }
apply from: "$rootDir/common.gradle" apply from: "$rootDir/common.gradle"

View File

@ -1,6 +1,5 @@
package eu.kanade.tachiyomi.extension.ru.mangaclub package eu.kanade.tachiyomi.extension.ru.mangaclub
import android.net.Uri
import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.POST import eu.kanade.tachiyomi.network.POST
import eu.kanade.tachiyomi.source.model.Filter import eu.kanade.tachiyomi.source.model.Filter
@ -23,176 +22,199 @@ class Mangaclub : ParsedHttpSource() {
override val name: String = "MangaClub" override val name: String = "MangaClub"
override val baseUrl: String = "https://mangaclub.ru" override val baseUrl: String = "https://mangaclub.ru"
override val lang: String = "ru" override val lang: String = "ru"
override val supportsLatest: Boolean = false override val supportsLatest: Boolean = true
override val client: OkHttpClient = network.cloudflareClient override val client: OkHttpClient = network.cloudflareClient
// Popular // Popular
override fun popularMangaRequest(page: Int): Request = GET("$baseUrl/page/$page/", headers) override fun popularMangaRequest(page: Int): Request = GET("$baseUrl/f/sort=rating/order=desc/page/$page/", headers)
override fun popularMangaNextPageSelector(): String = "a i.icon-right-open" override fun popularMangaNextPageSelector(): String = "div.pagination-list>a>.icon-right-open"
override fun popularMangaSelector(): String = "div.shortstory" override fun popularMangaSelector(): String = "div.shortstory"
override fun popularMangaFromElement(element: Element): SManga = SManga.create().apply { override fun popularMangaFromElement(element: Element): SManga = SManga.create().apply {
thumbnail_url = element.select("img").attr("abs:src") thumbnail_url = element.select("div.content-block>.image>picture>img").attr("abs:src")
element.select(".title > a").apply { element.select("div.content-title>.title>a").apply {
title = this.text().trim() title = this.text().trim()
setUrlWithoutDomain(this.attr("abs:href")) setUrlWithoutDomain(this.attr("abs:href"))
} }
} }
// Latest // Latest
override fun latestUpdatesRequest(page: Int): Request = popularMangaRequest(page) override fun latestUpdatesRequest(page: Int): Request = GET("$baseUrl/page/$page/", headers)
override fun latestUpdatesNextPageSelector(): String = popularMangaNextPageSelector() override fun latestUpdatesNextPageSelector(): String = popularMangaNextPageSelector()
override fun latestUpdatesSelector(): String = popularMangaSelector() override fun latestUpdatesSelector(): String = popularMangaSelector()
override fun latestUpdatesFromElement(element: Element): SManga = popularMangaFromElement(element) override fun latestUpdatesFromElement(element: Element): SManga = popularMangaFromElement(element)
// Search // Search
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
if (query.isNotBlank()) { var url = baseUrl
if (query.isNotEmpty()) {
val formBody = FormBody.Builder() val formBody = FormBody.Builder()
.add("do", "search") .add("do", "search")
.add("subaction", "search") .add("subaction", "search")
.add("search_start", page.toString()) .add("search_start", "$page")
.add("full_search", "0") .add("full_search", "0")
.add("result_from", ((page - 1) * 8 + 1).toString()) .add("result_from", "${((page - 1) * 8 + 1)}")
.add("story", query) .add("story", query)
.build() .build()
val searchHeaders = headers.newBuilder().add("Content-Type", "application/x-www-form-urlencoded").build() val searchHeaders = headers.newBuilder().add("Content-Type", "application/x-www-form-urlencoded").build()
return POST("$baseUrl/index.php?do=search", searchHeaders, formBody) return POST("$url/index.php?do=search", searchHeaders, formBody)
} } else {
url += "/f"
val uri = Uri.parse(baseUrl).buildUpon() (if (filters.isEmpty()) getFilterList() else filters).forEach { filter ->
when (filter) {
for (filter in filters) { is GenreList -> {
if (filter is Tag && filter.values[filter.state].isNotEmpty()) { val genresIDs = mutableListOf<String>()
uri.appendEncodedPath("tags/${filter.values[filter.state]}") filter.state.forEach { genre ->
if (genre.state) {
genresIDs += genre.id
}
}
if (genresIDs.isNotEmpty()) {
url += "/n.l.tags=${genresIDs.joinToString(",")}"
}
}
is CategoryList -> {
val categoriesIDs = mutableListOf<String>()
filter.state.forEach { category ->
if (category.state) {
categoriesIDs += category.id
}
}
if (categoriesIDs.isNotEmpty()) {
url += "/o.cat=${categoriesIDs.joinToString(",")}"
}
}
is Status -> {
val statusID = arrayOf("Не выбрано", "Завершен", "Продолжается", "Заморожено/Заброшено")[filter.state]
if (filter.state > 0) {
url += "/status_translation=$statusID"
}
}
is OrderBy -> {
val orderState = if (filter.state!!.ascending) "asc" else "desc"
val orderID = arrayOf("date", "editdate", "title", "comm_num", "news_read", "rating")[filter.state!!.index]
url += "/sort=$orderID/order=$orderState"
}
}
} }
url += "/page/$page"
} }
uri.appendPath("page").appendPath(page.toString()) return GET(url, headers)
return GET(uri.toString(), headers)
} }
override fun searchMangaNextPageSelector(): String = popularMangaNextPageSelector() override fun searchMangaNextPageSelector(): String = popularMangaNextPageSelector()
override fun searchMangaSelector(): String = popularMangaSelector() override fun searchMangaSelector(): String = popularMangaSelector()
override fun searchMangaFromElement(element: Element): SManga = popularMangaFromElement(element) override fun searchMangaFromElement(element: Element): SManga = popularMangaFromElement(element)
// Details // Details
override fun mangaDetailsParse(document: Document): SManga = SManga.create().apply { override fun mangaDetailsParse(document: Document): SManga = SManga.create().apply {
thumbnail_url = document.select("div.image img").attr("abs:src") thumbnail_url = document.select("div.content-block>.image>picture>img").attr("abs:src")
title = document.select("div.info>div>strong").text().trim() title = document.select("div.info>div>strong").text().trim()
author = document.select("a[href*=author]").text().trim() author = document.select("div.info>div>a[href*=author]").text().trim()
artist = author artist = author
status = when (document.select("a[href*=status_translation]")?.first()?.text()) { status = when (document.select("div.info>div>a[href*=status_translation]").text().trim()) {
"Продолжается" -> SManga.ONGOING "Продолжается" -> SManga.ONGOING
"Завершен" -> SManga.COMPLETED "Завершен" -> SManga.COMPLETED
else -> SManga.UNKNOWN else -> SManga.UNKNOWN
} }
description = document.select("div.description").text().trim() description = document.select("div.description").text().trim()
genre = document.select("div.info a[href*=tags]").joinToString(", ") { it.text() } genre = document.select("div.info>div>a[href*=tags]").joinToString(", ") { it.text() }
} }
// Chapters // Chapters
override fun chapterListSelector(): String = ".chapter-item" override fun chapterListSelector(): String = "div.chapters>.chapter-item"
override fun chapterFromElement(element: Element): SChapter = SChapter.create().apply { override fun chapterFromElement(element: Element): SChapter = SChapter.create().apply {
val link = element.select("a") val chapterLink = element.select("div.item-left>a")
name = link.text().trim() name = chapterLink.text().trim()
chapter_number = name.substringAfter("Глава").replace(",", ".").trim().toFloat() chapter_number = name.substringAfter("Глава").trim().toFloat()
setUrlWithoutDomain(link.attr("abs:href")) setUrlWithoutDomain(chapterLink.attr("abs:href"))
date_upload = parseDate(element.select(".date").text().trim()) date_upload = element.select("div.item-right>.date").text().trim().let {
} SimpleDateFormat("dd.MM.yyyy", Locale.US).parse(it)?.time ?: 0
}
private fun parseDate(date: String): Long {
return SimpleDateFormat("dd.MM.yyyy", Locale.US).parse(date)?.time ?: 0
} }
// Pages // Pages
override fun pageListParse(document: Document): List<Page> = mutableListOf<Page>().apply { override fun pageListParse(document: Document): List<Page> = mutableListOf<Page>().apply {
document.select(".manga-lines-page a").forEach { document.select("div.manga-lines-page>a").forEach {
add(Page(it.attr("data-p").toInt(), "", baseUrl.replace("//", "//img.") + "/" + it.attr("data-i"))) add(Page(it.attr("data-p").toInt(), "", "${baseUrl.replace("//", "//img.")}/${it.attr("data-i")}"))
} }
} }
override fun imageUrlParse(document: Document): String = ""
override fun imageUrlParse(document: Document): String =
throw Exception("imageUrlParse Not Used")
// Filters // Filters
private class Categories(values: Array<Pair<String, String>>) : private class GenreList(genres: List<Genre>) : Filter.Group<Genre>("Жанры", genres)
Filter.Select<String>("Категории", values.map { it.first }.toTypedArray()) private class Genre(name: String, val id: String) : Filter.CheckBox(name)
private class CategoryList(categories: List<Category>) : Filter.Group<Category>("Категория", categories)
private class Tag(values: Array<String>) : Filter.Select<String>("Жанр", values) private class Category(name: String, val id: String) : Filter.CheckBox(name)
private class Sort(values: List<Pair<String, String>>) : Filter.Sort(
"Сортировать результат поиска",
values.map { it.first }.toTypedArray(),
Selection(2, false)
)
private class Status : Filter.Select<String>( private class Status : Filter.Select<String>(
"Статус", "Статус",
arrayOf("", "Завершен", "Продолжается", "Заморожено/Заброшено") arrayOf("Не выбрано", "Завершен", "Продолжается", "Заморожено/Заброшено")
)
private class OrderBy : Filter.Sort(
"Сортировка",
arrayOf("По дате добавления", "По дате обновления", "В алфавитном порядке", "По количеству комментариев", "По количеству просмотров", "По рейтингу"),
Selection(0, false)
) )
override fun getFilterList() = FilterList( override fun getFilterList() = FilterList(
Filter.Header("NOTE: Filters are ignored if using text search."), GenreList(getGenreList()),
Tag(tag) Status(),
CategoryList(getCategoryList()),
OrderBy()
) )
private val categoriesArray = arrayOf( private fun getCategoryList() = listOf(
Pair("", ""), Category("Манга", "1"),
Pair("Манга", "1"), Category("Манхва", "2"),
Pair("Манхва", "2"), Category("Маньхуа", "3"),
Pair("Маньхуа", "3"), Category("Веб-манхва", "6")
Pair("Веб-манхва", "6")
) )
private val tag = arrayOf( private fun getGenreList() = listOf(
"", Genre("Боевик", "боевик"),
"Боевые искусства", Genre("Боевые искусства", "боевые+искусства"),
"Боевик", Genre("Вампиры", "вампиры"),
"Вампиры", Genre("Гарем", "гарем"),
"Гарем", Genre("Гендерная интрига", "гендерная+интрига"),
"Гендерная интрига", Genre("Героическое фэнтези", "героическое+фэнтези"),
"Героическое фэнтези", Genre("Детектив", "детектив"),
"Додзинси", Genre("Дзёсэй", "дзёсэй"),
"Дзёсэй", Genre("Додзинси", "додзинси"),
"Драма", Genre("Драма", "драма"),
"Детектив", Genre("Игра", "игра"),
"Игра", Genre("История", "история"),
"История", Genre("Киберпанк", "киберпанк"),
"Киберпанк", Genre("Комедия", "комедия"),
"Комедия", Genre("Махо-сёдзё", "махо-сёдзё"),
"Мистика", Genre("Меха", "меха"),
"Меха", Genre("Мистика", "мистика"),
"Махо-сёдзё", Genre("Музыка", "музыка"),
"Научная фантастика", Genre("Научная фантастика", "научная+фантастика"),
"Повседневность", Genre("Перерождение", "перерождение"),
"Приключения", Genre("Повседневность", "повседневность"),
"Психология", Genre("Постапокалиптика", "постапокалиптика"),
"Романтика", Genre("Приключения", "приключения"),
"Самурайский боевик", Genre("Психология", "психология"),
"Сверхъестественное", Genre("Романтика", "романтика"),
"Сёдзё", Genre("Самурайский боевик", "самурайский+боевик"),
"Сёдзё для взрослых", Genre("Сборник", "сборник"),
"Сёдзё-ай", Genre("Сверхъестественное", "сверхъестественное"),
"Сёнэн", Genre("Сингл", "сингл"),
"Сёнэн-ай", Genre("Спорт", "спорт"),
"Спокон", Genre("Сэйнэн", "сэйнэн"),
"Сэйнэн", Genre("Сёдзё", "сёдзё"),
"Спорт", Genre("Сёдзё для взрослых", "сёдзе+для+взрослых"),
"Трагедия", Genre("Сёдзё-ай", "сёдзё-ай"),
"Триллер", Genre("Сёнэн", "сёнэн"),
"Ужасы", Genre("Сёнэн-ай", "сёнэн-ай"),
"Фантастика", Genre("Трагедия", "трагедия"),
"Фэнтези", Genre("Триллер", "триллер"),
"Школа", Genre("Ужасы", "ужасы"),
"Эротика", Genre("Фантастика", "фантастика"),
"Этти", Genre("Фэнтези", "фэнтези"),
"Юри", Genre("Школа", "школа"),
"Яой" Genre("Эротика", "эротика"),
) Genre("Ёнкома", "ёнкома"),
Genre("Этти", "этти"),
private val sortables = listOf( Genre("Юри", "юри"),
Pair("По заголовку", "title"), Genre("Яой", "яой")
Pair("По количеству комментариев", "comm_num"),
Pair("По количеству просмотров", "news_read"),
Pair("По имени автора", "autor"),
Pair("По рейтингу", "rating")
) )
} }