Add subtitle preferences for KamyRoll (#1132)
This commit is contained in:
@ -6,7 +6,7 @@ ext {
|
|||||||
extName = 'Kamyroll'
|
extName = 'Kamyroll'
|
||||||
pkgNameSuffix = 'all.kamyroll'
|
pkgNameSuffix = 'all.kamyroll'
|
||||||
extClass = '.Kamyroll'
|
extClass = '.Kamyroll'
|
||||||
extVersionCode = 1
|
extVersionCode = 2
|
||||||
libVersion = '13'
|
libVersion = '13'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,16 +202,23 @@ class Kamyroll : ConfigurableAnimeSource, AnimeHttpSource() {
|
|||||||
val streams = json.decodeFromString<VideoStreams>(response.body!!.string())
|
val streams = json.decodeFromString<VideoStreams>(response.body!!.string())
|
||||||
|
|
||||||
val subsList = mutableListOf<Track>()
|
val subsList = mutableListOf<Track>()
|
||||||
|
val subLocale = preferences.getString("preferred_sub", "en-US")!!
|
||||||
|
var subPreferred = 0
|
||||||
try {
|
try {
|
||||||
streams.subtitles.forEach { sub ->
|
streams.subtitles.forEach { sub ->
|
||||||
|
if (sub.locale == subLocale) {
|
||||||
subsList.add(
|
subsList.add(
|
||||||
Track(
|
subPreferred,
|
||||||
sub.url,
|
Track(sub.url, sub.locale.getLocale())
|
||||||
sub.locale.getLocale()
|
|
||||||
)
|
)
|
||||||
|
subPreferred++
|
||||||
|
} else {
|
||||||
|
subsList.add(
|
||||||
|
Track(sub.url, sub.locale.getLocale())
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} catch (_: Error) {}
|
}
|
||||||
|
} catch (_: Error) { }
|
||||||
|
|
||||||
return streams.streams.parallelMap { stream ->
|
return streams.streams.parallelMap { stream ->
|
||||||
runCatching {
|
runCatching {
|
||||||
@ -274,40 +281,20 @@ class Kamyroll : ConfigurableAnimeSource, AnimeHttpSource() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun List<Video>.sort(): List<Video> {
|
override fun List<Video>.sort(): List<Video> {
|
||||||
val quality = preferences.getString("preferred_quality", null)
|
val quality = preferences.getString("preferred_quality", "1080")!!
|
||||||
val dubLocale = preferences.getString("preferred_audio", null)
|
val dubLocale = preferences.getString("preferred_audio", "en-US")!!
|
||||||
|
val subLocale = preferences.getString("preferred_sub", "en-US")!!
|
||||||
|
val subType = preferences.getString("preferred_sub_type", "soft")!!
|
||||||
|
val shouldContainHard = subType == "hard"
|
||||||
|
|
||||||
val newDubSortList = mutableListOf<Video>()
|
return this.sortedWith(
|
||||||
if (dubLocale != null) {
|
compareBy(
|
||||||
var preferred = 0
|
{ it.quality.contains(quality) },
|
||||||
val dubLang = dubLocale.getLocale()
|
{ it.quality.contains("Aud: ${dubLocale.getLocale()}") },
|
||||||
for (video in this) {
|
{ it.quality.contains("HardSub") == shouldContainHard },
|
||||||
if (video.quality.contains(dubLang)) {
|
{ it.quality.contains(subLocale) }
|
||||||
newDubSortList.add(preferred, video)
|
)
|
||||||
preferred++
|
).reversed()
|
||||||
} else {
|
|
||||||
newDubSortList.add(video)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
newDubSortList.addAll(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
val newList = mutableListOf<Video>()
|
|
||||||
if (quality != null) {
|
|
||||||
var preferred = 0
|
|
||||||
for (video in newDubSortList) {
|
|
||||||
if (video.quality.contains(quality)) {
|
|
||||||
newList.add(preferred, video)
|
|
||||||
preferred++
|
|
||||||
} else {
|
|
||||||
newList.add(video)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
newList.addAll(newDubSortList)
|
|
||||||
}
|
|
||||||
return newList
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setupPreferenceScreen(screen: PreferenceScreen) {
|
override fun setupPreferenceScreen(screen: PreferenceScreen) {
|
||||||
@ -359,9 +346,43 @@ class Kamyroll : ConfigurableAnimeSource, AnimeHttpSource() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val subLocalePref = ListPreference(screen.context).apply {
|
||||||
|
key = "preferred_sub"
|
||||||
|
title = "Preferred Sub Language"
|
||||||
|
entries = locale.map { it.second }.toTypedArray()
|
||||||
|
entryValues = locale.map { it.first }.toTypedArray()
|
||||||
|
setDefaultValue("en-US")
|
||||||
|
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 subTypePref = ListPreference(screen.context).apply {
|
||||||
|
key = "preferred_sub_type"
|
||||||
|
title = "Preferred Sub Type"
|
||||||
|
entries = arrayOf("Softsub", "Hardsub")
|
||||||
|
entryValues = arrayOf("soft", "hard")
|
||||||
|
setDefaultValue("softsub")
|
||||||
|
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(domainPref)
|
screen.addPreference(domainPref)
|
||||||
screen.addPreference(videoQualityPref)
|
screen.addPreference(videoQualityPref)
|
||||||
screen.addPreference(audLocalePref)
|
screen.addPreference(audLocalePref)
|
||||||
|
screen.addPreference(subLocalePref)
|
||||||
|
screen.addPreference(subTypePref)
|
||||||
}
|
}
|
||||||
|
|
||||||
// From Dopebox
|
// From Dopebox
|
||||||
|
Reference in New Issue
Block a user