Delegate Mangadex
Features that are now usable because of this: - Batch add mangadex manga - Open mangadex manga into TachiyomiSY(skipping the extension)
This commit is contained in:
parent
a2f2e7658d
commit
ad82dc1c90
@ -285,6 +285,24 @@
|
||||
android:host="www.hbrowse.com"
|
||||
android:pathPrefix="/"
|
||||
android:scheme="https" />
|
||||
|
||||
<!-- MangaDex -->
|
||||
<data
|
||||
android:host="mangadex.org"
|
||||
android:pathPattern="\/(title|manga)\/"
|
||||
android:scheme="http" />
|
||||
<data
|
||||
android:host="mangadex.org"
|
||||
android:pathPattern="\/(title|manga)\/"
|
||||
android:scheme="https" />
|
||||
<data
|
||||
android:host="www.mangadex.org"
|
||||
android:pathPattern="\/(title|manga)\/"
|
||||
android:scheme="http" />
|
||||
<data
|
||||
android:host="www.mangadex.org"
|
||||
android:pathPattern="\/(title|manga)\/"
|
||||
android:scheme="https" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
|
@ -10,6 +10,7 @@ import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
import eu.kanade.tachiyomi.source.online.all.EHentai
|
||||
import eu.kanade.tachiyomi.source.online.all.Hitomi
|
||||
import eu.kanade.tachiyomi.source.online.all.MangaDex
|
||||
import eu.kanade.tachiyomi.source.online.all.MergedSource
|
||||
import eu.kanade.tachiyomi.source.online.all.NHentai
|
||||
import eu.kanade.tachiyomi.source.online.all.PervEden
|
||||
@ -87,13 +88,22 @@ open class SourceManager(private val context: Context) {
|
||||
internal fun registerSource(source: Source, overwrite: Boolean = false) {
|
||||
// EXH -->
|
||||
val sourceQName = source::class.qualifiedName
|
||||
val delegate = DELEGATED_SOURCES[sourceQName]
|
||||
val factories = DELEGATED_SOURCES.entries.filter { it.value.factory }.map { it.value.originalSourceQualifiedClassName }
|
||||
val delegate = if (sourceQName != null) {
|
||||
val matched = factories.find { sourceQName.startsWith(it) }
|
||||
if (matched != null) {
|
||||
DELEGATED_SOURCES[matched]
|
||||
} else DELEGATED_SOURCES[sourceQName]
|
||||
} else null
|
||||
val newSource = if (source is HttpSource && delegate != null) {
|
||||
XLog.d("[EXH] Delegating source: %s -> %s!", sourceQName, delegate.newSourceClass.qualifiedName)
|
||||
EnhancedHttpSource(
|
||||
val enhancedSource = EnhancedHttpSource(
|
||||
source,
|
||||
delegate.newSourceClass.constructors.find { it.parameters.size == 1 }!!.call(source)
|
||||
)
|
||||
val map = listOf(DelegatedSource(enhancedSource.originalSource.name, enhancedSource.originalSource.id, enhancedSource.originalSource::class.qualifiedName ?: delegate.originalSourceQualifiedClassName, (enhancedSource.enchancedSource as DelegatedHttpSource)::class, delegate.factory)).associateBy { it.originalSourceQualifiedClassName }
|
||||
currentDelegatedSources.plusAssign(map)
|
||||
enhancedSource
|
||||
} else source
|
||||
|
||||
if (source.id in BlacklistedSources.BLACKLISTED_EXT_SOURCES) {
|
||||
@ -161,6 +171,7 @@ open class SourceManager(private val context: Context) {
|
||||
|
||||
// SY -->
|
||||
companion object {
|
||||
private const val fillInSourceId = 9999L
|
||||
val DELEGATED_SOURCES = listOf(
|
||||
DelegatedSource(
|
||||
"Hentai Cafe",
|
||||
@ -179,14 +190,24 @@ open class SourceManager(private val context: Context) {
|
||||
6707338697138388238,
|
||||
"eu.kanade.tachiyomi.extension.en.tsumino.Tsumino",
|
||||
Tsumino::class
|
||||
),
|
||||
DelegatedSource(
|
||||
"MangaDex",
|
||||
fillInSourceId,
|
||||
"eu.kanade.tachiyomi.extension.all.mangadex",
|
||||
MangaDex::class,
|
||||
true
|
||||
)
|
||||
).associateBy { it.originalSourceQualifiedClassName }
|
||||
|
||||
var currentDelegatedSources = mutableMapOf<String, DelegatedSource>()
|
||||
|
||||
data class DelegatedSource(
|
||||
val sourceName: String,
|
||||
val sourceId: Long,
|
||||
val originalSourceQualifiedClassName: String,
|
||||
val newSourceClass: KClass<out DelegatedHttpSource>
|
||||
val newSourceClass: KClass<out DelegatedHttpSource>,
|
||||
val factory: Boolean = false
|
||||
)
|
||||
}
|
||||
// SY <--
|
||||
|
@ -0,0 +1,25 @@
|
||||
package eu.kanade.tachiyomi.source.online.all
|
||||
|
||||
import android.net.Uri
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
import eu.kanade.tachiyomi.source.online.UrlImportableSource
|
||||
import exh.source.DelegatedHttpSource
|
||||
|
||||
class MangaDex(delegate: HttpSource) :
|
||||
DelegatedHttpSource(delegate),
|
||||
UrlImportableSource {
|
||||
|
||||
override val matchingHosts: List<String> = listOf("mangadex.org")
|
||||
|
||||
override fun mapUrlToMangaUrl(uri: Uri): String? {
|
||||
val lcFirstPathSegment = uri.pathSegments.firstOrNull()?.toLowerCase() ?: return null
|
||||
|
||||
return if (lcFirstPathSegment == "title" || lcFirstPathSegment == "manga") {
|
||||
"/manga/${uri.pathSegments[1]}"
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
override val lang: String = delegate.lang
|
||||
}
|
@ -41,15 +41,15 @@ val LIBRARY_UPDATE_EXCLUDED_SOURCES = listOf(
|
||||
PURURIN_SOURCE_ID
|
||||
)
|
||||
|
||||
private inline fun <reified T> delegatedSourceId(): Long {
|
||||
private inline fun <reified T> delegatedSourceId(): Long? {
|
||||
return SourceManager.DELEGATED_SOURCES.entries.find {
|
||||
it.value.newSourceClass == T::class
|
||||
}!!.value.sourceId
|
||||
}?.value?.sourceId
|
||||
}
|
||||
|
||||
// Used to speed up isLewdSource
|
||||
val lewdDelegatedSourceIds = SourceManager.DELEGATED_SOURCES.filter {
|
||||
it.value.newSourceClass in DELEGATED_LEWD_SOURCES
|
||||
val lewdDelegatedSourceIds = SourceManager.currentDelegatedSources.filter {
|
||||
!it.value.factory && it.value.newSourceClass in DELEGATED_LEWD_SOURCES
|
||||
}.map { it.value.sourceId }.sorted()
|
||||
|
||||
// This method MUST be fast!
|
||||
|
@ -62,12 +62,12 @@ object EXHMigrations {
|
||||
fun migrateBackupEntry(manga: MangaImpl): MangaImpl {
|
||||
// Migrate HentaiCafe source IDs
|
||||
if (manga.source == 6908L) {
|
||||
manga.source = HENTAI_CAFE_SOURCE_ID
|
||||
manga.source = HENTAI_CAFE_SOURCE_ID!!
|
||||
}
|
||||
|
||||
// Migrate Tsumino source IDs
|
||||
if (manga.source == 6909L) {
|
||||
manga.source = TSUMINO_SOURCE_ID
|
||||
manga.source = TSUMINO_SOURCE_ID!!
|
||||
}
|
||||
|
||||
// Migrate nhentai URLs
|
||||
|
@ -12,6 +12,7 @@ import eu.kanade.tachiyomi.data.database.tables.MangaTable
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.source.CatalogueSource
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
import eu.kanade.tachiyomi.source.SourceManager.Companion.currentDelegatedSources
|
||||
import exh.EH_SOURCE_ID
|
||||
import exh.EXHMigrations
|
||||
import exh.EXHSavedSearch
|
||||
@ -67,6 +68,8 @@ object DebugFunctions {
|
||||
}
|
||||
private val throttleManager = EHentaiThrottleManager()
|
||||
|
||||
fun getDelegatedSourceList(): String = currentDelegatedSources.map { it.value.sourceName }.joinToString(separator = "\n")
|
||||
|
||||
fun ResetEHGalleriesForUpdater() {
|
||||
throttleManager.resetThrottle()
|
||||
runBlocking {
|
||||
|
Loading…
x
Reference in New Issue
Block a user