Feat(Vizer.tv): Add video and language preferences (#988)
* feat(Vizer): Add player/language preferences * feat(Vizer): Respect player/language preferences * Vizer: bump version
This commit is contained in:
@ -6,7 +6,7 @@ ext {
|
||||
extName = 'Vizer.tv'
|
||||
pkgNameSuffix = 'pt.vizer'
|
||||
extClass = '.Vizer'
|
||||
extVersionCode = 2
|
||||
extVersionCode = 3
|
||||
libVersion = '13'
|
||||
containsNsfw = true
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ class Vizer : ConfigurableAnimeSource, AnimeHttpSource() {
|
||||
val players = client.newCall(apiRequest("getVideoPlayers=${videoObj.id}"))
|
||||
.execute()
|
||||
.parseAs<PlayersDto>()
|
||||
val langPrefix = if (videoObj.lang == "1") "SUB" else "DUB"
|
||||
val langPrefix = if (videoObj.lang == "1") "LEG" else "DUB"
|
||||
val videoList = players.iterator().mapNotNull loop@{ (name, status) ->
|
||||
if (status == "0") return@loop null
|
||||
val url = getPlayerUrl(videoObj.id, name)
|
||||
@ -271,7 +271,40 @@ class Vizer : ConfigurableAnimeSource, AnimeHttpSource() {
|
||||
preferences.edit().putString(key, entry).commit()
|
||||
}
|
||||
}
|
||||
|
||||
val preferredPlayer = ListPreference(screen.context).apply {
|
||||
key = PREF_PLAYER_KEY
|
||||
title = PREF_PLAYER_TITLE
|
||||
entries = PREF_PLAYER_ARRAY
|
||||
entryValues = PREF_PLAYER_ARRAY
|
||||
setDefaultValue("MixDrop")
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
val preferredLanguage = ListPreference(screen.context).apply {
|
||||
key = PREF_LANGUAGE_KEY
|
||||
title = PREF_LANGUAGE_TITLE
|
||||
entries = PREF_LANGUAGE_ENTRIES
|
||||
entryValues = PREF_LANGUAGE_VALUES
|
||||
setDefaultValue("LEG")
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
screen.addPreference(popularPage)
|
||||
screen.addPreference(preferredPlayer)
|
||||
screen.addPreference(preferredLanguage)
|
||||
}
|
||||
|
||||
// ============================= Utilities ==============================
|
||||
@ -289,6 +322,27 @@ class Vizer : ConfigurableAnimeSource, AnimeHttpSource() {
|
||||
return POST("$API_URL/publicFunctions.php", newHeaders, body = reqBody)
|
||||
}
|
||||
|
||||
private fun List<Video>.sortIfContains(item: String): List<Video> {
|
||||
val newList = mutableListOf<Video>()
|
||||
var preferred = 0
|
||||
for (video in this) {
|
||||
if (item in video.quality) {
|
||||
newList.add(preferred, video)
|
||||
preferred++
|
||||
} else {
|
||||
newList.add(video)
|
||||
}
|
||||
}
|
||||
return newList
|
||||
}
|
||||
|
||||
override fun List<Video>.sort(): List<Video> {
|
||||
val player = preferences.getString(PREF_PLAYER_KEY, "MixDrop")!!
|
||||
val language = preferences.getString(PREF_LANGUAGE_KEY, "LEG")!!
|
||||
val newList = this.sortIfContains(language).sortIfContains(player)
|
||||
return newList
|
||||
}
|
||||
|
||||
private inline fun <reified T> Response.parseAs(): T {
|
||||
val responseBody = body?.string().orEmpty()
|
||||
return json.decodeFromString(responseBody)
|
||||
@ -304,6 +358,17 @@ class Vizer : ConfigurableAnimeSource, AnimeHttpSource() {
|
||||
"anime", "movie", "serie"
|
||||
)
|
||||
|
||||
private const val PREF_PLAYER_KEY = "pref_player"
|
||||
private const val PREF_PLAYER_TITLE = "Player/Server favorito"
|
||||
private val PREF_PLAYER_ARRAY = arrayOf(
|
||||
"MixDrop", "StreamTape", "Fembed"
|
||||
)
|
||||
|
||||
private const val PREF_LANGUAGE_KEY = "pref_language"
|
||||
private const val PREF_LANGUAGE_TITLE = "Língua/tipo preferido"
|
||||
private val PREF_LANGUAGE_ENTRIES = arrayOf("Legendado", "Dublado")
|
||||
private val PREF_LANGUAGE_VALUES = arrayOf("LEG", "DUB")
|
||||
|
||||
const val PREFIX_SEARCH = "path:"
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user