mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
[Feature] Filter subtitle using 'preferred media' language
This commit is contained in:
parent
bbf9f247a9
commit
b5337a1cfb
4 changed files with 55 additions and 1 deletions
|
@ -1004,12 +1004,25 @@ class GeneratorPlayer : FullScreenPlayer() {
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
var langFilterList = listOf<String>()
|
||||||
|
var filterSubByLang = false
|
||||||
|
|
||||||
context?.let { ctx ->
|
context?.let { ctx ->
|
||||||
val settingsManager = PreferenceManager.getDefaultSharedPreferences(ctx)
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(ctx)
|
||||||
titleRez = settingsManager.getInt(ctx.getString(R.string.prefer_limit_title_rez_key), 3)
|
titleRez = settingsManager.getInt(ctx.getString(R.string.prefer_limit_title_rez_key), 3)
|
||||||
limitTitle = settingsManager.getInt(ctx.getString(R.string.prefer_limit_title_key), 0)
|
limitTitle = settingsManager.getInt(ctx.getString(R.string.prefer_limit_title_key), 0)
|
||||||
updateForcedEncoding(ctx)
|
updateForcedEncoding(ctx)
|
||||||
|
|
||||||
|
filterSubByLang = settingsManager.getBoolean(getString(R.string.filter_sub_lang_key), false)
|
||||||
|
if (filterSubByLang) {
|
||||||
|
val langFromPrefMedia = settingsManager.getStringSet(
|
||||||
|
this.getString(R.string.provider_lang_key),
|
||||||
|
mutableSetOf("en")
|
||||||
|
)
|
||||||
|
langFilterList = langFromPrefMedia?.mapNotNull {
|
||||||
|
fromTwoLettersToLanguage(it)?.lowercase() ?: return@mapNotNull null
|
||||||
|
} ?: listOf()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unwrapBundle(savedInstanceState)
|
unwrapBundle(savedInstanceState)
|
||||||
|
@ -1062,7 +1075,18 @@ class GeneratorPlayer : FullScreenPlayer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
observe(viewModel.currentSubs) { set ->
|
observe(viewModel.currentSubs) { set ->
|
||||||
|
val setOfSub = mutableSetOf<SubtitleData>()
|
||||||
|
if (langFilterList.isNotEmpty() && filterSubByLang) {
|
||||||
|
Log.i("subfilter", "Filtering subtitle")
|
||||||
|
langFilterList.forEach { lang ->
|
||||||
|
Log.i("subfilter", "Lang: $lang")
|
||||||
|
setOfSub += set.filter { it.name.contains(lang, ignoreCase = true) }
|
||||||
|
.toMutableSet()
|
||||||
|
}
|
||||||
|
currentSubs = setOfSub
|
||||||
|
} else {
|
||||||
currentSubs = set
|
currentSubs = set
|
||||||
|
}
|
||||||
player.setActiveSubtitles(set)
|
player.setActiveSubtitles(set)
|
||||||
|
|
||||||
autoSelectSubtitles()
|
autoSelectSubtitles()
|
||||||
|
|
|
@ -16,6 +16,7 @@ import android.widget.Toast
|
||||||
import androidx.annotation.FontRes
|
import androidx.annotation.FontRes
|
||||||
import androidx.core.content.res.ResourcesCompat
|
import androidx.core.content.res.ResourcesCompat
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
|
import androidx.preference.PreferenceManager
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty
|
import com.fasterxml.jackson.annotation.JsonProperty
|
||||||
import com.google.android.exoplayer2.text.Cue
|
import com.google.android.exoplayer2.text.Cue
|
||||||
import com.google.android.exoplayer2.ui.CaptionStyleCompat
|
import com.google.android.exoplayer2.ui.CaptionStyleCompat
|
||||||
|
@ -415,6 +416,20 @@ class SubtitlesFragment : Fragment() {
|
||||||
return@setOnLongClickListener true
|
return@setOnLongClickListener true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Fetch current value from preference
|
||||||
|
context?.let { ctx ->
|
||||||
|
subtitles_filter_sub_lang?.isChecked = PreferenceManager.getDefaultSharedPreferences(ctx)
|
||||||
|
.getBoolean(getString(R.string.filter_sub_lang_key), false)
|
||||||
|
}
|
||||||
|
subtitles_filter_sub_lang?.setOnCheckedChangeListener { _, b ->
|
||||||
|
context?.let { ctx ->
|
||||||
|
PreferenceManager.getDefaultSharedPreferences(ctx)
|
||||||
|
.edit()
|
||||||
|
.putBoolean(getString(R.string.filter_sub_lang_key), b)
|
||||||
|
.apply()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
subs_font.setFocusableInTv()
|
subs_font.setFocusableInTv()
|
||||||
subs_font.setOnClickListener { textView ->
|
subs_font.setOnClickListener { textView ->
|
||||||
val fontTypes = listOf(
|
val fontTypes = listOf(
|
||||||
|
|
|
@ -169,6 +169,19 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" />
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
|
<com.google.android.material.switchmaterial.SwitchMaterial
|
||||||
|
android:nextFocusUp="@id/subtitles_remove_captions"
|
||||||
|
android:nextFocusDown="@id/apply_btt"
|
||||||
|
android:nextFocusLeft="@id/apply_btt"
|
||||||
|
android:nextFocusRight="@id/cancel_btt"
|
||||||
|
android:fontFamily="@font/google_sans"
|
||||||
|
style="@style/SettingsItem"
|
||||||
|
app:drawableEndCompat="@null"
|
||||||
|
android:id="@+id/subtitles_filter_sub_lang"
|
||||||
|
android:text="@string/subtitles_filter_lang"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|
|
@ -53,6 +53,7 @@
|
||||||
<string name="subtitles_encoding_key" translatable="false">subtitles_encoding_key</string>
|
<string name="subtitles_encoding_key" translatable="false">subtitles_encoding_key</string>
|
||||||
<string name="override_site_key" translatable="false">override_site_key</string>
|
<string name="override_site_key" translatable="false">override_site_key</string>
|
||||||
<string name="redo_setup_key" translatable="false">redo_setup_key</string>
|
<string name="redo_setup_key" translatable="false">redo_setup_key</string>
|
||||||
|
<string name="filter_sub_lang_key" translatable="false">filter_sub_lang_key</string>
|
||||||
|
|
||||||
<!-- FORMAT MIGHT TRANSLATE, WILL CAUSE CRASH IF APPLIED WRONG -->
|
<!-- FORMAT MIGHT TRANSLATE, WILL CAUSE CRASH IF APPLIED WRONG -->
|
||||||
<string name="extra_info_format" formatted="true" translatable="false">%d %s | %sMB</string>
|
<string name="extra_info_format" formatted="true" translatable="false">%d %s | %sMB</string>
|
||||||
|
@ -561,6 +562,7 @@
|
||||||
<string name="error">Error</string>
|
<string name="error">Error</string>
|
||||||
<string name="subtitles_remove_captions">Remove closed captions from subtitles</string>
|
<string name="subtitles_remove_captions">Remove closed captions from subtitles</string>
|
||||||
<string name="subtitles_remove_bloat">Remove bloat from subtitles</string>
|
<string name="subtitles_remove_bloat">Remove bloat from subtitles</string>
|
||||||
|
<string name="subtitles_filter_lang">Filter by preferred media language</string>
|
||||||
<string name="extras">Extras</string>
|
<string name="extras">Extras</string>
|
||||||
<string name="trailer">Trailer</string>
|
<string name="trailer">Trailer</string>
|
||||||
<string name="network_adress_example">Link to stream</string>
|
<string name="network_adress_example">Link to stream</string>
|
||||||
|
|
Loading…
Reference in a new issue