From 4ba9118ce325fb260a01b676e98e8fd43eafce82 Mon Sep 17 00:00:00 2001 From: Arraiment <76941874+Arraiment@users.noreply.github.com> Date: Sun, 22 Aug 2021 01:32:20 +0800 Subject: [PATCH] Various fixes for Tapas (#8699) * Fix cookie management * Fix filters --- src/en/tapastic/build.gradle | 2 +- .../extension/en/tapastic/Tapastic.kt | 104 ++++++++++-------- 2 files changed, 60 insertions(+), 46 deletions(-) diff --git a/src/en/tapastic/build.gradle b/src/en/tapastic/build.gradle index 84d5339f5..83d7db254 100644 --- a/src/en/tapastic/build.gradle +++ b/src/en/tapastic/build.gradle @@ -6,7 +6,7 @@ ext { extName = 'Tapas' pkgNameSuffix = 'en.tapastic' extClass = '.Tapastic' - extVersionCode = 12 + extVersionCode = 13 libVersion = '1.2' } diff --git a/src/en/tapastic/src/eu/kanade/tachiyomi/extension/en/tapastic/Tapastic.kt b/src/en/tapastic/src/eu/kanade/tachiyomi/extension/en/tapastic/Tapastic.kt index e200ed194..decdd247a 100644 --- a/src/en/tapastic/src/eu/kanade/tachiyomi/extension/en/tapastic/Tapastic.kt +++ b/src/en/tapastic/src/eu/kanade/tachiyomi/extension/en/tapastic/Tapastic.kt @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.extension.en.tapastic import android.app.Application import android.content.SharedPreferences +import android.webkit.CookieManager import androidx.preference.PreferenceScreen import androidx.preference.SwitchPreferenceCompat import eu.kanade.tachiyomi.network.GET @@ -88,26 +89,45 @@ class Tapastic : ConfigurableSource, ParsedHttpSource() { override val client: OkHttpClient = super.client.newBuilder() .cookieJar( + // Syncs okhttp with webview cookies, allowing logged-in users do logged-in stuff object : CookieJar { - override fun saveFromResponse(url: HttpUrl, cookies: List) {} + private val webviewCookieManager = CookieManager.getInstance() + + override fun saveFromResponse(url: HttpUrl, cookies: List) { + for (cookie in cookies) { + webviewCookieManager.setCookie(url.toString(), cookie.toString()) + } + } override fun loadForRequest(url: HttpUrl): MutableList { - return ArrayList().apply { - add( - Cookie.Builder() - .domain("tapas.io") - .path("/") - .name("birthDate") - .value("1994-01-01") - .build() - ) - add( - Cookie.Builder() - .domain("tapas.io") - .path("/") - .name("adjustedBirthDate") - .value("1994-01-01") - .build() - ) + val cookiesString = webviewCookieManager.getCookie(url.toString()) + + if (cookiesString != null && cookiesString.isNotEmpty()) { + val cookieHeaders = cookiesString.split("; ").toList() + val cookies = mutableListOf() + for (header in cookieHeaders) { + cookies.add(Cookie.parse(url, header)!!) + } + // Adds age verification cookies to access mature comics + return cookies.apply { + add( + Cookie.Builder() + .domain("tapas.io") + .path("/") + .name("birthDate") + .value("1994-01-01") + .build() + ) + add( + Cookie.Builder() + .domain("tapas.io") + .path("/") + .name("adjustedBirthDate") + .value("1994-01-01") + .build() + ) + } + } else { + return mutableListOf() } } } @@ -169,6 +189,11 @@ class Tapastic : ConfigurableSource, ParsedHttpSource() { } } } + // Append sort if category = ALL + if (url.toString().contains("b=ALL")) { + val sortFilter = filterList.find { it is SortFilter } as SortFilter + sortFilter.addToUri(url) + } // Append page number url.addQueryParameter("pageNumber", page.toString()) return GET(url.toString()) @@ -272,18 +297,17 @@ class Tapastic : ConfigurableSource, ParsedHttpSource() { // Tapastic does not support genre filtering and text search at the same time Filter.Header("NOTE: All filters ignored if using text search!"), Filter.Separator(), + Filter.Header("Sort: Only applied when category is All"), + SortFilter(), + Filter.Separator(), CategoryFilter(), GenreFilter(), StatusFilter(), - Filter.Header("Sort is ignored when category filter is active!"), - SortFilter(), Filter.Separator(), Filter.Header("Mature filters"), MatureFilter("Show Mature Results Only"), MatureCategoryFilter(), - MatureGenreFilter(), - Filter.Header("Sort is ignored when category filter is active!"), - MatureSortFilter(), + MatureGenreFilter() ) private class CategoryFilter : UriSelectFilter( @@ -298,7 +322,6 @@ class Tapastic : ConfigurableSource, ParsedHttpSource() { Pair("BINGE", "Binge"), Pair("ORIGINAL", "Tapas Originals") ), - firstIsUnspecified = false, defaultValue = 1 ) @@ -335,17 +358,6 @@ class Tapastic : ConfigurableSource, ParsedHttpSource() { ) ) - private class SortFilter : UriSelectFilter( - "Sort", - false, - "s", - arrayOf( - Pair("DATE", "Date"), - Pair("LIKE", "Likes"), - Pair("SUBSCRIBE", "Subscribers") - ) - ) - private class MatureFilter(name: String) : Filter.CheckBox(name) private class MatureCategoryFilter : UriSelectFilter( @@ -357,13 +369,12 @@ class Tapastic : ConfigurableSource, ParsedHttpSource() { Pair("POPULAR", "Popular"), Pair("FRESH", "Fresh"), ), - firstIsUnspecified = false, defaultValue = 1 ) private class MatureGenreFilter : UriSelectFilter( "Genre", - false, + true, "g", arrayOf( Pair("0", "Any"), @@ -376,16 +387,19 @@ class Tapastic : ConfigurableSource, ParsedHttpSource() { ) ) - private class MatureSortFilter : UriSelectFilter( - "Sort", - true, - "s", - arrayOf( + private class SortFilter( + name: String = "Sort by", + var vals: Array> = arrayOf( Pair("DATE", "Date"), Pair("LIKE", "Likes"), Pair("SUBSCRIBE", "Subscribers") - ) - ) + ), + defaultValue: Int = 0 + ) : Filter.Select(name, vals.map { it.second }.toTypedArray(), defaultValue) { + fun addToUri(uri: HttpUrl.Builder) { + uri.addQueryParameter("s", vals[state].first) + } + } /** * Class that creates a select filter. Each entry in the dropdown has a name and a display name. @@ -398,7 +412,7 @@ class Tapastic : ConfigurableSource, ParsedHttpSource() { override val isMature: Boolean, val uriParam: String, val vals: Array>, - val firstIsUnspecified: Boolean = true, + val firstIsUnspecified: Boolean = false, defaultValue: Int = 0 ) : Filter.Select(displayName, vals.map { it.second }.toTypedArray(), defaultValue),