diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/MangaParser.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/MangaParser.kt index 08aab2b9..14eee58f 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/MangaParser.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/MangaParser.kt @@ -63,6 +63,12 @@ abstract class MangaParser @InternalParsersApi constructor( open val isSearchYearSupported: Boolean = false + /** + * Whether parser supports searching by year range + */ + + open val isSearchYearRangeSupported: Boolean = false + /** * Whether parser supports searching Original Languages */ @@ -183,6 +189,8 @@ abstract class MangaParser @InternalParsersApi constructor( contentRating = emptySet(), query = null, year = null, + yearFrom = null, + yearTo = null, ), ) } diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/model/MangaListFilter.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/model/MangaListFilter.kt index c85fbb15..aa777726 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/model/MangaListFilter.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/model/MangaListFilter.kt @@ -15,8 +15,8 @@ sealed interface MangaListFilter { (tagsExclude.isEmpty() || parser.isTagsExclusionSupported) && (contentRating.isEmpty() || parser.availableContentRating.containsAll(contentRating)) && (states.isEmpty() || parser.availableStates.containsAll(states) && - (parser.searchSupportedWithMultipleFilters) && - (parser.isSearchYearSupported) && (parser.isSearchOriginalLanguages)) + (parser.searchSupportedWithMultipleFilters) &&(parser.isSearchOriginalLanguages) && + (parser.isSearchYearSupported) && (parser.isSearchYearRangeSupported)) is Search -> parser.isSearchSupported } @@ -40,10 +40,12 @@ sealed interface MangaListFilter { @JvmField val contentRating: Set, @JvmField val query: String?, @JvmField val year: Int?, + @JvmField val yearFrom: Int?, + @JvmField val yearTo: Int?, ) : MangaListFilter { override fun isEmpty(): Boolean = - tags.isEmpty() && tagsExclude.isEmpty() && locale == null && localeMangas == null && states.isEmpty() && contentRating.isEmpty() && query == null && year == null + tags.isEmpty() && tagsExclude.isEmpty() && locale == null && localeMangas == null && states.isEmpty() && contentRating.isEmpty() && query == null && year == null && yearFrom == null && yearTo == null fun newBuilder() = Builder(sortOrder) .tags(tags) @@ -54,6 +56,8 @@ sealed interface MangaListFilter { .contentRatings(contentRating) .query(query) .year(year) + .yearFrom(yearFrom) + .yearTo(yearTo) class Builder(sortOrder: SortOrder) { @@ -66,6 +70,8 @@ sealed interface MangaListFilter { private var _contentRating: Set? = null private var _query: String? = null private var _year: Int? = null + private var _yearFrom: Int? = null + private var _yearTo: Int? = null fun sortOrder(order: SortOrder) = apply { _sortOrder = order @@ -103,6 +109,14 @@ sealed interface MangaListFilter { _year = year } + fun yearFrom(yearFrom: Int?) = apply { + _yearFrom = yearFrom + } + + fun yearTo(yearTo: Int?) = apply { + _yearTo = yearTo + } + fun build() = Advanced( @@ -115,7 +129,9 @@ sealed interface MangaListFilter { contentRating = _contentRating.orEmpty(), query = _query, year = _year, - ) + yearFrom = _yearFrom, + yearTo = _yearTo, + ) } } } diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/all/ComickFunParser.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/all/ComickFunParser.kt index f7bbcbfe..dea30dda 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/all/ComickFunParser.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/all/ComickFunParser.kt @@ -29,6 +29,8 @@ internal class ComickFunParser(context: MangaLoaderContext) : override val isTagsExclusionSupported = true + override val isSearchYearRangeSupported = true + override val availableSortOrders: Set = EnumSet.of( SortOrder.POPULARITY, SortOrder.UPDATED, @@ -93,6 +95,14 @@ internal class ComickFunParser(context: MangaLoaderContext) : }, ) } + + filter.yearFrom?.let { + url.addQueryParameter("from", filter.yearFrom.toString() ) + } + + filter.yearTo?.let { + url.addQueryParameter("to", filter.yearTo.toString() ) + } } } val ja = webClient.httpGet(url.build()).parseJsonArray() diff --git a/src/test/kotlin/org/koitharu/kotatsu/parsers/MangaParserTest.kt b/src/test/kotlin/org/koitharu/kotatsu/parsers/MangaParserTest.kt index ccafc149..e58151b0 100644 --- a/src/test/kotlin/org/koitharu/kotatsu/parsers/MangaParserTest.kt +++ b/src/test/kotlin/org/koitharu/kotatsu/parsers/MangaParserTest.kt @@ -62,6 +62,8 @@ internal class MangaParserTest { contentRating = emptySet(), query = null, year = null, + yearFrom = null, + yearTo = null, ), ).minByOrNull { it.title.length @@ -139,6 +141,8 @@ internal class MangaParserTest { contentRating = setOf(), query = null, year = null, + yearFrom = null, + yearTo = null, ) val list = parser.getList(offset = 0, filter) checkMangaList(list, filter.locale.toString())