From d8c5ca853425a4f934d0bae4d9899df1c3294e3e Mon Sep 17 00:00:00 2001 From: Vesnyx Date: Fri, 12 Jul 2019 23:31:03 +0000 Subject: [PATCH] Madara: Refactor and added new sources (#1190) --- src/all/madara/build.gradle | 2 +- .../tachiyomi/extension/all/madara/Madara.kt | 105 ++++++++++++----- .../extension/all/madara/MadaraFactory.kt | 109 +++++++----------- 3 files changed, 116 insertions(+), 100 deletions(-) diff --git a/src/all/madara/build.gradle b/src/all/madara/build.gradle index a01fadc4c..8c5c3c249 100644 --- a/src/all/madara/build.gradle +++ b/src/all/madara/build.gradle @@ -5,7 +5,7 @@ ext { appName = 'Tachiyomi: Madara' pkgNameSuffix = "all.madara" extClass = '.MadaraFactory' - extVersionCode = 2 + extVersionCode = 3 libVersion = '1.2' } diff --git a/src/all/madara/src/eu/kanade/tachiyomi/extension/all/madara/Madara.kt b/src/all/madara/src/eu/kanade/tachiyomi/extension/all/madara/Madara.kt index 84074c120..15d5fee2e 100644 --- a/src/all/madara/src/eu/kanade/tachiyomi/extension/all/madara/Madara.kt +++ b/src/all/madara/src/eu/kanade/tachiyomi/extension/all/madara/Madara.kt @@ -1,6 +1,5 @@ package eu.kanade.tachiyomi.extension.all.madara -import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.source.model.* import eu.kanade.tachiyomi.source.online.ParsedHttpSource import okhttp3.* @@ -9,8 +8,13 @@ import org.jsoup.nodes.Element import java.text.ParseException import java.text.SimpleDateFormat import java.util.* +import eu.kanade.tachiyomi.source.model.FilterList +import okhttp3.CacheControl +import okhttp3.FormBody +import okhttp3.Request +import eu.kanade.tachiyomi.network.POST -abstract class Madara( +open class Madara( override val name: String, override val baseUrl: String, override val lang: String, @@ -40,13 +44,54 @@ abstract class Madara( return manga } + override fun popularMangaRequest(page: Int): Request { + val form = FormBody.Builder().apply { + add("action", "madara_load_more") + add("page", (page-1).toString()) + add("template", "madara-core/content/content-archive") + add("vars[orderby]", "meta_value_num") + add("vars[paged]", "1") + add("vars[posts_per_page]", "20") + add("vars[post_type]", "wp-manga") + add("vars[post_status]", "publish") + add("vars[meta_key]", "_wp_manga_views") + add("vars[order]", "desc") + add("vars[sidebar]", "full") + add("vars[manga_archives_item_layout]", "big_thumbnail") + } + return POST("$baseUrl/wp-admin/admin-ajax.php", headers, form.build(), CacheControl.FORCE_NETWORK) + } + + override fun popularMangaNextPageSelector(): String? = "body:not(:has(.no-posts))" + // Latest Updates - override fun latestUpdatesRequest(page: Int): Request = GET(baseUrl) + override fun latestUpdatesSelector() = "div.page-item-detail" - override fun latestUpdatesSelector() = "div.item__wrap" + override fun latestUpdatesFromElement(element: Element): SManga { + // Even if it's different from the popular manga's list, the relevant classes are the same + return popularMangaFromElement(element) + } - override fun latestUpdatesNextPageSelector(): String? = null + override fun latestUpdatesRequest(page: Int): Request { + val form = FormBody.Builder().apply { + add("action", "madara_load_more") + add("page", (page-1).toString()) + add("template", "madara-core/content/content-archive") + add("vars[orderby]", "meta_value_num") + add("vars[paged]", "1") + add("vars[posts_per_page]", "20") + add("vars[post_type]", "wp-manga") + add("vars[post_status]", "publish") + add("vars[meta_key]", "_latest_update") + add("vars[order]", "desc") + add("vars[sidebar]", "right") + add("vars[manga_archives_item_layout]", "big_thumbnail") + } + return POST("$baseUrl/wp-admin/admin-ajax.php", headers, form.build(), CacheControl.FORCE_NETWORK) + } + + override fun latestUpdatesNextPageSelector(): String? = "body:not(:has(.no-posts))" override fun latestUpdatesParse(response: Response): MangasPage { val mp = super.latestUpdatesParse(response) @@ -54,13 +99,24 @@ abstract class Madara( return MangasPage(mangas, mp.hasNextPage) } - override fun latestUpdatesFromElement(element: Element): SManga { - // Even if it's different from the popular manga's list, the relevant classes are the same - return popularMangaFromElement(element) - } - // Search Manga + override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { + val form = FormBody.Builder().apply { + add("action", "madara_load_more") + add("page", (page-1).toString()) + add("template", "madara-core/content/content-search") + add("vars[s]", query) + add("vars[orderby]", "") + add("vars[paged]", (page-1).toString()) + add("vars[template]", "search") + add("vars[post_type]", "wp-manga") + add("vars[post_status]", "publish") + add("vars[manga_archives_item_layout]", "default") + } + return POST("$baseUrl/wp-admin/admin-ajax.php", headers, form.build(), CacheControl.FORCE_NETWORK) + } + override fun searchMangaSelector() = "div.c-tabs-item__content" override fun searchMangaFromElement(element: Element): SManga { @@ -74,23 +130,6 @@ abstract class Madara( select("img").first()?.let { manga.thumbnail_url = it.absUrl(if(it.hasAttr("data-src")) "data-src" else "src") } - select("div.mg_author div.summary-content a").first()?.let { - manga.author = it.text() - } - select("div.mg_artists div.summary-content a").first()?.let { - manga.artist = it.text() - } - select("div.mg_genres div.summary-content a").first()?.let { - manga.genre = it.text() - } - select("div.mg_status div.summary-content a").first()?.let { - manga.status = when(it.text()) { - // I don't know what's the corresponding for COMPLETED and LICENSED - // There's no support for "Canceled" or "On Hold" - "OnGoing" -> SManga.ONGOING - else -> SManga.UNKNOWN - } - } } return manga @@ -121,6 +160,14 @@ abstract class Madara( select("div.summary_image img").first()?.let { manga.thumbnail_url = it.absUrl(if(it.hasAttr("data-src")) "data-src" else "src") } + select("div.summary-content").last()?.let { + manga.status = when(it.text()) { + // I don't know what's the corresponding for COMPLETED and LICENSED + // There's no support for "Canceled" or "On Hold" + "OnGoing", "Продолжается", "Updating" -> SManga.ONGOING + else -> SManga.UNKNOWN + } + } } return manga @@ -153,7 +200,7 @@ abstract class Madara( parseRelativeDate(lcDate)?.let { return it } //Handle 'yesterday' and 'today', using midnight - if (lcDate.startsWith("ayer")) + if (lcDate.startsWith("year")) return Calendar.getInstance().apply { add(Calendar.DAY_OF_MONTH, -1) //yesterday set(Calendar.HOUR_OF_DAY, 0) @@ -208,4 +255,4 @@ abstract class Madara( } override fun imageUrlParse(document: Document) = throw UnsupportedOperationException("Not used") -} \ No newline at end of file +} diff --git a/src/all/madara/src/eu/kanade/tachiyomi/extension/all/madara/MadaraFactory.kt b/src/all/madara/src/eu/kanade/tachiyomi/extension/all/madara/MadaraFactory.kt index 74fc026dc..49a162e29 100644 --- a/src/all/madara/src/eu/kanade/tachiyomi/extension/all/madara/MadaraFactory.kt +++ b/src/all/madara/src/eu/kanade/tachiyomi/extension/all/madara/MadaraFactory.kt @@ -1,84 +1,53 @@ package eu.kanade.tachiyomi.extension.all.madara -import eu.kanade.tachiyomi.network.GET -import eu.kanade.tachiyomi.network.POST + import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.SourceFactory -import eu.kanade.tachiyomi.source.model.FilterList -import okhttp3.CacheControl -import okhttp3.FormBody -import okhttp3.Request import java.text.SimpleDateFormat import java.util.* +import eu.kanade.tachiyomi.network.GET +import eu.kanade.tachiyomi.source.model.FilterList +import okhttp3.Request class MadaraFactory : SourceFactory { override fun createSources(): List = listOf( - Mangasushi(), - NinjaScans(), - ReadManhua(), - ZeroScans() + Mangasushi(), + NinjaScans(), + ReadManhua(), + ZeroScans(), + IsekaiScanCom(), + HappyTeaScans(), + JustForFun(), + AoCTranslations(), + Kanjiku(), + KomikGo(), + LuxyScans(), + TritiniaScans(), + TsubakiNoScan(), + YokaiJump(), + ZManga() ) } -class Mangasushi : LoadMadara("Mangasushi", "https://mangasushi.net", "en") { - override fun latestUpdatesSelector() = "div.page-item-detail" -} -class NinjaScans : PageMadara("NinjaScans", "https://ninjascans.com", "en", urlModifier = "/manhua") -class ReadManhua : LoadMadara("ReadManhua", "https://readmanhua.net", "en", dateFormat = SimpleDateFormat("dd MMM yy", Locale.US)) -class ZeroScans : PageMadara("ZeroScans", "https://zeroscans.com", "en") - -open class LoadMadara( - name: String, - baseUrl: String, - lang: String, - dateFormat: SimpleDateFormat = SimpleDateFormat("MMMM dd, yyyy", Locale.US) -) : Madara(name, baseUrl, lang, dateFormat) { - override fun popularMangaRequest(page: Int): Request { - val form = FormBody.Builder().apply { - add("action", "madara_load_more") - add("page", (page-1).toString()) - add("template", "madara-core/content/content-archive") - add("vars[manga_archives_item_layout]", "default") - add("vars[meta_key]", "_latest_update") - add("vars[order]", "desc") - add("vars[paged]", (page-1).toString()) - add("vars[post_status]", "publish") - add("vars[post_type]", "wp-manga") - add("vars[sidebar]", "right") - add("vars[template]", "archive") - } - return POST("$baseUrl/wp-admin/admin-ajax.php", headers, form.build(), CacheControl.FORCE_NETWORK) - } - - override fun popularMangaNextPageSelector(): String? = "body:not(:has(.no-posts))" - - override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { - val form = FormBody.Builder().apply { - add("action", "madara_load_more") - add("page", (page-1).toString()) - add("template", "madara-core/content/content-search") - add("vars[s]", query) - add("vars[orderby]", "") - add("vars[paged]", (page-1).toString()) - add("vars[template]", "search") - add("vars[post_type]", "wp-manga") - add("vars[post_status]", "publish") - add("vars[manga_archives_item_layout]", "default") - } - return POST("$baseUrl/wp-admin/admin-ajax.php", headers, form.build(), CacheControl.FORCE_NETWORK) - } -} - -open class PageMadara( - name: String, - baseUrl: String, - lang: String, - private val urlModifier: String = "/manga", - dateFormat: SimpleDateFormat = SimpleDateFormat("MMMM dd, yyyy", Locale.US) -) : Madara(name, baseUrl, lang, dateFormat) { - override fun popularMangaRequest(page: Int): Request = GET("$baseUrl$urlModifier/page/$page", headers) - override fun popularMangaNextPageSelector() = "div.nav-previous" - - override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request = GET("$baseUrl/page/$page/?s=$query&post_type=wp-manga", headers) +class Mangasushi : Madara("Mangasushi", "https://mangasushi.net", "en") +class NinjaScans : Madara("NinjaScans", "https://ninjascans.com", "en") +class ReadManhua : Madara("ReadManhua", "https://readmanhua.net", "en", dateFormat = SimpleDateFormat("dd MMM yy", Locale.US)) +class ZeroScans : Madara("ZeroScans", "https://zeroscans.com", "en") +class IsekaiScanCom : Madara("IsekaiScan.com", "http://isekaiscan.com/", "en") +class HappyTeaScans : Madara("Happy Tea Scans", "https://happyteascans.com/", "en") +class JustForFun : Madara("Just For Fun", "https://just-for-fun.ru/", "ru", dateFormat = SimpleDateFormat("dd/MM/yy", Locale.US)) +class AoCTranslations : Madara("Agent of Change Translations", "https://aoc.moe/", "en") +class Kanjiku : Madara("Kanjiku", "https://kanjiku.net/", "de", dateFormat = SimpleDateFormat("dd. MMM yyyy", Locale.GERMAN)) +class KomikGo : Madara("KomikGo", "https://komikgo.com/", "id") +class LuxyScans : Madara("Luxy Scans", "https://luxyscans.com/", "en") +class TritiniaScans : Madara("Tritinia Scans", "http://tritiniascans.ml/", "en") { + override fun popularMangaRequest(page: Int): Request = GET("$baseUrl/index-m_orderby=views.html", headers) + override fun latestUpdatesRequest(page: Int): Request = GET("$baseUrl/index-m_orderby=latest.html", headers) + override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request = GET("$baseUrl/index.html?s=$query", headers) + override fun latestUpdatesNextPageSelector(): String? = null + override fun popularMangaNextPageSelector(): String? = null } +class TsubakiNoScan : Madara("Tsubaki No Scan", "https://tsubakinoscan.com/", "fr", dateFormat = SimpleDateFormat("dd/MM/yy", Locale.US)) +class YokaiJump : Madara("Yokai Jump", "https://yokaijump.fr/", "fr", dateFormat = SimpleDateFormat("dd/MM/yy", Locale.US)) +class ZManga : Madara("ZManga", "https://zmanga.org/", "es")