[MangaAe] update url and other things (#16781)

This commit is contained in:
Asheraf 2023-06-20 17:11:27 +01:00 committed by GitHub
parent 4f1bbcdee9
commit 05702a5dec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 81 additions and 9 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = 'Manga.ae'
pkgNameSuffix = 'ar.mangaae'
extClass = '.MangaAe'
extVersionCode = 9
extVersionCode = 10
}
apply from: "$rootDir/common.gradle"

View File

@ -1,7 +1,13 @@
package eu.kanade.tachiyomi.extension.ar.mangaae
import android.app.Application
import android.content.SharedPreferences
import android.widget.Toast
import androidx.preference.PreferenceScreen
import eu.kanade.tachiyomi.extension.BuildConfig
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.interceptor.rateLimit
import eu.kanade.tachiyomi.source.ConfigurableSource
import eu.kanade.tachiyomi.source.model.Filter
import eu.kanade.tachiyomi.source.model.FilterList
import eu.kanade.tachiyomi.source.model.Page
@ -14,12 +20,22 @@ import okhttp3.OkHttpClient
import okhttp3.Request
import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
class MangaAe : ParsedHttpSource() {
class MangaAe : ParsedHttpSource(), ConfigurableSource {
override val name = "مانجا العرب"
override val baseUrl = "https://mngaar.com"
private val defaultBaseUrl = "https://manga.ae"
private val defaultUserAgent = "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Mobile Safari/537.3"
override val baseUrl by lazy { getPrefBaseUrl() }
private val userAgent by lazy { getPrefUserAgent() }
private val preferences: SharedPreferences by lazy {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
}
override val lang = "ar"
@ -29,9 +45,16 @@ class MangaAe : ParsedHttpSource() {
.rateLimit(2)
.build()
override fun headersBuilder(): Headers.Builder = Headers.Builder()
.add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:54.0) Gecko/20100101 Firefox/75.0")
.add("Referer", baseUrl)
override fun headersBuilder() = Headers.Builder().apply {
set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7")
set("Accept-Language", "en-US,en;q=0.9,ar-MA;q=0.8,ar;q=0.7")
set("Connection", "keep-alive")
set("Sec-Fetch-Dest", "document")
set("Sec-Fetch-Mode", "navigate")
set("Sec-Fetch-Site", "same-origin")
set("Sec-Fetch-User", "?1")
set("Referer", baseUrl)
}
// Popular
override fun popularMangaRequest(page: Int): Request {
@ -104,9 +127,9 @@ class MangaAe : ParsedHttpSource() {
title = infoElement.select("h1.EnglishName").text().removeSurrounding("(", ")")
author = infoElement.select("div.manga-details-author h4")[0].text()
artist = author
status = parseStatus(infoElement.select("div.manga-details-extended h4")[1].text())
status = parseStatus(infoElement.select("div.manga-details-extended td h4")[0].text().trim())
genre = infoElement.select("div.manga-details-extended a[href*=tag]").joinToString(", ") { it.text() }
description = infoElement.select("div.manga-details-extended h4")[2].text()
description = infoElement.select("div.manga-details-extended h4[style*=overflow-y]")[0].text()
thumbnail_url = infoElement.select("img.manga-cover").attr("src")
}
@ -124,7 +147,7 @@ class MangaAe : ParsedHttpSource() {
val chapter = SChapter.create()
element.select("a").let {
// use full pages for easier links
chapter.setUrlWithoutDomain(it.attr("href").removeSuffix("/1/") + "/0/fully")
chapter.setUrlWithoutDomain(it.attr("href").removeSuffix("/1/") + "/0/allpages")
chapter.name = "\u061C" + it.text() // Add unicode ARABIC LETTER MARK to ensure all titles are right to left
}
return chapter
@ -141,6 +164,14 @@ class MangaAe : ParsedHttpSource() {
override fun imageUrlParse(document: Document): String = throw Exception("Not used")
override fun imageRequest(page: Page): Request {
val imgHeaders = headersBuilder().apply {
set("Accept", "image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8")
set("Referer", baseUrl)
}.build()
return GET(page.imageUrl!!, imgHeaders)
}
private open class UriPartFilter(displayName: String, val vals: Array<Pair<String, String>>) :
Filter.Select<String>(displayName, vals.map { it.first }.toTypedArray()) {
fun toUriPart() = vals[state].second
@ -160,4 +191,45 @@ class MangaAe : ParsedHttpSource() {
override fun getFilterList() = FilterList(
OrderByFilter(),
)
companion object {
private const val RESTART_TACHIYOMI = ".لتطبيق الإعدادات الجديدة Tachiyomi أعد تشغيل"
private const val BASE_URL_PREF_TITLE = "تعديل الرابط"
private const val BASE_URL_PREF = "overrideBaseUrl_v${BuildConfig.VERSION_CODE}"
private const val USER_AGENT_PREF_TITLE = "تعديل وكيل المستخدم"
private const val USER_AGENT_PREF = "overrideUserAgent_v${BuildConfig.VERSION_CODE}"
private const val PREF_SUMMARY = ".للاستخدام المؤقت. تحديث التطبيق سيؤدي الى حذف الإعدادات"
}
override fun setupPreferenceScreen(screen: PreferenceScreen) {
val baseUrlPref = androidx.preference.EditTextPreference(screen.context).apply {
key = BASE_URL_PREF
title = BASE_URL_PREF_TITLE
summary = PREF_SUMMARY
this.setDefaultValue(defaultBaseUrl)
dialogTitle = BASE_URL_PREF_TITLE
setOnPreferenceChangeListener { _, _ ->
Toast.makeText(screen.context, RESTART_TACHIYOMI, Toast.LENGTH_LONG).show()
true
}
}
val userAgentPref = androidx.preference.EditTextPreference(screen.context).apply {
key = USER_AGENT_PREF
title = USER_AGENT_PREF_TITLE
summary = PREF_SUMMARY
this.setDefaultValue(defaultUserAgent)
dialogTitle = USER_AGENT_PREF_TITLE
setOnPreferenceChangeListener { _, _ ->
Toast.makeText(screen.context, RESTART_TACHIYOMI, Toast.LENGTH_LONG).show()
true
}
}
screen.addPreference(baseUrlPref)
screen.addPreference(userAgentPref)
}
private fun getPrefBaseUrl(): String = preferences.getString(BASE_URL_PREF, defaultBaseUrl)!!
private fun getPrefUserAgent(): String = preferences.getString(USER_AGENT_PREF, defaultUserAgent)!!
}