fix(pt/vizer): Fix crashes in episode list and video list (#3189)
This commit is contained in:
parent
06d6953f95
commit
0fdb8d25b4
@ -1,7 +1,7 @@
|
|||||||
ext {
|
ext {
|
||||||
extName = 'Vizer.tv'
|
extName = 'Vizer.tv'
|
||||||
extClass = '.Vizer'
|
extClass = '.Vizer'
|
||||||
extVersionCode = 14
|
extVersionCode = 15
|
||||||
isNsfw = true
|
isNsfw = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,9 @@ import eu.kanade.tachiyomi.lib.streamtapeextractor.StreamTapeExtractor
|
|||||||
import eu.kanade.tachiyomi.network.GET
|
import eu.kanade.tachiyomi.network.GET
|
||||||
import eu.kanade.tachiyomi.network.POST
|
import eu.kanade.tachiyomi.network.POST
|
||||||
import eu.kanade.tachiyomi.network.awaitSuccess
|
import eu.kanade.tachiyomi.network.awaitSuccess
|
||||||
|
import eu.kanade.tachiyomi.network.interceptor.rateLimitHost
|
||||||
import eu.kanade.tachiyomi.util.asJsoup
|
import eu.kanade.tachiyomi.util.asJsoup
|
||||||
|
import eu.kanade.tachiyomi.util.parallelCatchingFlatMapBlocking
|
||||||
import eu.kanade.tachiyomi.util.parseAs
|
import eu.kanade.tachiyomi.util.parseAs
|
||||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||||
import okhttp3.MediaType.Companion.toMediaType
|
import okhttp3.MediaType.Companion.toMediaType
|
||||||
@ -33,6 +35,7 @@ import okhttp3.Response
|
|||||||
import org.jsoup.nodes.Element
|
import org.jsoup.nodes.Element
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
|
import kotlin.time.Duration.Companion.seconds
|
||||||
|
|
||||||
class Vizer : ConfigurableAnimeSource, AnimeHttpSource() {
|
class Vizer : ConfigurableAnimeSource, AnimeHttpSource() {
|
||||||
|
|
||||||
@ -47,6 +50,10 @@ class Vizer : ConfigurableAnimeSource, AnimeHttpSource() {
|
|||||||
|
|
||||||
override fun headersBuilder() = super.headersBuilder().add("Referer", "$baseUrl/")
|
override fun headersBuilder() = super.headersBuilder().add("Referer", "$baseUrl/")
|
||||||
|
|
||||||
|
private val episodesClient by lazy {
|
||||||
|
client.newBuilder().rateLimitHost(baseUrl.toHttpUrl(), 1, 1.5.seconds).build()
|
||||||
|
}
|
||||||
|
|
||||||
private val preferences by lazy {
|
private val preferences by lazy {
|
||||||
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
||||||
}
|
}
|
||||||
@ -140,7 +147,7 @@ class Vizer : ConfigurableAnimeSource, AnimeHttpSource() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return GET(urlBuilder.build().toString(), headers)
|
return GET(urlBuilder.build(), headers)
|
||||||
}
|
}
|
||||||
|
|
||||||
// =========================== Anime Details ============================
|
// =========================== Anime Details ============================
|
||||||
@ -152,9 +159,9 @@ class Vizer : ConfigurableAnimeSource, AnimeHttpSource() {
|
|||||||
|
|
||||||
description = buildString {
|
description = buildString {
|
||||||
append(doc.selectFirst("span.desc")!!.text() + "\n")
|
append(doc.selectFirst("span.desc")!!.text() + "\n")
|
||||||
doc.selectFirst("div.year")?.also { append("\nAno: ${it.text()}") }
|
doc.selectFirst("div.year")?.also { append("\nAno: ", it.text()) }
|
||||||
doc.selectFirst("div.tm")?.also { append("\nDuração: ${it.text()}") }
|
doc.selectFirst("div.tm")?.also { append("\nDuração: ", it.text()) }
|
||||||
doc.selectFirst("a.rating")?.also { append("\nNota: ${it.text()}") }
|
doc.selectFirst("a.rating")?.also { append("\nNota: ", it.text()) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,13 +169,19 @@ class Vizer : ConfigurableAnimeSource, AnimeHttpSource() {
|
|||||||
private fun getSeasonEps(seasonElement: Element): List<SEpisode> {
|
private fun getSeasonEps(seasonElement: Element): List<SEpisode> {
|
||||||
val id = seasonElement.attr("data-season-id")
|
val id = seasonElement.attr("data-season-id")
|
||||||
val sname = seasonElement.text()
|
val sname = seasonElement.text()
|
||||||
val response = client.newCall(apiRequest("getEpisodes=$id")).execute()
|
val response = episodesClient.newCall(apiRequest("getEpisodes=$id")).execute()
|
||||||
val episodes = response.parseAs<EpisodeListDto>().episodes
|
val episodes = response.parseAs<EpisodeListDto>().episodes
|
||||||
.values
|
.values
|
||||||
.filter { it.released }
|
.filter { it.released }
|
||||||
.map {
|
.map {
|
||||||
SEpisode.create().apply {
|
SEpisode.create().apply {
|
||||||
name = "Temp $sname: Ep ${it.name} - ${it.title}"
|
name = "$sname: Ep ${it.name}".run {
|
||||||
|
if (!it.title.contains("Episode ")) {
|
||||||
|
this + " - ${it.title}"
|
||||||
|
} else {
|
||||||
|
this
|
||||||
|
}
|
||||||
|
}
|
||||||
episode_number = it.name.toFloatOrNull() ?: 0F
|
episode_number = it.name.toFloatOrNull() ?: 0F
|
||||||
url = it.id
|
url = it.id
|
||||||
}
|
}
|
||||||
@ -221,7 +234,7 @@ class Vizer : ConfigurableAnimeSource, AnimeHttpSource() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return videoObjectList.flatMap(::getVideosFromObject)
|
return videoObjectList.parallelCatchingFlatMapBlocking(::getVideosFromObject)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val mixdropExtractor by lazy { MixDropExtractor(client) }
|
private val mixdropExtractor by lazy { MixDropExtractor(client) }
|
||||||
@ -254,13 +267,6 @@ class Vizer : ConfigurableAnimeSource, AnimeHttpSource() {
|
|||||||
entryValues = PREF_POPULAR_PAGE_VALUES
|
entryValues = PREF_POPULAR_PAGE_VALUES
|
||||||
setDefaultValue(PREF_POPULAR_PAGE_DEFAULT)
|
setDefaultValue(PREF_POPULAR_PAGE_DEFAULT)
|
||||||
summary = "%s"
|
summary = "%s"
|
||||||
|
|
||||||
setOnPreferenceChangeListener { _, newValue ->
|
|
||||||
val selected = newValue as String
|
|
||||||
val index = findIndexOfValue(selected)
|
|
||||||
val entry = entryValues[index] as String
|
|
||||||
preferences.edit().putString(key, entry).commit()
|
|
||||||
}
|
|
||||||
}.also(screen::addPreference)
|
}.also(screen::addPreference)
|
||||||
|
|
||||||
ListPreference(screen.context).apply {
|
ListPreference(screen.context).apply {
|
||||||
@ -270,13 +276,6 @@ class Vizer : ConfigurableAnimeSource, AnimeHttpSource() {
|
|||||||
entryValues = PREF_PLAYER_ARRAY
|
entryValues = PREF_PLAYER_ARRAY
|
||||||
setDefaultValue(PREF_PLAYER_DEFAULT)
|
setDefaultValue(PREF_PLAYER_DEFAULT)
|
||||||
summary = "%s"
|
summary = "%s"
|
||||||
|
|
||||||
setOnPreferenceChangeListener { _, newValue ->
|
|
||||||
val selected = newValue as String
|
|
||||||
val index = findIndexOfValue(selected)
|
|
||||||
val entry = entryValues[index] as String
|
|
||||||
preferences.edit().putString(key, entry).commit()
|
|
||||||
}
|
|
||||||
}.also(screen::addPreference)
|
}.also(screen::addPreference)
|
||||||
|
|
||||||
ListPreference(screen.context).apply {
|
ListPreference(screen.context).apply {
|
||||||
@ -286,13 +285,6 @@ class Vizer : ConfigurableAnimeSource, AnimeHttpSource() {
|
|||||||
entryValues = PREF_LANGUAGE_VALUES
|
entryValues = PREF_LANGUAGE_VALUES
|
||||||
setDefaultValue(PREF_LANGUAGE_DEFAULT)
|
setDefaultValue(PREF_LANGUAGE_DEFAULT)
|
||||||
summary = "%s"
|
summary = "%s"
|
||||||
|
|
||||||
setOnPreferenceChangeListener { _, newValue ->
|
|
||||||
val selected = newValue as String
|
|
||||||
val index = findIndexOfValue(selected)
|
|
||||||
val entry = entryValues[index] as String
|
|
||||||
preferences.edit().putString(key, entry).commit()
|
|
||||||
}
|
|
||||||
}.also(screen::addPreference)
|
}.also(screen::addPreference)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,12 @@ import eu.kanade.tachiyomi.util.parseAs
|
|||||||
import kotlinx.serialization.EncodeDefault
|
import kotlinx.serialization.EncodeDefault
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
import kotlinx.serialization.builtins.serializer
|
||||||
|
import kotlinx.serialization.json.JsonElement
|
||||||
|
import kotlinx.serialization.json.JsonPrimitive
|
||||||
|
import kotlinx.serialization.json.JsonTransformingSerializer
|
||||||
|
import kotlinx.serialization.json.booleanOrNull
|
||||||
|
import kotlinx.serialization.json.jsonPrimitive
|
||||||
|
|
||||||
typealias FakeList<T> = Map<String, T>
|
typealias FakeList<T> = Map<String, T>
|
||||||
|
|
||||||
@ -34,6 +40,7 @@ class EpisodeListDto(
|
|||||||
class EpisodeItemDto(
|
class EpisodeItemDto(
|
||||||
val id: String,
|
val id: String,
|
||||||
val name: String,
|
val name: String,
|
||||||
|
@Serializable(with = BooleanSerializer::class)
|
||||||
val released: Boolean,
|
val released: Boolean,
|
||||||
val title: String,
|
val title: String,
|
||||||
)
|
)
|
||||||
@ -72,3 +79,14 @@ class HostersDto(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
object BooleanSerializer : JsonTransformingSerializer<Boolean>(Boolean.serializer()) {
|
||||||
|
override fun transformDeserialize(element: JsonElement): JsonElement {
|
||||||
|
require(element is JsonPrimitive)
|
||||||
|
return if (element.jsonPrimitive.isString) {
|
||||||
|
JsonPrimitive(true)
|
||||||
|
} else {
|
||||||
|
JsonPrimitive(element.jsonPrimitive.booleanOrNull ?: false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user