[mangadex] Update Mangadex Filtering (Closes #680) (#681)

[mangadex] Update Mangadex Filtering (Closes #680)
This commit is contained in:
Ken Swenson 2018-12-25 20:24:14 -05:00 committed by Carlos
parent 6f35fc4c60
commit 95ec0851e6
2 changed files with 130 additions and 49 deletions

View File

@ -5,7 +5,7 @@ ext {
appName = 'Tachiyomi: MangaDex' appName = 'Tachiyomi: MangaDex'
pkgNameSuffix = 'all.mangadex' pkgNameSuffix = 'all.mangadex'
extClass = '.MangadexFactory' extClass = '.MangadexFactory'
extVersionCode = 41 extVersionCode = 42
libVersion = '1.2' libVersion = '1.2'
} }

View File

@ -168,6 +168,24 @@ open class Mangadex(override val lang: String, private val internalLang: String,
url.addQueryParameter("source_lang", number) url.addQueryParameter("source_lang", number)
} }
} }
is ContentList -> {
filter.state.forEach { content ->
if (content.isExcluded()) {
genresToExclude.add(content.id)
} else if (content.isIncluded()) {
genresToInclude.add(content.id)
}
}
}
is FormatList -> {
filter.state.forEach { format ->
if (format.isExcluded()) {
genresToExclude.add(format.id)
} else if (format.isIncluded()) {
genresToInclude.add(format.id)
}
}
}
is GenreList -> { is GenreList -> {
filter.state.forEach { genre -> filter.state.forEach { genre ->
if (genre.isExcluded()) { if (genre.isExcluded()) {
@ -177,6 +195,15 @@ open class Mangadex(override val lang: String, private val internalLang: String,
} }
} }
} }
is ThemeList -> {
filter.state.forEach { theme ->
if (theme.isExcluded()) {
genresToExclude.add(theme.id)
} else if (theme.isIncluded()) {
genresToInclude.add(theme.id)
}
}
}
is SortFilter -> { is SortFilter -> {
if (filter.state != null) { if (filter.state != null) {
if (filter.state!!.ascending) { if (filter.state!!.ascending) {
@ -192,10 +219,10 @@ open class Mangadex(override val lang: String, private val internalLang: String,
// Manually append genres list to avoid commas being encoded // Manually append genres list to avoid commas being encoded
var urlToUse = url.toString() var urlToUse = url.toString()
if (genresToInclude.isNotEmpty()) { if (genresToInclude.isNotEmpty()) {
urlToUse += "&genres_inc=" + genresToInclude.joinToString(",") urlToUse += "&tags_inc=" + genresToInclude.joinToString(",")
} }
if (genresToExclude.isNotEmpty()) { if (genresToExclude.isNotEmpty()) {
urlToUse += "&genres_exc=" + genresToExclude.joinToString(",") urlToUse += "&tags_exc=" + genresToExclude.joinToString(",")
} }
return GET(urlToUse, headers) return GET(urlToUse, headers)
@ -251,6 +278,8 @@ open class Mangadex(override val lang: String, private val internalLang: String,
val finalChapterNumber = getFinalChapter(mangaJson) val finalChapterNumber = getFinalChapter(mangaJson)
if ((status == 2 || status == 3) && chapterJson != null && isMangaCompleted(finalChapterNumber, chapterJson)) { if ((status == 2 || status == 3) && chapterJson != null && isMangaCompleted(finalChapterNumber, chapterJson)) {
manga.status = SManga.COMPLETED manga.status = SManga.COMPLETED
} else if (status == 2 && chapterJson.takeIf { it.size() > 0 }?.get(chapterJson.keys().elementAt(0))?.obj?.get("title")?.string?.trim() == "Oneshot"){
manga.status = SManga.COMPLETED
} else { } else {
manga.status = parseStatus(status) manga.status = parseStatus(status)
} }
@ -288,7 +317,7 @@ open class Mangadex(override val lang: String, private val internalLang: String,
} }
} }
private fun getFinalChapter(jsonObj: JsonObject) = jsonObj.get("last_chapter").string.trim() private fun getFinalChapter(jsonObj: JsonObject): String = jsonObj.get("last_chapter").string.trim()
private fun isMangaCompleted(finalChapterNumber: String, chapterJson: JsonObject): Boolean { private fun isMangaCompleted(finalChapterNumber: String, chapterJson: JsonObject): Boolean {
val count = chapterJson.entrySet() val count = chapterJson.entrySet()
@ -314,7 +343,6 @@ open class Mangadex(override val lang: String, private val internalLang: String,
chapterJson?.forEach { key, jsonElement -> chapterJson?.forEach { key, jsonElement ->
val chapterElement = jsonElement.asJsonObject val chapterElement = jsonElement.asJsonObject
if (chapterElement.get("lang_code").string == internalLang && (chapterElement.get("timestamp").asLong * 1000) <= now) { if (chapterElement.get("lang_code").string == internalLang && (chapterElement.get("timestamp").asLong * 1000) <= now) {
chapterElement.toString()
chapters.add(chapterFromJson(key, chapterElement, finalChapterNumber, status)) chapters.add(chapterFromJson(key, chapterElement, finalChapterNumber, status))
} }
} }
@ -424,10 +452,13 @@ open class Mangadex(override val lang: String, private val internalLang: String,
private class TextField(name: String, val key: String) : Filter.Text(name) private class TextField(name: String, val key: String) : Filter.Text(name)
private class Genre(val id: String, name: String) : Filter.TriState(name) private class Tag(val id: String, name: String) : Filter.TriState(name)
private class GenreList(genres: List<Genre>) : Filter.Group<Genre>("Genres", genres) private class ContentList(contents: List<Tag>) : Filter.Group<Tag>("Content", contents)
private class FormatList(formats: List<Tag>) : Filter.Group<Tag>("Format", formats)
private class GenreList(genres: List<Tag>) : Filter.Group<Tag>("Genres", genres)
private class R18 : Filter.Select<String>("R18+", arrayOf("Default", "Show all", "Show only", "Show none")) private class R18 : Filter.Select<String>("R18+", arrayOf("Default", "Show all", "Show only", "Show none"))
private class Demographic : Filter.Select<String>("Demographic", arrayOf("All", "Shounen", "Shoujo", "Seinen", "Josei")) private class Demographic : Filter.Select<String>("Demographic", arrayOf("All", "Shounen", "Shoujo", "Seinen", "Josei"))
private class ThemeList(themes: List<Tag>) : Filter.Group<Tag>("Themes", themes)
class SortFilter : Filter.Sort("Sort", class SortFilter : Filter.Sort("Sort",
sortables.map { it.first }.toTypedArray(), sortables.map { it.first }.toTypedArray(),
@ -442,51 +473,101 @@ open class Mangadex(override val lang: String, private val internalLang: String,
SortFilter(), SortFilter(),
Demographic(), Demographic(),
OriginalLanguage(), OriginalLanguage(),
GenreList(getGenreList()) ContentList(getContentList()),
FormatList(getFormatList()),
GenreList(getGenreList()),
ThemeList(getThemeList())
) )
private fun getContentList() = listOf(
Tag("9", "Ecchi"),
Tag("32", "Smut"),
Tag("49", "Gore"),
Tag("50", "Sexual Violence")
).sortedWith(compareBy { it.name })
private fun getFormatList() = listOf(
Tag("1", "4-koma"),
Tag("4", "Award Winning"),
Tag("7", "Doujinshi"),
Tag("21", "Oneshot"),
Tag("36", "Long Strip"),
Tag("42", "Adaption"),
Tag("43", "Anthology"),
Tag("44", "Web Comic"),
Tag("45", "Full Color"),
Tag("46", "User Created"),
Tag("47", "Official Colored"),
Tag("48", "Fan Colored")
).sortedWith(compareBy { it.name })
private fun getGenreList() = listOf( private fun getGenreList() = listOf(
Genre("1", "4-koma"), Tag("2", "Action"),
Genre("2", "Action"), Tag("3", "Adventure"),
Genre("3", "Adventure"), Tag("5", "Comedy"),
Genre("4", "Award Winning"), Tag("6", "Cooking"),
Genre("5", "Comedy"), Tag("8", "Drama"),
Genre("6", "Cooking"), Tag("10", "Fantasy"),
Genre("7", "Doujinshi"), Tag("13", "Historical"),
Genre("8", "Drama"), Tag("14", "Horror"),
Genre("9", "Ecchi"), Tag("15", "Josei"),
Genre("10", "Fantasy"), Tag("17", "Mecha"),
Genre("11", "Gender Bender"), Tag("18", "Medical"),
Genre("12", "Harem"), Tag("20", "Mystery"),
Genre("13", "Historical"), Tag("22", "Psychological"),
Genre("14", "Horror"), Tag("23", "Romance"),
Genre("15", "Josei"), Tag("25", "Sci-Fi"),
Genre("16", "Martial Arts"), Tag("28", "Shoujo Ai"),
Genre("17", "Mecha"), Tag("30", "Shounen Ai"),
Genre("18", "Medical"), Tag("31", "Slice of Life"),
Genre("19", "Music"), Tag("33", "Sports"),
Genre("20", "Mystery"), Tag("35", "Tragedy"),
Genre("21", "Oneshot"), Tag("37", "Yaoi"),
Genre("22", "Psychological"), Tag("38", "Yuri"),
Genre("23", "Romance"), Tag("41", "Isekai"),
Genre("24", "School Life"), Tag("51", "Crime"),
Genre("25", "Sci-Fi"), Tag("52", "Magical Girls"),
Genre("26", "Seinen"), Tag("53", "Philosophical"),
Genre("27", "Shoujo"), Tag("54", "Superhero"),
Genre("28", "Shoujo Ai"), Tag("55", "Thriller"),
Genre("29", "Shounen"), Tag("56", "Wuxia")
Genre("30", "Shounen Ai"), ).sortedWith(compareBy { it.name })
Genre("31", "Slice of Life"),
Genre("32", "Smut"), private fun getThemeList() = listOf(
Genre("33", "Sports"), Tag("12", "Harem"),
Genre("34", "Supernatural"), Tag("16", "Martial Arts"),
Genre("35", "Tragedy"), Tag("19", "Music"),
Genre("36", "Webtoon"), Tag("24", "School Life"),
Genre("37", "Yaoi"), Tag("34", "Supernatural"),
Genre("38", "Yuri"), Tag("40", "Video Games"),
Genre("39", "[no chapters]"), Tag("57", "Aliens"),
Genre("40", "Game"), Tag("58", "Animals"),
Genre("41", "Isekai")) Tag("59", "Crossdressing"),
Tag("60", "Demons"),
Tag("61", "Delinquents"),
Tag("62", "Genderswap"),
Tag("63", "Ghosts"),
Tag("64", "Monster Girls"),
Tag("65", "Loli"),
Tag("66", "Magic"),
Tag("67", "Military"),
Tag("68", "Monsters"),
Tag("69", "Ninja"),
Tag("70", "Office Workers"),
Tag("71", "Police"),
Tag("72", "Post-Apocalyptic"),
Tag("73", "Reincarnation"),
Tag("74", "Reverse Harem"),
Tag("75", "Samurai"),
Tag("76", "Shota"),
Tag("77", "Survival"),
Tag("78", "Time Travel"),
Tag("79", "Vampires"),
Tag("80", "Traditional Games"),
Tag("81", "Virtual Reality"),
Tag("82", "Zombies"),
Tag("83", "Incest")
).sortedWith(compareBy { it.name })
companion object { companion object {