MangaDex: Add filtering to list search (#17460)

* increment extVersionCode

closes https://github.com/tachiyomiorg/tachiyomi-extensions/issues/17456

* add filtering to `list:`

* prefer using the constant instead

* revert to fallback url if MD@H node fails

* handle edge case in accessing list entries

mostly just to ensure the Retry message doesn't happen

* finish off TODO as manga redirects work fine nowadays

* linting

* add missing headers

this helps add the necessary tachiyomi ua and other stuff

* fix getMangaUrl
This commit is contained in:
nicki 2023-08-11 12:59:21 -05:00 committed by GitHub
parent 77bb7872e3
commit d19e67ed2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 17 deletions

View File

@ -6,7 +6,7 @@ ext {
extName = 'MangaDex'
pkgNameSuffix = 'all.mangadex'
extClass = '.MangaDexFactory'
extVersionCode = 186
extVersionCode = 187
isNsfw = true
}

View File

@ -202,7 +202,7 @@ abstract class MangaDex(final override val lang: String, private val dexLang: St
),
)
.asObservableSuccess()
.map { searchMangaListParse(it, page) }
.map { searchMangaListParse(it, page, filters) }
else -> super.fetchSearchManga(page, query.trim(), filters)
}
@ -289,7 +289,7 @@ abstract class MangaDex(final override val lang: String, private val dexLang: St
return GET("${MDConstants.apiListUrl}/$list", headers, CacheControl.FORCE_NETWORK)
}
private fun searchMangaListParse(response: Response, page: Int): MangasPage {
private fun searchMangaListParse(response: Response, page: Int, filters: FilterList): MangasPage {
val listDto = response.parseAs<ListDto>()
val listDtoFiltered = listDto.data!!.relationships.filterIsInstance<MangaDataDto>()
val amount = listDtoFiltered.count()
@ -300,7 +300,7 @@ abstract class MangaDex(final override val lang: String, private val dexLang: St
val minIndex = (page - 1) * MDConstants.mangaLimit
val url = MDConstants.apiMangaUrl.toHttpUrl().newBuilder()
val tempUrl = MDConstants.apiMangaUrl.toHttpUrl().newBuilder()
.addQueryParameter("limit", MDConstants.mangaLimit.toString())
.addQueryParameter("offset", "0")
.addQueryParameter("includes[]", MDConstants.coverArt)
@ -310,13 +310,20 @@ abstract class MangaDex(final override val lang: String, private val dexLang: St
.map(MangaDataDto::id)
.toSet()
url.addQueryParameter("ids[]", ids)
tempUrl.addQueryParameter("ids[]", ids)
val mangaRequest = GET(url.build(), headers, CacheControl.FORCE_NETWORK)
val finalUrl = helper.mdFilters.addFiltersToUrl(
url = tempUrl,
filters = filters.ifEmpty { getFilterList() },
dexLang = dexLang,
)
val mangaRequest = GET(finalUrl, headers, CacheControl.FORCE_NETWORK)
val mangaResponse = client.newCall(mangaRequest).execute()
val mangaList = searchMangaListParse(mangaResponse)
val hasNextPage = amount.toFloat() / MDConstants.mangaLimit - (page.toFloat() - 1) > 1
val hasNextPage = amount.toFloat() / MDConstants.mangaLimit - (page.toFloat() - 1) > 1 &&
ids.size == MDConstants.mangaLimit
return MangasPage(mangaList, hasNextPage)
}
@ -370,11 +377,7 @@ abstract class MangaDex(final override val lang: String, private val dexLang: St
// Manga Details section
override fun getMangaUrl(manga: SManga): String {
// TODO: Remove once redirect for /manga is fixed.
val title = manga.title
val url = baseUrl + manga.url.replaceFirst("manga", "title")
return "$url/" + helper.titleToSlug(title)
return baseUrl + manga.url + "/" + helper.titleToSlug(manga.title)
}
/**
@ -496,10 +499,7 @@ abstract class MangaDex(final override val lang: String, private val dexLang: St
*/
private fun paginatedChapterListRequest(mangaId: String, offset: Int): Request {
val url = helper.getChapterEndpoint(mangaId, offset, dexLang).toHttpUrl().newBuilder()
.addQueryParameter("contentRating[]", "safe")
.addQueryParameter("contentRating[]", "suggestive")
.addQueryParameter("contentRating[]", "erotica")
.addQueryParameter("contentRating[]", "pornographic")
.addQueryParameter("contentRating[]", MDConstants.allContentRatings)
.addQueryParameter("excludedGroups[]", preferences.blockedGroups)
.addQueryParameter("excludedUploaders[]", preferences.blockedUploaders)
.build()

View File

@ -2,12 +2,14 @@ package eu.kanade.tachiyomi.extension.all.mangadex
import android.util.Log
import eu.kanade.tachiyomi.extension.all.mangadex.dto.ImageReportDto
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.POST
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import okhttp3.Call
import okhttp3.Callback
import okhttp3.Headers
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.Interceptor
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
@ -55,7 +57,15 @@ class MdAtHomeReportInterceptor(
// gets stuck, as it tend to happens sometimes.
client.newCall(reportRequest).enqueue(REPORT_CALLBACK)
return response
return if (!response.isSuccessful) {
Log.e("MangaDex", "Error connecting to MD@Home node, fallback to uploads server")
val fallbackUrl = MDConstants.cdnUrl.toHttpUrl().newBuilder()
.addPathSegments(originalRequest.url.pathSegments.joinToString("/"))
.build()
client.newCall(GET(fallbackUrl, headers)).execute()
} else {
response
}
}
companion object {