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' extName = 'MangaDex'
pkgNameSuffix = 'all.mangadex' pkgNameSuffix = 'all.mangadex'
extClass = '.MangaDexFactory' extClass = '.MangaDexFactory'
extVersionCode = 186 extVersionCode = 187
isNsfw = true isNsfw = true
} }

View File

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

View File

@ -2,12 +2,14 @@ package eu.kanade.tachiyomi.extension.all.mangadex
import android.util.Log import android.util.Log
import eu.kanade.tachiyomi.extension.all.mangadex.dto.ImageReportDto import eu.kanade.tachiyomi.extension.all.mangadex.dto.ImageReportDto
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.POST import eu.kanade.tachiyomi.network.POST
import kotlinx.serialization.encodeToString import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import okhttp3.Call import okhttp3.Call
import okhttp3.Callback import okhttp3.Callback
import okhttp3.Headers import okhttp3.Headers
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.Interceptor import okhttp3.Interceptor
import okhttp3.MediaType.Companion.toMediaType import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
@ -55,7 +57,15 @@ class MdAtHomeReportInterceptor(
// gets stuck, as it tend to happens sometimes. // gets stuck, as it tend to happens sometimes.
client.newCall(reportRequest).enqueue(REPORT_CALLBACK) 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 { companion object {