YugenMangas: Fix not showing new chapters (#17318)

* Use permUrl only if fetchAllTitles is true

* Add extension setting

* Move extension settings to Yugen

* Set default to "true" so that users dont have to migrate

* Import SwitchPreferenceCompact

Co-authored-by: Alessandro Jean <14254807+alessandrojean@users.noreply.github.com>

* Remove ChangeListener

Co-authored-by: Alessandro Jean <14254807+alessandrojean@users.noreply.github.com>

* Show toast

---------

Co-authored-by: Alessandro Jean <14254807+alessandrojean@users.noreply.github.com>
This commit is contained in:
Rolando Lecca 2023-07-30 16:37:17 -05:00 committed by GitHub
parent 66cd665b92
commit 920a2812df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 68 additions and 20 deletions

View File

@ -1,22 +1,38 @@
package eu.kanade.tachiyomi.extension.es.yugenmangas package eu.kanade.tachiyomi.extension.es.yugenmangas
import android.app.Application
import android.content.SharedPreferences
import android.widget.Toast
import androidx.preference.PreferenceScreen
import androidx.preference.SwitchPreferenceCompat
import eu.kanade.tachiyomi.multisrc.heancms.Genre import eu.kanade.tachiyomi.multisrc.heancms.Genre
import eu.kanade.tachiyomi.multisrc.heancms.HeanCms import eu.kanade.tachiyomi.multisrc.heancms.HeanCms
import eu.kanade.tachiyomi.network.interceptor.rateLimit import eu.kanade.tachiyomi.network.interceptor.rateLimit
import eu.kanade.tachiyomi.source.ConfigurableSource
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.TimeZone import java.util.TimeZone
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
class YugenMangas : HeanCms( class YugenMangas :
"YugenMangas", HeanCms(
"https://yugenmangas.net", "YugenMangas",
"es", "https://yugenmangas.net",
"https://api.yugenmangas.net", "es",
) { "https://api.yugenmangas.net",
),
ConfigurableSource {
private val preferences: SharedPreferences by lazy {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
}
// Site changed from Madara to HeanCms. // Site changed from Madara to HeanCms.
override val versionId = 2 override val versionId = 2
override val fetchAllTitles = getFetchAllSeriesPref()
override val client = super.client.newBuilder() override val client = super.client.newBuilder()
.connectTimeout(60, TimeUnit.SECONDS) .connectTimeout(60, TimeUnit.SECONDS)
.readTimeout(90, TimeUnit.SECONDS) .readTimeout(90, TimeUnit.SECONDS)
@ -29,6 +45,26 @@ class YugenMangas : HeanCms(
timeZone = TimeZone.getTimeZone("UTC") timeZone = TimeZone.getTimeZone("UTC")
} }
private fun getFetchAllSeriesPref(): Boolean {
return preferences.getBoolean(FETCH_ALL_SERIES_PREF, FETCH_ALL_SERIES_DEFAULT_VALUE)
}
override fun setupPreferenceScreen(screen: PreferenceScreen) {
val fetchAllSeriesPreference = SwitchPreferenceCompat(screen.context).apply {
key = FETCH_ALL_SERIES_PREF
title = FETCH_ALL_SERIES_TITLE
summary = FETCH_ALL_SERIES_SUMMARY
setDefaultValue(FETCH_ALL_SERIES_DEFAULT_VALUE)
setOnPreferenceChangeListener { _, newValue ->
Toast.makeText(screen.context, "Reinicia la app para aplicar los cambios.", Toast.LENGTH_LONG).show()
true
}
}
screen.addPreference(fetchAllSeriesPreference)
}
override fun getGenreList(): List<Genre> = listOf( override fun getGenreList(): List<Genre> = listOf(
Genre("+18", 1), Genre("+18", 1),
Genre("Acción", 36), Genre("Acción", 36),
@ -79,4 +115,14 @@ class YugenMangas : HeanCms(
Genre("Yaoi", 43), Genre("Yaoi", 43),
Genre("Yuri", 44), Genre("Yuri", 44),
) )
companion object {
private const val FETCH_ALL_SERIES_PREF = "fetchAllSeriesPref"
private const val FETCH_ALL_SERIES_TITLE = "Buscar todas las series"
private const val FETCH_ALL_SERIES_SUMMARY = "Busca las URLs actuales de las series. " +
"Habilitar esta opción evita la necesidad de migrar, " +
"pero puede llevar tiempo dependiendo del número total de series. \n" +
"Tendrá que migrar cada vez que cambie esta opción."
private const val FETCH_ALL_SERIES_DEFAULT_VALUE = true
}
} }

View File

@ -81,7 +81,7 @@ abstract class HeanCms(
if (json.startsWith("{")) { if (json.startsWith("{")) {
val result = json.parseAs<HeanCmsQuerySearchDto>() val result = json.parseAs<HeanCmsQuerySearchDto>()
val mangaList = result.data.map { it.toSManga(apiUrl, coverPath) } val mangaList = result.data.map { it.toSManga(apiUrl, coverPath, fetchAllTitles) }
fetchAllTitles() fetchAllTitles()
@ -89,7 +89,7 @@ abstract class HeanCms(
} }
val mangaList = json.parseAs<List<HeanCmsSeriesDto>>() val mangaList = json.parseAs<List<HeanCmsSeriesDto>>()
.map { it.toSManga(apiUrl, coverPath) } .map { it.toSManga(apiUrl, coverPath, fetchAllTitles) }
fetchAllTitles() fetchAllTitles()
@ -179,14 +179,14 @@ abstract class HeanCms(
val result = json.parseAs<List<HeanCmsSearchDto>>() val result = json.parseAs<List<HeanCmsSearchDto>>()
val mangaList = result val mangaList = result
.filter { it.type == "Comic" } .filter { it.type == "Comic" }
.map { it.toSManga(apiUrl, coverPath, seriesSlugMap.orEmpty()) } .map { it.toSManga(apiUrl, coverPath, seriesSlugMap.orEmpty(), fetchAllTitles) }
return MangasPage(mangaList, false) return MangasPage(mangaList, false)
} }
if (json.startsWith("{")) { if (json.startsWith("{")) {
val result = json.parseAs<HeanCmsQuerySearchDto>() val result = json.parseAs<HeanCmsQuerySearchDto>()
val mangaList = result.data.map { it.toSManga(apiUrl, coverPath) } val mangaList = result.data.map { it.toSManga(apiUrl, coverPath, fetchAllTitles) }
fetchAllTitles() fetchAllTitles()
@ -194,7 +194,7 @@ abstract class HeanCms(
} }
val mangaList = json.parseAs<List<HeanCmsSeriesDto>>() val mangaList = json.parseAs<List<HeanCmsSeriesDto>>()
.map { it.toSManga(apiUrl, coverPath) } .map { it.toSManga(apiUrl, coverPath, fetchAllTitles) }
fetchAllTitles() fetchAllTitles()
@ -206,7 +206,7 @@ abstract class HeanCms(
.substringAfterLast("/") .substringAfterLast("/")
.replace(TIMESTAMP_REGEX, "") .replace(TIMESTAMP_REGEX, "")
val currentSlug = seriesSlugMap?.get(seriesSlug)?.slug ?: seriesSlug val currentSlug = seriesSlugMap?.get(seriesSlug)?.slug ?: manga.url.substringAfterLast("/")
return "$baseUrl/series/$currentSlug" return "$baseUrl/series/$currentSlug"
} }
@ -219,7 +219,7 @@ abstract class HeanCms(
fetchAllTitles() fetchAllTitles()
val seriesDetails = seriesSlugMap?.get(seriesSlug) val seriesDetails = seriesSlugMap?.get(seriesSlug)
val currentSlug = seriesDetails?.slug ?: seriesSlug val currentSlug = seriesDetails?.slug ?: manga.url.substringAfterLast("/")
val currentStatus = seriesDetails?.status ?: manga.status val currentStatus = seriesDetails?.status ?: manga.status
val apiHeaders = headersBuilder() val apiHeaders = headersBuilder()
@ -231,7 +231,7 @@ abstract class HeanCms(
override fun mangaDetailsParse(response: Response): SManga { override fun mangaDetailsParse(response: Response): SManga {
val result = runCatching { response.parseAs<HeanCmsSeriesDto>() } val result = runCatching { response.parseAs<HeanCmsSeriesDto>() }
val seriesDetails = result.getOrNull()?.toSManga(apiUrl, coverPath) val seriesDetails = result.getOrNull()?.toSManga(apiUrl, coverPath, fetchAllTitles)
?: throw Exception(intl.urlChangedError(name)) ?: throw Exception(intl.urlChangedError(name))
return seriesDetails.apply { return seriesDetails.apply {

View File

@ -36,14 +36,15 @@ data class HeanCmsSearchDto(
apiUrl: String, apiUrl: String,
coverPath: String, coverPath: String,
slugMap: Map<String, HeanCms.HeanCmsTitle>, slugMap: Map<String, HeanCms.HeanCmsTitle>,
usePermSlug: Boolean,
): SManga = SManga.create().apply { ): SManga = SManga.create().apply {
val slugOnly = slug.replace(HeanCms.TIMESTAMP_REGEX, "") val slug = if (!usePermSlug) slug else slug.replace(HeanCms.TIMESTAMP_REGEX, "")
val thumbnailFileName = slugMap[slugOnly]?.thumbnailFileName val thumbnailFileName = slugMap[slug]?.thumbnailFileName
title = this@HeanCmsSearchDto.title title = this@HeanCmsSearchDto.title
thumbnail_url = thumbnail?.toAbsoluteThumbnailUrl(apiUrl, coverPath) thumbnail_url = thumbnail?.toAbsoluteThumbnailUrl(apiUrl, coverPath)
?: thumbnailFileName?.toAbsoluteThumbnailUrl(apiUrl, coverPath) ?: thumbnailFileName?.toAbsoluteThumbnailUrl(apiUrl, coverPath)
url = "/series/$slugOnly" url = "/series/$slug"
} }
} }
@ -62,8 +63,9 @@ data class HeanCmsSeriesDto(
val chapters: List<HeanCmsChapterDto>? = emptyList(), val chapters: List<HeanCmsChapterDto>? = emptyList(),
) { ) {
fun toSManga(apiUrl: String, coverPath: String): SManga = SManga.create().apply { fun toSManga(apiUrl: String, coverPath: String, usePermSlug: Boolean): SManga = SManga.create().apply {
val descriptionBody = this@HeanCmsSeriesDto.description?.let(Jsoup::parseBodyFragment) val descriptionBody = this@HeanCmsSeriesDto.description?.let(Jsoup::parseBodyFragment)
val slug = if (!usePermSlug) slug else slug.replace(HeanCms.TIMESTAMP_REGEX, "")
title = this@HeanCmsSeriesDto.title title = this@HeanCmsSeriesDto.title
author = this@HeanCmsSeriesDto.author?.trim() author = this@HeanCmsSeriesDto.author?.trim()
@ -77,7 +79,7 @@ data class HeanCmsSeriesDto(
thumbnail_url = thumbnail.ifEmpty { null } thumbnail_url = thumbnail.ifEmpty { null }
?.toAbsoluteThumbnailUrl(apiUrl, coverPath) ?.toAbsoluteThumbnailUrl(apiUrl, coverPath)
status = this@HeanCmsSeriesDto.status?.toStatus() ?: SManga.UNKNOWN status = this@HeanCmsSeriesDto.status?.toStatus() ?: SManga.UNKNOWN
url = "/series/${slug.replace(HeanCms.TIMESTAMP_REGEX, "")}" url = "/series/$slug"
} }
} }

View File

@ -9,7 +9,7 @@ class HeanCmsGenerator : ThemeSourceGenerator {
override val themeClass = "HeanCms" override val themeClass = "HeanCms"
override val baseVersionCode: Int = 13 override val baseVersionCode: Int = 14
override val sources = listOf( override val sources = listOf(
SingleLang("Glorious Scan", "https://gloriousscan.com", "pt-BR", overrideVersionCode = 17), SingleLang("Glorious Scan", "https://gloriousscan.com", "pt-BR", overrideVersionCode = 17),