Mangadex cleanup

This commit is contained in:
Jobobby04 2021-05-09 15:58:23 -04:00
parent 5c2d26aa7c
commit 31473351af
4 changed files with 25 additions and 29 deletions

View File

@ -47,7 +47,6 @@ import tachiyomi.source.model.ChapterInfo
import tachiyomi.source.model.MangaInfo
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy
import kotlin.reflect.KClass
@Suppress("OverridingDeprecatedMember")
@ -68,18 +67,14 @@ class MangaDex(delegate: HttpSource, val context: Context) :
// override val matchingHosts: List<String> = listOf("mangadex.org", "www.mangadex.org")
val preferences: PreferencesHelper by injectLazy()
val mdList: MdList by lazy {
Injekt.get<TrackManager>().mdList
}
val preferences = Injekt.get<PreferencesHelper>()
val mdList: MdList = Injekt.get<TrackManager>().mdList
/*private val sourcePreferences: SharedPreferences by lazy {
context.getSharedPreferences("source_$id", 0x0000)
}*/
private val loginHelper by lazy {
MangaDexLoginHelper(networkHttpClient, preferences, mdList)
}
private val loginHelper = MangaDexLoginHelper(networkHttpClient, preferences, mdList)
override val baseHttpClient: OkHttpClient = super.client.newBuilder()
.authenticator(

View File

@ -16,6 +16,7 @@ import exh.metadata.metadata.MangaDexSearchMetadata
import exh.metadata.metadata.base.RaisedTag
import exh.metadata.metadata.base.getFlatMetadataForManga
import exh.metadata.metadata.base.insertFlatMetadata
import exh.util.dropEmpty
import exh.util.executeOnIO
import exh.util.floor
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"]!!)
// get authors ignore if they error, artists are labelled as authors currently
val authorIds = networkApiManga.relationships.filter { relationship ->
relationship.type.equals("author", true)
}.map { relationship -> relationship.id }
.distinct()
val artistIds = networkApiManga.relationships.filter { relationship ->
relationship.type.equals("artist", true)
}.map { relationship -> relationship.id }
.distinct()
val authorIds = networkApiManga.relationships
.filter { it.type.equals("author", true) }
.map { it.id }
.toSet()
val artistIds = networkApiManga.relationships
.filter { it.type.equals("artist", true) }
.map { it.id }
.toSet()
// get author/artist map ignore if they error
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()
.parseAs<AuthorResponseList>()
response.results.map {
@ -102,8 +103,8 @@ class ApiMangaParser(val client: OkHttpClient, private val lang: String) {
}.toMap()
}.getOrNull() ?: emptyMap()
authors = authorIds.mapNotNull { authorMap[it] }.takeUnless { it.isEmpty() }
artists = artistIds.mapNotNull { authorMap[it] }.takeUnless { it.isEmpty() }
authors = authorIds.mapNotNull { authorMap[it] }.dropEmpty()
artists = artistIds.mapNotNull { authorMap[it] }.dropEmpty()
langFlag = networkManga.originalLanguage
val lastChapter = networkManga.lastChapter.toFloatOrNull()
@ -114,12 +115,12 @@ class ApiMangaParser(val client: OkHttpClient, private val lang: String) {
manga.users = it.users
}*/
networkManga.links?.let {
it["al"]?.let { anilistId = it }
it["kt"]?.let { kitsuId = it }
it["mal"]?.let { myAnimeListId = it }
it["mu"]?.let { mangaUpdatesId = it }
it["ap"]?.let { animePlanetId = it }
networkManga.links?.let { links ->
links["al"]?.let { anilistId = it }
links["kt"]?.let { kitsuId = it }
links["mal"]?.let { myAnimeListId = it }
links["mu"]?.let { mangaUpdatesId = it }
links["ap"]?.let { animePlanetId = it }
}
if (kitsuId?.toIntOrNull() != null) {

View File

@ -50,7 +50,9 @@ class TokenAuthenticator(private val loginHelper: MangaDexLoginHelper) : Authent
val result = runCatching {
validated = loginHelper.refreshToken(
MdUtil.getAuthHeaders(
Headers.Builder().build(), loginHelper.preferences, loginHelper.mdList
Headers.Builder().build(),
loginHelper.preferences,
loginHelper.mdList
)
)
}

View File

@ -4,7 +4,6 @@ import android.content.Context
import eu.kanade.tachiyomi.R
import exh.md.utils.MdUtil
import exh.metadata.metadata.base.RaisedSearchMetadata
import exh.util.nullIfBlank
import kotlinx.serialization.Serializable
import tachiyomi.source.model.MangaInfo
@ -98,7 +97,6 @@ class MangaDexSearchMetadata : RaisedSearchMetadata() {
companion object {
private const val TITLE_TYPE_MAIN = 0
private const val TITLE_TYPE_ALT_TITLE = 1
const val TAG_TYPE_DEFAULT = 0
}