mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Save selected subtitle language (#765)
This commit is contained in:
parent
5bf2b4ead2
commit
e11d36aed8
4 changed files with 44 additions and 12 deletions
|
@ -1014,7 +1014,8 @@ class CS3IPlayer : IPlayer {
|
||||||
format.id!!,
|
format.id!!,
|
||||||
SubtitleOrigin.EMBEDDED_IN_VIDEO,
|
SubtitleOrigin.EMBEDDED_IN_VIDEO,
|
||||||
format.sampleMimeType ?: MimeTypes.APPLICATION_SUBRIP,
|
format.sampleMimeType ?: MimeTypes.APPLICATION_SUBRIP,
|
||||||
emptyMap()
|
emptyMap(),
|
||||||
|
format.language
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -100,7 +100,8 @@ class DownloadFileGenerator(
|
||||||
uri.toString(),
|
uri.toString(),
|
||||||
SubtitleOrigin.DOWNLOADED_FILE,
|
SubtitleOrigin.DOWNLOADED_FILE,
|
||||||
name.toSubtitleMimeType(),
|
name.toSubtitleMimeType(),
|
||||||
emptyMap()
|
emptyMap(),
|
||||||
|
null
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import androidx.media3.common.Format.NO_VALUE
|
||||||
import androidx.media3.common.MimeTypes
|
import androidx.media3.common.MimeTypes
|
||||||
import com.lagradost.cloudstream3.*
|
import com.lagradost.cloudstream3.*
|
||||||
import com.lagradost.cloudstream3.APIHolder.getApiFromNameNull
|
import com.lagradost.cloudstream3.APIHolder.getApiFromNameNull
|
||||||
|
import com.lagradost.cloudstream3.AcraApplication.Companion.setKey
|
||||||
import com.lagradost.cloudstream3.CommonActivity.showToast
|
import com.lagradost.cloudstream3.CommonActivity.showToast
|
||||||
import com.lagradost.cloudstream3.databinding.DialogOnlineSubtitlesBinding
|
import com.lagradost.cloudstream3.databinding.DialogOnlineSubtitlesBinding
|
||||||
import com.lagradost.cloudstream3.databinding.FragmentPlayerBinding
|
import com.lagradost.cloudstream3.databinding.FragmentPlayerBinding
|
||||||
|
@ -38,6 +39,7 @@ import com.lagradost.cloudstream3.ui.player.source_priority.QualityDataHelper
|
||||||
import com.lagradost.cloudstream3.ui.player.source_priority.QualityProfileDialog
|
import com.lagradost.cloudstream3.ui.player.source_priority.QualityProfileDialog
|
||||||
import com.lagradost.cloudstream3.ui.result.*
|
import com.lagradost.cloudstream3.ui.result.*
|
||||||
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings
|
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings
|
||||||
|
import com.lagradost.cloudstream3.ui.subtitles.SUBTITLE_AUTO_SELECT_KEY
|
||||||
import com.lagradost.cloudstream3.ui.subtitles.SubtitlesFragment.Companion.getAutoSelectLanguageISO639_1
|
import com.lagradost.cloudstream3.ui.subtitles.SubtitlesFragment.Companion.getAutoSelectLanguageISO639_1
|
||||||
import com.lagradost.cloudstream3.utils.*
|
import com.lagradost.cloudstream3.utils.*
|
||||||
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
|
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
|
||||||
|
@ -100,10 +102,33 @@ class GeneratorPlayer : FullScreenPlayer() {
|
||||||
binding?.playerLoadingOverlay?.isVisible = true
|
binding?.playerLoadingOverlay?.isVisible = true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setSubtitles(sub: SubtitleData?): Boolean {
|
private fun setSubtitles(subtitle: SubtitleData?): Boolean {
|
||||||
currentSelectedSubtitles = sub
|
// If subtitle is changed -> Save the language
|
||||||
//Log.i(TAG, "setSubtitles = $sub")
|
if (subtitle != currentSelectedSubtitles) {
|
||||||
return player.setPreferredSubtitles(sub)
|
val subtitleLanguage639 = if (subtitle == null) {
|
||||||
|
// "" is No Subtitles
|
||||||
|
""
|
||||||
|
} else if (subtitle.languageCode != null) {
|
||||||
|
// Could be "English 4" which is why it is trimmed.
|
||||||
|
val trimmedLanguage = subtitle.languageCode.replace(Regex("\\d"), "").trim()
|
||||||
|
|
||||||
|
languages.firstOrNull { language ->
|
||||||
|
language.languageName.equals(trimmedLanguage, ignoreCase = true) ||
|
||||||
|
language.ISO_639_1 == subtitle.languageCode
|
||||||
|
}?.ISO_639_1
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
|
if (subtitleLanguage639 != null) {
|
||||||
|
setKey(SUBTITLE_AUTO_SELECT_KEY, subtitleLanguage639)
|
||||||
|
preferredAutoSelectSubtitles = subtitleLanguage639
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
currentSelectedSubtitles = subtitle
|
||||||
|
//Log.i(TAG, "setSubtitles = $subtitle")
|
||||||
|
return player.setPreferredSubtitles(subtitle)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun embeddedSubtitlesFetched(subtitles: List<SubtitleData>) {
|
override fun embeddedSubtitlesFetched(subtitles: List<SubtitleData>) {
|
||||||
|
@ -448,7 +473,8 @@ class GeneratorPlayer : FullScreenPlayer() {
|
||||||
url = url,
|
url = url,
|
||||||
origin = SubtitleOrigin.URL,
|
origin = SubtitleOrigin.URL,
|
||||||
mimeType = url.toSubtitleMimeType(),
|
mimeType = url.toSubtitleMimeType(),
|
||||||
headers = currentSubtitle.headers
|
headers = currentSubtitle.headers,
|
||||||
|
currentSubtitle.lang
|
||||||
)
|
)
|
||||||
runOnMainThread {
|
runOnMainThread {
|
||||||
addAndSelectSubtitles(subtitle)
|
addAndSelectSubtitles(subtitle)
|
||||||
|
@ -536,7 +562,8 @@ class GeneratorPlayer : FullScreenPlayer() {
|
||||||
uri.toString(),
|
uri.toString(),
|
||||||
SubtitleOrigin.DOWNLOADED_FILE,
|
SubtitleOrigin.DOWNLOADED_FILE,
|
||||||
name.toSubtitleMimeType(),
|
name.toSubtitleMimeType(),
|
||||||
emptyMap()
|
emptyMap(),
|
||||||
|
null
|
||||||
)
|
)
|
||||||
|
|
||||||
addAndSelectSubtitles(subtitleData)
|
addAndSelectSubtitles(subtitleData)
|
||||||
|
|
|
@ -30,13 +30,15 @@ enum class SubtitleOrigin {
|
||||||
* @param name To be displayed in the player
|
* @param name To be displayed in the player
|
||||||
* @param url Url for the subtitle, when EMBEDDED_IN_VIDEO this variable is used as the real backend id
|
* @param url Url for the subtitle, when EMBEDDED_IN_VIDEO this variable is used as the real backend id
|
||||||
* @param headers if empty it will use the base onlineDataSource headers else only the specified headers
|
* @param headers if empty it will use the base onlineDataSource headers else only the specified headers
|
||||||
|
* @param languageCode Not guaranteed to follow any standard. Could be something like "English 4" or "en".
|
||||||
* */
|
* */
|
||||||
data class SubtitleData(
|
data class SubtitleData(
|
||||||
val name: String,
|
val name: String,
|
||||||
val url: String,
|
val url: String,
|
||||||
val origin: SubtitleOrigin,
|
val origin: SubtitleOrigin,
|
||||||
val mimeType: String,
|
val mimeType: String,
|
||||||
val headers: Map<String, String>
|
val headers: Map<String, String>,
|
||||||
|
val languageCode: String?
|
||||||
) {
|
) {
|
||||||
/** Internal ID for exoplayer, unique for each link*/
|
/** Internal ID for exoplayer, unique for each link*/
|
||||||
fun getId(): String {
|
fun getId(): String {
|
||||||
|
@ -80,7 +82,8 @@ class PlayerSubtitleHelper {
|
||||||
url = subtitleFile.url,
|
url = subtitleFile.url,
|
||||||
origin = SubtitleOrigin.URL,
|
origin = SubtitleOrigin.URL,
|
||||||
mimeType = subtitleFile.url.toSubtitleMimeType(),
|
mimeType = subtitleFile.url.toSubtitleMimeType(),
|
||||||
headers = emptyMap()
|
headers = emptyMap(),
|
||||||
|
languageCode = subtitleFile.lang
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue