Mangadex cleanup
This commit is contained in:
parent
5c2d26aa7c
commit
31473351af
@ -47,7 +47,6 @@ import tachiyomi.source.model.ChapterInfo
|
|||||||
import tachiyomi.source.model.MangaInfo
|
import tachiyomi.source.model.MangaInfo
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
import uy.kohesive.injekt.injectLazy
|
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
@Suppress("OverridingDeprecatedMember")
|
@Suppress("OverridingDeprecatedMember")
|
||||||
@ -68,18 +67,14 @@ class MangaDex(delegate: HttpSource, val context: Context) :
|
|||||||
|
|
||||||
// override val matchingHosts: List<String> = listOf("mangadex.org", "www.mangadex.org")
|
// override val matchingHosts: List<String> = listOf("mangadex.org", "www.mangadex.org")
|
||||||
|
|
||||||
val preferences: PreferencesHelper by injectLazy()
|
val preferences = Injekt.get<PreferencesHelper>()
|
||||||
val mdList: MdList by lazy {
|
val mdList: MdList = Injekt.get<TrackManager>().mdList
|
||||||
Injekt.get<TrackManager>().mdList
|
|
||||||
}
|
|
||||||
|
|
||||||
/*private val sourcePreferences: SharedPreferences by lazy {
|
/*private val sourcePreferences: SharedPreferences by lazy {
|
||||||
context.getSharedPreferences("source_$id", 0x0000)
|
context.getSharedPreferences("source_$id", 0x0000)
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
private val loginHelper by lazy {
|
private val loginHelper = MangaDexLoginHelper(networkHttpClient, preferences, mdList)
|
||||||
MangaDexLoginHelper(networkHttpClient, preferences, mdList)
|
|
||||||
}
|
|
||||||
|
|
||||||
override val baseHttpClient: OkHttpClient = super.client.newBuilder()
|
override val baseHttpClient: OkHttpClient = super.client.newBuilder()
|
||||||
.authenticator(
|
.authenticator(
|
||||||
|
@ -16,6 +16,7 @@ import exh.metadata.metadata.MangaDexSearchMetadata
|
|||||||
import exh.metadata.metadata.base.RaisedTag
|
import exh.metadata.metadata.base.RaisedTag
|
||||||
import exh.metadata.metadata.base.getFlatMetadataForManga
|
import exh.metadata.metadata.base.getFlatMetadataForManga
|
||||||
import exh.metadata.metadata.base.insertFlatMetadata
|
import exh.metadata.metadata.base.insertFlatMetadata
|
||||||
|
import exh.util.dropEmpty
|
||||||
import exh.util.executeOnIO
|
import exh.util.executeOnIO
|
||||||
import exh.util.floor
|
import exh.util.floor
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
@ -83,18 +84,18 @@ class ApiMangaParser(val client: OkHttpClient, private val lang: String) {
|
|||||||
|
|
||||||
description = MdUtil.cleanDescription(networkManga.description[lang] ?: networkManga.description["en"]!!)
|
description = MdUtil.cleanDescription(networkManga.description[lang] ?: networkManga.description["en"]!!)
|
||||||
|
|
||||||
// get authors ignore if they error, artists are labelled as authors currently
|
val authorIds = networkApiManga.relationships
|
||||||
val authorIds = networkApiManga.relationships.filter { relationship ->
|
.filter { it.type.equals("author", true) }
|
||||||
relationship.type.equals("author", true)
|
.map { it.id }
|
||||||
}.map { relationship -> relationship.id }
|
.toSet()
|
||||||
.distinct()
|
val artistIds = networkApiManga.relationships
|
||||||
val artistIds = networkApiManga.relationships.filter { relationship ->
|
.filter { it.type.equals("artist", true) }
|
||||||
relationship.type.equals("artist", true)
|
.map { it.id }
|
||||||
}.map { relationship -> relationship.id }
|
.toSet()
|
||||||
.distinct()
|
|
||||||
|
|
||||||
|
// get author/artist map ignore if they error
|
||||||
val authorMap = runCatching {
|
val authorMap = runCatching {
|
||||||
val ids = (authorIds + artistIds).distinct().joinToString("&ids[]=", "?ids[]=")
|
val ids = (authorIds + artistIds).joinToString("&ids[]=", "?ids[]=")
|
||||||
val response = client.newCall(GET("${MdUtil.authorUrl}$ids")).await()
|
val response = client.newCall(GET("${MdUtil.authorUrl}$ids")).await()
|
||||||
.parseAs<AuthorResponseList>()
|
.parseAs<AuthorResponseList>()
|
||||||
response.results.map {
|
response.results.map {
|
||||||
@ -102,8 +103,8 @@ class ApiMangaParser(val client: OkHttpClient, private val lang: String) {
|
|||||||
}.toMap()
|
}.toMap()
|
||||||
}.getOrNull() ?: emptyMap()
|
}.getOrNull() ?: emptyMap()
|
||||||
|
|
||||||
authors = authorIds.mapNotNull { authorMap[it] }.takeUnless { it.isEmpty() }
|
authors = authorIds.mapNotNull { authorMap[it] }.dropEmpty()
|
||||||
artists = artistIds.mapNotNull { authorMap[it] }.takeUnless { it.isEmpty() }
|
artists = artistIds.mapNotNull { authorMap[it] }.dropEmpty()
|
||||||
|
|
||||||
langFlag = networkManga.originalLanguage
|
langFlag = networkManga.originalLanguage
|
||||||
val lastChapter = networkManga.lastChapter.toFloatOrNull()
|
val lastChapter = networkManga.lastChapter.toFloatOrNull()
|
||||||
@ -114,12 +115,12 @@ class ApiMangaParser(val client: OkHttpClient, private val lang: String) {
|
|||||||
manga.users = it.users
|
manga.users = it.users
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
networkManga.links?.let {
|
networkManga.links?.let { links ->
|
||||||
it["al"]?.let { anilistId = it }
|
links["al"]?.let { anilistId = it }
|
||||||
it["kt"]?.let { kitsuId = it }
|
links["kt"]?.let { kitsuId = it }
|
||||||
it["mal"]?.let { myAnimeListId = it }
|
links["mal"]?.let { myAnimeListId = it }
|
||||||
it["mu"]?.let { mangaUpdatesId = it }
|
links["mu"]?.let { mangaUpdatesId = it }
|
||||||
it["ap"]?.let { animePlanetId = it }
|
links["ap"]?.let { animePlanetId = it }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kitsuId?.toIntOrNull() != null) {
|
if (kitsuId?.toIntOrNull() != null) {
|
||||||
|
@ -50,7 +50,9 @@ class TokenAuthenticator(private val loginHelper: MangaDexLoginHelper) : Authent
|
|||||||
val result = runCatching {
|
val result = runCatching {
|
||||||
validated = loginHelper.refreshToken(
|
validated = loginHelper.refreshToken(
|
||||||
MdUtil.getAuthHeaders(
|
MdUtil.getAuthHeaders(
|
||||||
Headers.Builder().build(), loginHelper.preferences, loginHelper.mdList
|
Headers.Builder().build(),
|
||||||
|
loginHelper.preferences,
|
||||||
|
loginHelper.mdList
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import android.content.Context
|
|||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import exh.md.utils.MdUtil
|
import exh.md.utils.MdUtil
|
||||||
import exh.metadata.metadata.base.RaisedSearchMetadata
|
import exh.metadata.metadata.base.RaisedSearchMetadata
|
||||||
import exh.util.nullIfBlank
|
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import tachiyomi.source.model.MangaInfo
|
import tachiyomi.source.model.MangaInfo
|
||||||
|
|
||||||
@ -98,7 +97,6 @@ class MangaDexSearchMetadata : RaisedSearchMetadata() {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val TITLE_TYPE_MAIN = 0
|
private const val TITLE_TYPE_MAIN = 0
|
||||||
private const val TITLE_TYPE_ALT_TITLE = 1
|
|
||||||
|
|
||||||
const val TAG_TYPE_DEFAULT = 0
|
const val TAG_TYPE_DEFAULT = 0
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user