From 32220c1673687e242155f592c09f44ccdbd54756 Mon Sep 17 00:00:00 2001 From: AwkwardPeak7 <48650614+AwkwardPeak7@users.noreply.github.com> Date: Fri, 9 Aug 2024 17:28:29 +0500 Subject: [PATCH] MangaDistrict: get absolute dates from page list (#4527) * MangaDistrict: get absolute dates from page list * tfw --- src/en/mangadistrict/build.gradle | 2 +- .../en/mangadistrict/MangaDistrict.kt | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/en/mangadistrict/build.gradle b/src/en/mangadistrict/build.gradle index 81a664004..04a2a2041 100644 --- a/src/en/mangadistrict/build.gradle +++ b/src/en/mangadistrict/build.gradle @@ -3,7 +3,7 @@ ext { extClass = '.MangaDistrict' themePkg = 'madara' baseUrl = 'https://mangadistrict.com' - overrideVersionCode = 5 + overrideVersionCode = 6 isNsfw = true } diff --git a/src/en/mangadistrict/src/eu/kanade/tachiyomi/extension/en/mangadistrict/MangaDistrict.kt b/src/en/mangadistrict/src/eu/kanade/tachiyomi/extension/en/mangadistrict/MangaDistrict.kt index 8cddd2a4a..93e4c8122 100644 --- a/src/en/mangadistrict/src/eu/kanade/tachiyomi/extension/en/mangadistrict/MangaDistrict.kt +++ b/src/en/mangadistrict/src/eu/kanade/tachiyomi/extension/en/mangadistrict/MangaDistrict.kt @@ -7,13 +7,19 @@ import androidx.preference.PreferenceScreen import androidx.preference.SwitchPreferenceCompat import eu.kanade.tachiyomi.multisrc.madara.Madara import eu.kanade.tachiyomi.source.ConfigurableSource +import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga +import kotlinx.serialization.decodeFromString +import kotlinx.serialization.encodeToString import okhttp3.Response import org.jsoup.nodes.Document import org.jsoup.nodes.Element import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get +import java.text.SimpleDateFormat +import java.util.Locale +import java.util.TimeZone class MangaDistrict : Madara( @@ -66,9 +72,44 @@ class MangaDistrict : } } + override fun chapterFromElement(element: Element): SChapter { + return super.chapterFromElement(element).apply { + preferences.dates[url]?.also { + date_upload = it + } + } + } + + private val pageListDate = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ENGLISH).apply { + timeZone = TimeZone.getTimeZone("UTC") + } + + override fun pageListParse(document: Document): List { + try { + preferences.dates[document.location()] = pageListDate.parse( + document.selectFirst("meta[property=og:updated_time]")!! + .attr("content").substringBeforeLast("+"), + )!!.time + } catch (_: Exception) {} + + return super.pageListParse(document) + } + private fun isRemoveTitleVersion() = preferences.getBoolean(REMOVE_TITLE_VERSION_PREF, false) private fun getImgRes() = preferences.getString(IMG_RES_PREF, IMG_RES_DEFAULT)!! + private var SharedPreferences.dates: MutableMap + get() = try { + json.decodeFromString(getString(DATE_MAP, "{}") ?: "{}") + } catch (_: Exception) { + mutableMapOf() + } + set(newVal) { + val currentMap = dates + currentMap.putAll(newVal) + edit().putString(DATE_MAP, json.encodeToString(currentMap)).apply() + } + override fun setupPreferenceScreen(screen: PreferenceScreen) { SwitchPreferenceCompat(screen.context).apply { key = REMOVE_TITLE_VERSION_PREF @@ -105,5 +146,7 @@ class MangaDistrict : private const val IMG_RES_HIGH = "high" private const val IMG_RES_FULL = "full" private const val IMG_RES_DEFAULT = IMG_RES_ALL + + private const val DATE_MAP = "date_saved" } }