Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,19 @@ import androidx.media3.ui.PlayerNotificationManager.MediaDescriptionAdapter
import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.lagradost.cloudstream3.amap
import com.lagradost.cloudstream3.APIHolder.getApiFromNameNull
import com.lagradost.cloudstream3.CloudStreamApp
import com.lagradost.cloudstream3.CloudStreamApp.Companion.setKey
import com.lagradost.cloudstream3.CommonActivity.showToast
import com.lagradost.cloudstream3.LoadResponse
import com.lagradost.cloudstream3.LoadResponse.Companion.getAniListId
import com.lagradost.cloudstream3.LoadResponse.Companion.getImdbId
import com.lagradost.cloudstream3.LoadResponse.Companion.getMalId
import com.lagradost.cloudstream3.LoadResponse.Companion.getTMDbId
import com.lagradost.cloudstream3.MainActivity
import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.TvType
import com.lagradost.cloudstream3.amap
import com.lagradost.cloudstream3.databinding.DialogOnlineSubtitlesBinding
import com.lagradost.cloudstream3.databinding.FragmentPlayerBinding
import com.lagradost.cloudstream3.databinding.PlayerSelectSourceAndSubsBinding
Expand All @@ -58,22 +66,14 @@ import com.lagradost.cloudstream3.isAnimeOp
import com.lagradost.cloudstream3.isEpisodeBased
import com.lagradost.cloudstream3.isLiveStream
import com.lagradost.cloudstream3.isMovieType
import com.lagradost.cloudstream3.LoadResponse
import com.lagradost.cloudstream3.LoadResponse.Companion.getAniListId
import com.lagradost.cloudstream3.LoadResponse.Companion.getImdbId
import com.lagradost.cloudstream3.LoadResponse.Companion.getMalId
import com.lagradost.cloudstream3.LoadResponse.Companion.getTMDbId
import com.lagradost.cloudstream3.MainActivity
import com.lagradost.cloudstream3.mvvm.Resource
import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.mvvm.observe
import com.lagradost.cloudstream3.mvvm.observeNullable
import com.lagradost.cloudstream3.mvvm.Resource
import com.lagradost.cloudstream3.mvvm.safe
import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.subtitles.AbstractSubtitleEntities
import com.lagradost.cloudstream3.subtitles.AbstractSubtitleEntities.SubtitleSearch
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.subtitleProviders
import com.lagradost.cloudstream3.TvType
import com.lagradost.cloudstream3.ui.download.DownloadButtonSetup
import com.lagradost.cloudstream3.ui.player.CS3IPlayer.Companion.preferredAudioTrackLanguage
import com.lagradost.cloudstream3.ui.player.CustomDecoder.Companion.updateForcedEncoding
Expand All @@ -86,13 +86,12 @@ import com.lagradost.cloudstream3.ui.result.FOCUS_SELF
import com.lagradost.cloudstream3.ui.result.ResultEpisode
import com.lagradost.cloudstream3.ui.result.ResultFragment
import com.lagradost.cloudstream3.ui.result.ResultViewModel2
import com.lagradost.cloudstream3.ui.result.setLinearListLayout
import com.lagradost.cloudstream3.ui.result.SyncViewModel
import com.lagradost.cloudstream3.ui.result.VideoWatchState
import com.lagradost.cloudstream3.ui.result.setLinearListLayout
import com.lagradost.cloudstream3.ui.settings.Globals.EMULATOR
import com.lagradost.cloudstream3.ui.settings.Globals.isLayout
import com.lagradost.cloudstream3.ui.settings.Globals.PHONE
import com.lagradost.cloudstream3.ui.settings.Globals.TV
import com.lagradost.cloudstream3.ui.settings.Globals.isLayout
import com.lagradost.cloudstream3.ui.subtitles.SUBTITLE_AUTO_SELECT_KEY
import com.lagradost.cloudstream3.ui.subtitles.SubtitlesFragment
import com.lagradost.cloudstream3.ui.subtitles.SubtitlesFragment.Companion.getAutoSelectLanguageTagIETF
Expand All @@ -102,19 +101,14 @@ import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
import com.lagradost.cloudstream3.utils.Coroutines.runOnMainThread
import com.lagradost.cloudstream3.utils.DataStoreHelper
import com.lagradost.cloudstream3.utils.DataStoreHelper.getViewPos
import com.lagradost.cloudstream3.utils.DataStoreHelper.setVideoWatchState
import com.lagradost.cloudstream3.utils.EpisodeSkip
import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.ExtractorLinkType
import com.lagradost.cloudstream3.utils.Qualities
import com.lagradost.cloudstream3.utils.setText
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showDialog
import com.lagradost.cloudstream3.utils.SubtitleHelper.fromCodeToLangTagIETF
import com.lagradost.cloudstream3.utils.SubtitleHelper.fromLanguageToTagIETF
import com.lagradost.cloudstream3.utils.SubtitleHelper.fromTagToEnglishLanguageName
import com.lagradost.cloudstream3.utils.SubtitleHelper.fromTagToLanguageName
import com.lagradost.cloudstream3.utils.SubtitleHelper.languages
import com.lagradost.cloudstream3.utils.txt
import com.lagradost.cloudstream3.utils.UIHelper.clipboardHelper
import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
Expand All @@ -123,14 +117,16 @@ import com.lagradost.cloudstream3.utils.UIHelper.hideSystemUI
import com.lagradost.cloudstream3.utils.UIHelper.popCurrentPage
import com.lagradost.cloudstream3.utils.UIHelper.toPx
import com.lagradost.cloudstream3.utils.VideoDownloadManager.getImageBitmapFromUrl
import com.lagradost.cloudstream3.utils.setText
import com.lagradost.cloudstream3.utils.txt
import com.lagradost.safefile.SafeFile
import java.io.Serializable
import java.util.Calendar
import kotlin.math.abs
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import java.io.Serializable
import java.util.Calendar
import kotlin.math.abs

