Flame Scans: Update Permanent Url logic and enable by default (#10232)

* Flame Scans: Update Permanent Url logic and enable by default

* Quick Fix
This commit is contained in:
FourTOne5 2021-12-27 17:05:38 +06:00 committed by GitHub
parent 2a1eaf5314
commit 63e9f627e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 30 deletions

View File

@ -137,6 +137,7 @@ open class FlameScans(
} }
// Split Image Fixer End // Split Image Fixer End
// Permanent Url start
override fun fetchPopularManga(page: Int): Observable<MangasPage> { override fun fetchPopularManga(page: Int): Observable<MangasPage> {
return super.fetchPopularManga(page).tempUrlToPermIfNeeded() return super.fetchPopularManga(page).tempUrlToPermIfNeeded()
} }
@ -159,41 +160,36 @@ open class FlameScans(
} }
private fun SManga.tempUrlToPermIfNeeded(): SManga { private fun SManga.tempUrlToPermIfNeeded(): SManga {
val sManga = this val turnTempUrlToPerm = preferences.getBoolean(getPermanentMangaUrlPreferenceKey(), true)
if (!turnTempUrlToPerm) return this
val turnTempUrlToPerm = preferences.getBoolean(getPermanentMangaUrlPreferenceKey(), false) val sMangaTitleFirstWord = this.title.split(" ")[0]
if (!turnTempUrlToPerm) return sManga if (!this.url.contains("/$sMangaTitleFirstWord", ignoreCase = true)) {
this.url = this.url.replaceFirst(TEMP_TO_PERM_URL_REGEX, "$1")
val sMangaUrl = sManga.url
val sMangaTitleFirstWord = sManga.title.split(" ")[0]
return if (sMangaUrl.startsWith("$mangaUrlDirectory/$sMangaTitleFirstWord")) {
sManga
} else {
sManga.url = sMangaUrl.replaceFirst(TEMP_TO_PERM_URL_REGEX, "$1")
sManga
} }
return this
} }
override fun fetchChapterList(manga: SManga): Observable<List<SChapter>> { override fun fetchChapterList(manga: SManga): Observable<List<SChapter>> {
return super.fetchChapterList(manga).map { sChapterList -> val sManga = manga.tempUrlToPermIfNeeded()
sChapterList.map { it.tempUrlToPermIfNeeded() } return super.fetchChapterList(sManga).map { sChapterList ->
sChapterList.map { it.tempUrlToPermIfNeeded(sManga) }
} }
} }
private fun SChapter.tempUrlToPermIfNeeded(): SChapter { private fun SChapter.tempUrlToPermIfNeeded(manga: SManga): SChapter {
val sChapter = this val turnTempUrlToPerm = preferences.getBoolean(getPermanentChapterUrlPreferenceKey(), true)
if (!turnTempUrlToPerm) return this
val turnTempUrlToPerm = preferences.getBoolean(getPermanentChapterUrlPreferenceKey(), false) val sChapterNameFirstWord = this.name.split(" ")[0]
if (!turnTempUrlToPerm) return sChapter val sMangaTitleFirstWord = manga.title.split(" ")[0]
if (
val sChapterUrl = sChapter.url !this.url.contains("/$sChapterNameFirstWord", ignoreCase = true) &&
val sChapterNameFirstWord = sChapter.name.split(" ")[0] !this.url.contains("/$sMangaTitleFirstWord", ignoreCase = true)
return if (sChapterUrl.startsWith("/$sChapterNameFirstWord")) { ) {
sChapter this.url = this.url.replaceFirst(TEMP_TO_PERM_URL_REGEX, "$1")
} else {
sChapter.url = sChapterUrl.replaceFirst(TEMP_TO_PERM_URL_REGEX, "$1")
sChapter
} }
return this
} }
override fun setupPreferenceScreen(screen: PreferenceScreen) { override fun setupPreferenceScreen(screen: PreferenceScreen) {
@ -201,7 +197,7 @@ open class FlameScans(
key = getPermanentMangaUrlPreferenceKey() key = getPermanentMangaUrlPreferenceKey()
title = PREF_PERM_MANGA_URL_TITLE title = PREF_PERM_MANGA_URL_TITLE
summary = PREF_PERM_MANGA_URL_SUMMARY summary = PREF_PERM_MANGA_URL_SUMMARY
setDefaultValue(false) setDefaultValue(true)
setOnPreferenceChangeListener { _, newValue -> setOnPreferenceChangeListener { _, newValue ->
val checkValue = newValue as Boolean val checkValue = newValue as Boolean
@ -214,7 +210,7 @@ open class FlameScans(
key = getPermanentChapterUrlPreferenceKey() key = getPermanentChapterUrlPreferenceKey()
title = PREF_PERM_CHAPTER_URL_TITLE title = PREF_PERM_CHAPTER_URL_TITLE
summary = PREF_PERM_CHAPTER_URL_SUMMARY summary = PREF_PERM_CHAPTER_URL_SUMMARY
setDefaultValue(false) setDefaultValue(true)
setOnPreferenceChangeListener { _, newValue -> setOnPreferenceChangeListener { _, newValue ->
val checkValue = newValue as Boolean val checkValue = newValue as Boolean
@ -240,11 +236,11 @@ open class FlameScans(
private const val COMPOSED_SUFFIX = "?comp" private const val COMPOSED_SUFFIX = "?comp"
private const val PREF_PERM_MANGA_URL_KEY_PREFIX = "pref_permanent_manga_url_" private const val PREF_PERM_MANGA_URL_KEY_PREFIX = "pref_permanent_manga_url_"
private const val PREF_PERM_MANGA_URL_TITLE = "Permanent Manga Url" private const val PREF_PERM_MANGA_URL_TITLE = "Permanent Manga URL"
private const val PREF_PERM_MANGA_URL_SUMMARY = "Turns all manga urls into permanent ones." private const val PREF_PERM_MANGA_URL_SUMMARY = "Turns all manga urls into permanent ones."
private const val PREF_PERM_CHAPTER_URL_KEY_PREFIX = "pref_permanent_chapter_url" private const val PREF_PERM_CHAPTER_URL_KEY_PREFIX = "pref_permanent_chapter_url"
private const val PREF_PERM_CHAPTER_URL_TITLE = "Permanent Chapter URl" private const val PREF_PERM_CHAPTER_URL_TITLE = "Permanent Chapter URL"
private const val PREF_PERM_CHAPTER_URL_SUMMARY = "Turns all chapter urls into permanent one." private const val PREF_PERM_CHAPTER_URL_SUMMARY = "Turns all chapter urls into permanent one."
private val TEMP_TO_PERM_URL_REGEX = Regex("""(/)\d+-""") private val TEMP_TO_PERM_URL_REGEX = Regex("""(/)\d+-""")

View File

@ -13,7 +13,7 @@ class WPMangaReaderGenerator : ThemeSourceGenerator {
override val baseVersionCode: Int = 11 override val baseVersionCode: Int = 11
override val sources = listOf( override val sources = listOf(
MultiLang("Flame Scans", "https://flamescans.org", listOf("ar", "en"), className = "FlameScansFactory", pkgName = "flamescans"), MultiLang("Flame Scans", "https://flamescans.org", listOf("ar", "en"), className = "FlameScansFactory", pkgName = "flamescans", overrideVersionCode = 1),
SingleLang("Anitation Arts", "https://anitationarts.org", "en", overrideVersionCode = 1), SingleLang("Anitation Arts", "https://anitationarts.org", "en", overrideVersionCode = 1),
SingleLang("Alpha Scans", "https://alpha-scans.org", "en", overrideVersionCode = 1), SingleLang("Alpha Scans", "https://alpha-scans.org", "en", overrideVersionCode = 1),
SingleLang("BeastScans", "https://beastscans.com", "en"), SingleLang("BeastScans", "https://beastscans.com", "en"),