From aa98af89076e7358bcb3f5acf6f16b598eb9a0db Mon Sep 17 00:00:00 2001 From: Alessandro Jean Date: Mon, 27 Dec 2021 16:17:14 -0300 Subject: [PATCH] Add a new filter and fix missing Bilibili chapters in MD. (#10253) --- src/all/mangadex/build.gradle | 2 +- .../tachiyomi/extension/all/mangadex/MangaDex.kt | 2 +- .../extension/all/mangadex/MangaDexFilters.kt | 11 ++++++++++- .../extension/all/mangadex/MangaDexHelper.kt | 14 +++++++++++++- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/all/mangadex/build.gradle b/src/all/mangadex/build.gradle index 997346db3..2fed37643 100644 --- a/src/all/mangadex/build.gradle +++ b/src/all/mangadex/build.gradle @@ -6,7 +6,7 @@ ext { extName = 'MangaDex' pkgNameSuffix = 'all.mangadex' extClass = '.MangaDexFactory' - extVersionCode = 148 + extVersionCode = 149 isNsfw = true } diff --git a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDex.kt b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDex.kt index 2615e2bab..9b34a16ba 100644 --- a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDex.kt +++ b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDex.kt @@ -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) } diff --git a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDexFilters.kt b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDexFilters.kt index 7a5e7b8da..f4d2d28a1 100644 --- a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDexFilters.kt +++ b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDexFilters.kt @@ -19,6 +19,7 @@ class MangaDexFilters { TagList(getTags()), TagInclusionMode(), TagExclusionMode(), + HasAvailableChaptersFilter(), ) } @@ -200,7 +201,9 @@ class MangaDexFilters { class SortFilter(sortables: Array) : 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 { // add filters filters.forEach { filter -> @@ -287,6 +290,12 @@ class MangaDexFilters { filter.values[filter.state].toUpperCase(Locale.US) ) } + is HasAvailableChaptersFilter -> { + if (filter.state) { + addQueryParameter("hasAvailableChapters", "true") + addQueryParameter("availableTranslatedLanguage[]", dexLang) + } + } } } } diff --git a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDexHelper.kt b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDexHelper.kt index 36e4f31cc..043b935a6 100644 --- a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDexHelper.kt +++ b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/MangaDexHelper.kt @@ -112,6 +112,8 @@ class MangaDexHelper() { val USE_CACHE = CacheControl.Builder() .maxStale(Integer.MAX_VALUE, TimeUnit.SECONDS) .build() + + private const val BILIBILI_URL = "bilibilicomics.com" } // 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 }