mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2026-05-16 04:52:39 +02:00
Add filters for video languages to resolve excessive sources
This commit is contained in:
@@ -387,7 +387,7 @@ class Settings : FragmentedStorageFileJson() {
|
||||
@DropdownFieldOptionsId(R.array.audio_languages)
|
||||
var primaryLanguage: Int = 0;
|
||||
|
||||
fun getPrimaryLanguage(context: Context): String? {
|
||||
fun getPrimaryLanguage(context: Context? = null): String? {
|
||||
return when(primaryLanguage) {
|
||||
0 -> "en";
|
||||
1 -> "es";
|
||||
|
||||
+49
-6
@@ -33,6 +33,7 @@ import android.widget.ImageButton
|
||||
import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.compose.ui.text.toLowerCase
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.media3.common.C
|
||||
@@ -2423,7 +2424,7 @@ class VideoDetailView : ConstraintLayout {
|
||||
|
||||
val doDedup = Settings.instance.playback.simplifySources;
|
||||
|
||||
val allLanguages = videoSources?.map { it.language } ?: listOf();
|
||||
val allLanguages = videoSources?.map { it.language }?.distinct() ?: listOf();
|
||||
val langResCombinations = if(videoSources != null) allLanguages.flatMap {
|
||||
lang -> videoSources
|
||||
.filter { v -> v.language == lang }
|
||||
@@ -2432,6 +2433,43 @@ class VideoDetailView : ConstraintLayout {
|
||||
.map { res -> Pair(res, lang) }
|
||||
} else listOf();
|
||||
|
||||
|
||||
Log.i(TAG, "Language count: ${allLanguages}");
|
||||
var videoSourceItems = mutableListOf<SlideUpMenuItem>();
|
||||
var selectedLanguage: String? = null;
|
||||
val languageFilters = if(allLanguages.filter { it != null }.count() > 1)
|
||||
SlideUpMenuButtonList(this.context, null, "language_filter", true).apply {
|
||||
var languageFilterLabels = allLanguages.filterNotNull().toList();
|
||||
val english = languageFilterLabels.find { it?.lowercase() == "en" };
|
||||
val originalLanguage = videoSources?.find { it.original == true }?.language;
|
||||
val primaryLanguage = Settings.instance.playback.getPrimaryLanguage();
|
||||
val hasPrimaryLanguage = videoSources?.any { it.language == primaryLanguage } ?: false;
|
||||
|
||||
if(english != null)
|
||||
languageFilterLabels = listOf(english).plus(languageFilterLabels.filter { it != english }).toList();
|
||||
if(primaryLanguage != null && languageFilterLabels.contains(primaryLanguage))
|
||||
languageFilterLabels = listOf(primaryLanguage).plus(languageFilterLabels.filter { it != primaryLanguage }).toList();
|
||||
if(originalLanguage != null)
|
||||
languageFilterLabels = listOf(originalLanguage).plus(languageFilterLabels.filter { it != originalLanguage }).toList();
|
||||
Log.i(TAG, "Language filtesr: ${languageFilterLabels.joinToString(", ")}");
|
||||
selectedLanguage = originalLanguage ?: (if(hasPrimaryLanguage) primaryLanguage else null);
|
||||
setButtons(languageFilterLabels, selectedLanguage);
|
||||
onClick.subscribe { selected ->
|
||||
setSelected(selected);
|
||||
|
||||
videoSourceItems.forEach {
|
||||
val item = it.itemTag;
|
||||
if(item is IVideoSource) {
|
||||
if(item.language == selected)
|
||||
it.visibility = View.VISIBLE;
|
||||
else
|
||||
it.visibility = View.GONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else null;
|
||||
|
||||
val bestVideoSources = if(doDedup && videoSources != null) (langResCombinations
|
||||
?.map { comb -> VideoHelper.selectBestVideoSource(videoSources.filter { comb.first == it.height * it.width && comb.second == it.language }, -1, FutoVideoPlayerBase.PREFERED_VIDEO_CONTAINERS) }
|
||||
?.plus(videoSources.filter { it is IHLSManifestSource || it is IDashManifestSource }))
|
||||
@@ -2539,11 +2577,10 @@ class VideoDetailView : ConstraintLayout {
|
||||
call = { _player.selectAudioTrack(it.bitrate) });
|
||||
}.toList().toTypedArray())
|
||||
else null,
|
||||
|
||||
if(languageFilters != null) languageFilters else null,
|
||||
if(bestVideoSources.isNotEmpty())
|
||||
SlideUpMenuGroup(this.context, context.getString(R.string.video), "video",
|
||||
*bestVideoSources
|
||||
.map {
|
||||
(bestVideoSources.map {
|
||||
val estSize = VideoHelper.estimateSourceSize(it);
|
||||
val prefix = if(estSize > 0) "±" + estSize.toHumanBytesSize() + " " else "";
|
||||
SlideUpMenuItem(this.context,
|
||||
@@ -2552,8 +2589,14 @@ class VideoDetailView : ConstraintLayout {
|
||||
if (it.width > 0 && it.height > 0) "${it.width}x${it.height}" else "",
|
||||
(prefix + it.codec.trim()).trim(),
|
||||
tag = it,
|
||||
call = { handleSelectVideoTrack(it) });
|
||||
}.toList().toTypedArray())
|
||||
call = { handleSelectVideoTrack(it) }).apply {
|
||||
videoSourceItems.add(this);
|
||||
if(selectedLanguage != null) {
|
||||
if(it.language != selectedLanguage)
|
||||
this.visibility = View.GONE;
|
||||
}
|
||||
};
|
||||
}).toList())
|
||||
else null,
|
||||
if(bestAudioSources.isNotEmpty())
|
||||
SlideUpMenuGroup(this.context, context.getString(R.string.audio), "audio",
|
||||
|
||||
+30
-6
@@ -11,6 +11,7 @@ import androidx.core.content.ContextCompat
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import com.futo.platformplayer.R
|
||||
import com.futo.platformplayer.constructs.Event1
|
||||
import com.futo.platformplayer.dp
|
||||
|
||||
class SlideUpMenuButtonList : LinearLayout {
|
||||
private val _root: LinearLayout;
|
||||
@@ -20,10 +21,16 @@ class SlideUpMenuButtonList : LinearLayout {
|
||||
var _activeText: String? = null;
|
||||
val id: String?
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet? = null, id: String? = null): super(context, attrs) {
|
||||
this.id = id
|
||||
val scrollable: Boolean;
|
||||
|
||||
LayoutInflater.from(context).inflate(R.layout.overlay_slide_up_menu_button_list, this, true);
|
||||
constructor(context: Context, attrs: AttributeSet? = null, id: String? = null, scrollable: Boolean = false): super(context, attrs) {
|
||||
this.id = id
|
||||
this.scrollable = scrollable ?: false;
|
||||
|
||||
LayoutInflater.from(context).inflate(
|
||||
if(!scrollable)
|
||||
R.layout.overlay_slide_up_menu_button_list
|
||||
else R.layout.overlay_slide_up_menu_button_list_scrollable, this, true);
|
||||
|
||||
_root = findViewById(R.id.root);
|
||||
}
|
||||
@@ -37,8 +44,9 @@ class SlideUpMenuButtonList : LinearLayout {
|
||||
buttons.clear();
|
||||
for (t in texts) {
|
||||
val button = LinearLayout(context);
|
||||
button.layoutParams = LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT).apply {
|
||||
weight = 1.0f;
|
||||
button.layoutParams = LinearLayout.LayoutParams(if(!scrollable) 0 else LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT).apply {
|
||||
if(!scrollable)
|
||||
weight = 1.0f;
|
||||
marginStart = marginLeft;
|
||||
marginEnd = marginRight;
|
||||
};
|
||||
@@ -49,7 +57,11 @@ class SlideUpMenuButtonList : LinearLayout {
|
||||
onClick.emit(t);
|
||||
};
|
||||
|
||||
button.setPadding(0, 0, 0, 0);
|
||||
val dp8 = 8.dp(resources)
|
||||
if(!scrollable)
|
||||
button.setPadding(0, 0, 0, 0);
|
||||
else
|
||||
button.setPadding(dp8, 0, dp8, 0);
|
||||
|
||||
val text = TextView(context);
|
||||
text.layoutParams = LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||
@@ -69,6 +81,18 @@ class SlideUpMenuButtonList : LinearLayout {
|
||||
fun setSelected(text: String) {
|
||||
buttons[_activeText]?.background = ContextCompat.getDrawable(context, R.drawable.background_slide_up_option);
|
||||
buttons[text]?.background = ContextCompat.getDrawable(context, R.drawable.background_slide_up_option_selected);
|
||||
|
||||
|
||||
val dp8 = 8.dp(resources)
|
||||
if(!scrollable) {
|
||||
buttons[text]?.setPadding(0, 0, 0, 0);
|
||||
buttons[_activeText]?.setPadding(0, 0, 0, 0);
|
||||
}
|
||||
else {
|
||||
buttons[text]?.setPadding(dp8, 0, dp8, 0);
|
||||
buttons[_activeText]?.setPadding(dp8, 0, dp8, 0);
|
||||
}
|
||||
|
||||
_activeText = text;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<HorizontalScrollView android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="35dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:id="@+id/root"
|
||||
android:orientation="horizontal"
|
||||
android:paddingStart="0dp"
|
||||
android:paddingEnd="0dp">
|
||||
|
||||
</LinearLayout>
|
||||
</HorizontalScrollView>
|
||||
Reference in New Issue
Block a user