added subs language preference [zoro] (#720)
* added subs language preference [zoro] * version update
This commit is contained in:
committed by
GitHub
parent
9a614af9ea
commit
491a39588c
@ -5,7 +5,7 @@ ext {
|
|||||||
extName = 'zoro.to (experimental)'
|
extName = 'zoro.to (experimental)'
|
||||||
pkgNameSuffix = 'en.zoro'
|
pkgNameSuffix = 'en.zoro'
|
||||||
extClass = '.Zoro'
|
extClass = '.Zoro'
|
||||||
extVersionCode = 8
|
extVersionCode = 9
|
||||||
libVersion = '13'
|
libVersion = '13'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,16 +124,17 @@ class Zoro : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
|||||||
if (!source.contains("{\"sources\":[{\"file\":\"")) return null
|
if (!source.contains("{\"sources\":[{\"file\":\"")) return null
|
||||||
val json = json.decodeFromString<JsonObject>(source)
|
val json = json.decodeFromString<JsonObject>(source)
|
||||||
val masterUrl = json["sources"]!!.jsonArray[0].jsonObject["file"]!!.jsonPrimitive.content
|
val masterUrl = json["sources"]!!.jsonArray[0].jsonObject["file"]!!.jsonPrimitive.content
|
||||||
val subs = mutableListOf<Track>()
|
val subs2 = mutableListOf<Track>()
|
||||||
json["tracks"]?.jsonArray
|
json["tracks"]?.jsonArray
|
||||||
?.filter { it.jsonObject["kind"]!!.jsonPrimitive.content == "captions" }
|
?.filter { it.jsonObject["kind"]!!.jsonPrimitive.content == "captions" }
|
||||||
?.map { track ->
|
?.map { track ->
|
||||||
val trackUrl = track.jsonObject["file"]!!.jsonPrimitive.content
|
val trackUrl = track.jsonObject["file"]!!.jsonPrimitive.content
|
||||||
val lang = track.jsonObject["label"]!!.jsonPrimitive.content
|
val lang = track.jsonObject["label"]!!.jsonPrimitive.content
|
||||||
try {
|
try {
|
||||||
subs.add(Track(trackUrl, lang))
|
subs2.add(Track(trackUrl, lang))
|
||||||
} catch (e: Error) {}
|
} catch (e: Error) {}
|
||||||
} ?: emptyList()
|
} ?: emptyList()
|
||||||
|
val subs = subLangOrder(subs2)
|
||||||
val masterPlaylist = client.newCall(GET(masterUrl)).execute().body!!.string()
|
val masterPlaylist = client.newCall(GET(masterUrl)).execute().body!!.string()
|
||||||
val videoList = mutableListOf<Video>()
|
val videoList = mutableListOf<Video>()
|
||||||
masterPlaylist.substringAfter("#EXT-X-STREAM-INF:").split("#EXT-X-STREAM-INF:").forEach {
|
masterPlaylist.substringAfter("#EXT-X-STREAM-INF:").split("#EXT-X-STREAM-INF:").forEach {
|
||||||
@ -174,6 +175,24 @@ class Zoro : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun subLangOrder(tracks: List<Track>): List<Track> {
|
||||||
|
val language = preferences.getString("preferred_subLang", null)
|
||||||
|
if (language != null) {
|
||||||
|
val newList = mutableListOf<Track>()
|
||||||
|
var preferred = 0
|
||||||
|
for (track in tracks) {
|
||||||
|
if (track.lang == language) {
|
||||||
|
newList.add(preferred, track)
|
||||||
|
preferred++
|
||||||
|
} else {
|
||||||
|
newList.add(track)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return newList
|
||||||
|
}
|
||||||
|
return tracks
|
||||||
|
}
|
||||||
|
|
||||||
override fun searchAnimeFromElement(element: Element) = popularAnimeFromElement(element)
|
override fun searchAnimeFromElement(element: Element) = popularAnimeFromElement(element)
|
||||||
|
|
||||||
override fun searchAnimeNextPageSelector(): String = popularAnimeNextPageSelector()
|
override fun searchAnimeNextPageSelector(): String = popularAnimeNextPageSelector()
|
||||||
@ -224,6 +243,22 @@ class Zoro : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
|||||||
preferences.edit().putString(key, entry).commit()
|
preferences.edit().putString(key, entry).commit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
val subLangPref = ListPreference(screen.context).apply {
|
||||||
|
key = "preferred_subLang"
|
||||||
|
title = "Preferred sub language"
|
||||||
|
entries = arrayOf("English", "Spanish", "Portuguese", "French", "German", "Italian", "Japanese", "Russian")
|
||||||
|
entryValues = arrayOf("English", "Spanish", "Portuguese", "French", "German", "Italian", "Japanese", "Russian")
|
||||||
|
setDefaultValue("English")
|
||||||
|
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(videoQualityPref)
|
screen.addPreference(videoQualityPref)
|
||||||
|
screen.addPreference(subLangPref)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user