Add a new filter and fix missing Bilibili chapters in MD. (#10253)

This commit is contained in:
Alessandro Jean 2021-12-27 16:17:14 -03:00 committed by GitHub
parent 190e1410e3
commit aa98af8907
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 4 deletions

View File

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

View File

@ -241,7 +241,7 @@ abstract class MangaDex(override val lang: String, val dexLang: String) :
} }
} }
val finalUrl = helper.mdFilters.addFiltersToUrl(tempUrl, filters) val finalUrl = helper.mdFilters.addFiltersToUrl(tempUrl, filters, dexLang)
return GET(finalUrl, headers, CacheControl.FORCE_NETWORK) return GET(finalUrl, headers, CacheControl.FORCE_NETWORK)
} }

View File

@ -19,6 +19,7 @@ class MangaDexFilters {
TagList(getTags()), TagList(getTags()),
TagInclusionMode(), TagInclusionMode(),
TagExclusionMode(), TagExclusionMode(),
HasAvailableChaptersFilter(),
) )
} }
@ -200,7 +201,9 @@ class MangaDexFilters {
class SortFilter(sortables: Array<String>) : Filter.Sort("Sort", sortables, Selection(2, false)) class SortFilter(sortables: Array<String>) : Filter.Sort("Sort", sortables, Selection(2, false))
internal fun addFiltersToUrl(url: HttpUrl.Builder, filters: FilterList): String { private class HasAvailableChaptersFilter : Filter.CheckBox("Has available chapters")
internal fun addFiltersToUrl(url: HttpUrl.Builder, filters: FilterList, dexLang: String): String {
url.apply { url.apply {
// add filters // add filters
filters.forEach { filter -> filters.forEach { filter ->
@ -287,6 +290,12 @@ class MangaDexFilters {
filter.values[filter.state].toUpperCase(Locale.US) filter.values[filter.state].toUpperCase(Locale.US)
) )
} }
is HasAvailableChaptersFilter -> {
if (filter.state) {
addQueryParameter("hasAvailableChapters", "true")
addQueryParameter("availableTranslatedLanguage[]", dexLang)
}
}
} }
} }
} }

View File

@ -112,6 +112,8 @@ class MangaDexHelper() {
val USE_CACHE = CacheControl.Builder() val USE_CACHE = CacheControl.Builder()
.maxStale(Integer.MAX_VALUE, TimeUnit.SECONDS) .maxStale(Integer.MAX_VALUE, TimeUnit.SECONDS)
.build() .build()
private const val BILIBILI_URL = "bilibilicomics.com"
} }
// Check the token map to see if the md@home host is still valid // Check the token map to see if the md@home host is still valid
@ -326,7 +328,17 @@ class MangaDexHelper() {
} }
} }
if (attr.externalUrl != null) { if (!attr.externalUrl.isNullOrEmpty() && !attr.externalUrl.contains(BILIBILI_URL)) {
return null
}
// Bilibili special check. If it's a Bilibili chapter and the
// publishAt date is < now, it can be read on MD.
if (
!attr.externalUrl.isNullOrEmpty() &&
attr.externalUrl.contains(BILIBILI_URL) &&
parseDate(attr.publishAt) >= Date().time
) {
return null return null
} }