@OptIn(UnstableApi::class)
class GeneratorPlayer : FullScreenPlayer() {
Expand All @@ -154,8 +150,11 @@ class GeneratorPlayer : FullScreenPlayer() {
}


private var titleRez = 3
private var limitTitle = 0
private var showTitle = false
private var showName = false
private var showResolution = false
private var showMediaInfo = false

private lateinit var viewModel: PlayerGeneratorViewModel //by activityViewModels()
private lateinit var sync: SyncViewModel
Expand Down Expand Up @@ -230,7 +229,7 @@ class GeneratorPlayer : FullScreenPlayer() {
}

private fun getPos(): Long {
val durPos = DataStoreHelper.getViewPos(viewModel.getId()) ?: return 0L
val durPos = getViewPos(viewModel.getId()) ?: return 0L
if (durPos.duration == 0L) return 0L
if (durPos.position * 100L / durPos.duration > 95L) {
return 0L
Expand Down Expand Up @@ -1452,9 +1451,7 @@ class GeneratorPlayer : FullScreenPlayer() {
track.formatIndex == tracks.currentAudioTrack?.formatIndex
}.coerceAtLeast(0)

val audioArrayAdapter =
ArrayAdapter<String>(ctx, R.layout.sort_bottom_single_choice)

val audioArrayAdapter = ArrayAdapter<String>(ctx, R.layout.sort_bottom_single_choice)

audioArrayAdapter.addAll(currentAudioTracks.mapIndexed { index, track ->
val language = track.language?.let { fromTagToLanguageName(it) ?: it }
Expand All @@ -1475,6 +1472,7 @@ class GeneratorPlayer : FullScreenPlayer() {
else -> mimeType.substringAfter("/")
}
} ?: "codec?"


val channels: Int = track.channelCount ?: 0
val channelConfig = when (channels) {
Expand All @@ -1484,6 +1482,13 @@ class GeneratorPlayer : FullScreenPlayer() {
8 -> "7.1"
else -> "${channels}Ch"
}

listOfNotNull(
"[$index]",
language.replaceFirstChar { it.uppercaseChar() },
codec.uppercase(),
channelConfig.replaceFirstChar { it.uppercaseChar() }
).joinToString("")

"[$index] $language $codec $channelConfig"
})
Expand Down Expand Up @@ -1828,45 +1833,32 @@ class GeneratorPlayer : FullScreenPlayer() {

@SuppressLint("SetTextI18n")
fun setPlayerDimen(widthHeight: Pair<Int, Int>?) {
val extra = widthHeight?.let { (w, h) -> "${w}x${h}" } ?: ""
val source = currentSelectedLink?.first?.name ?: currentSelectedLink?.second?.name ?: "NULL"
val headerName = getHeaderName().orEmpty()


val title = when (titleRez) {
0 -> ""
1 -> extra
2 -> source
3 -> "$source${
if (source.isBlank()) {
""
} else {
" - "
}
}$extra"
val resolution = widthHeight?.let { "${it.first}x${it.second}" }
val name = currentSelectedLink?.first?.name ?: currentSelectedLink?.second?.name
val title = getHeaderName()

4 -> headerName
5 -> "$headerName${
if (headerName.isBlank()) {
""
} else {
" - "
}
}$extra"
val result = listOfNotNull(
title?.takeIf { showTitle && it.isNotBlank() },
name?.takeIf { showName && it.isNotBlank() },
resolution?.takeIf { showResolution && it.isNotBlank() },
).joinToString(" - ")

else -> ""
}
playerBinding?.playerVideoTitleRez?.apply {
text = title
isVisible = title.isNotBlank()
text = result
isVisible = result.isNotBlank()
}
}

private fun updatePlayerInfo() {
val tracks = player.getVideoTracks()

val videoTrack = tracks.currentVideoTrack
val audioTrack = tracks.currentAudioTrack

val ctx = context ?: return
val prefs = PreferenceManager.getDefaultSharedPreferences(ctx)
showMediaInfo = prefs.getBoolean(ctx.getString(R.string.show_media_info_key), false)

val videoCodec = videoTrack?.sampleMimeType?.substringAfterLast('/')?.uppercase()
val audioCodec = audioTrack?.sampleMimeType?.substringAfterLast('/')?.uppercase()
val language = listOfNotNull(
Expand All @@ -1878,7 +1870,7 @@ class GeneratorPlayer : FullScreenPlayer() {

playerBinding?.playerVideoInfo?.apply {
text = stats
isVisible = stats.isNotBlank()
isVisible = showMediaInfo && stats.isNotBlank()
}
}

Expand Down Expand Up @@ -2074,8 +2066,10 @@ class GeneratorPlayer : FullScreenPlayer() {

context?.let { ctx ->
val settingsManager = PreferenceManager.getDefaultSharedPreferences(ctx)
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)
showName = settingsManager.getBoolean(ctx.getString(R.string.show_name_key), true)
showResolution = settingsManager.getBoolean(ctx.getString(R.string.show_resolution_key), true)
showMediaInfo = settingsManager.getBoolean(ctx.getString(R.string.show_media_info_key), false)
limitTitle = settingsManager.getInt(ctx.getString(R.string.prefer_title_limit_key), 0)
updateForcedEncoding(ctx)
filterSubByLang =
settingsManager.getBoolean(getString(R.string.filter_sub_lang_key), false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.lagradost.cloudstream3.ui.subtitles.SubtitlesFragment
import com.lagradost.cloudstream3.utils.Qualities
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showDialog
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showMultiDialog
import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard

class SettingsPlayer : BasePreferenceFragmentCompat() {
Expand Down Expand Up @@ -111,23 +112,39 @@ class SettingsPlayer : BasePreferenceFragmentCompat() {
return@setOnPreferenceClickListener true
}

getPref(R.string.prefer_limit_title_rez_key)?.setOnPreferenceClickListener {
val prefNames = resources.getStringArray(R.array.limit_title_rez_pref_names)
val prefValues = resources.getIntArray(R.array.limit_title_rez_pref_values)
val current = settingsManager.getInt(getString(R.string.prefer_limit_title_rez_key), 3)
getPref(R.string.prefer_limit_show_player_info)?.setOnPreferenceClickListener {
val ctx = context ?: return@setOnPreferenceClickListener false

activity?.showBottomDialog(
val prefNames = resources.getStringArray(R.array.title_info_pref_names)
val keys = resources.getStringArray(R.array.title_info_pref_values)

// Player defaults
val playerDefaults = mapOf(
ctx.getString(R.string.show_name_key) to true,
ctx.getString(R.string.show_resolution_key) to true,
ctx.getString(R.string.show_media_info_key) to false
)

val selectedIndices = keys.map { key ->
settingsManager.getBoolean(key, playerDefaults[key] ?: false)
}.mapIndexedNotNull { index, enabled ->
if (enabled) index else null
}

activity?.showMultiDialog(
prefNames.toList(),
prefValues.indexOf(current),
selectedIndices,
getString(R.string.limit_title_rez),
true,
{}
) {
) { selected ->
settingsManager.edit {
putInt(getString(R.string.prefer_limit_title_rez_key), prefValues[it])
for ((index, key) in keys.withIndex()) {
putBoolean(key, selected.contains(index))
}
}
}
return@setOnPreferenceClickListener true

true
}

getPref(R.string.hide_player_control_names_key)?.hideOn(TV)
Expand Down
21 changes: 8 additions & 13 deletions app/src/main/res/values-b+es/array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,19 @@
<item>@id/cast_button_type_forward_30_seconds</item>
</array>

<array name="limit_title_rez_pref_names">
<item>@string/resolution_and_name</item>
<item>@string/name</item>
<item>@string/resolution_and_title</item>
<item>@string/title</item>
<array name="title_info_pref_names">
<item>@string/source_name</item>
<item>@string/resolution</item>
<item>@string/none</item>
<item>@string/video_info</item>
</array>

<array name="limit_title_rez_pref_values">
<item>5</item>
<item>4</item>
<item>3</item>
<item>2</item>
<item>1</item>
<item>0</item>
<array name="title_info_pref_values">
<item>@string/show_name_key</item>
<item>@string/show_resolution_key</item>
<item>@string/show_media_info_key</item>
</array>


<array name="limit_title_pref_names">
<item>@string/none</item>
<item>16 caracteres</item>
Expand Down
24 changes: 10 additions & 14 deletions app/src/main/res/values-b+pl/array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,20 @@
</string-array>


<array name="limit_title_rez_pref_names">
<item>@string/resolution_and_name</item>
<item>@string/name</item>
<item>@string/resolution_and_title</item>
<item>@string/title</item>
<array name="title_info_pref_names">
<item>@string/source_name</item>
<item>@string/resolution</item>
<item>@string/none</item>
<item>@string/video_info</item>
</array>

<array name="limit_title_rez_pref_values">
<item>5</item>
<item>4</item>
<item>3</item>
<item>2</item>
<item>1</item>
<item>0</item>
<array name="title_info_pref_values">
<item>@string/show_name_key</item>
<item>@string/show_resolution_key</item>
<item>@string/show_media_info_key</item>
</array>




<array name="limit_title_pref_names">
<item>@string/none</item>
<item>16 znaków</item>
Expand Down
21 changes: 8 additions & 13 deletions app/src/main/res/values-b+tr/array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,19 @@
<item>8</item>
</array>

<array name="limit_title_rez_pref_names">
<item>@string/resolution_and_name</item>
<item>@string/name</item>
<item>@string/resolution_and_title</item>
<item>@string/title</item>
<array name="title_info_pref_names">
<item>@string/source_name</item>
<item>@string/resolution</item>
<item>@string/none</item>
<item>@string/video_info</item>
</array>

<array name="limit_title_rez_pref_values">
<item>5</item>
<item>4</item>
<item>3</item>
<item>2</item>
<item>1</item>
<item>0</item>
<array name="title_info_pref_values">
<item>@string/show_name_key</item>
<item>@string/show_resolution_key</item>
<item>@string/show_media_info_key</item>
</array>


<array name="limit_title_pref_names">
<item>@string/none</item>
<item>16 karakter</item>
Expand Down
Loading