From 1b129920f31b4bb2951fca9ec45ea915320328cb Mon Sep 17 00:00:00 2001 From: Blatzar <46196380+Blatzar@users.noreply.github.com> Date: Sat, 20 Aug 2022 18:08:39 +0200 Subject: [PATCH] Add OpenSubtitles support for Brazilian Portuguese --- .../syncproviders/providers/OpenSubtitlesApi.kt | 5 +++-- .../lagradost/cloudstream3/ui/player/GeneratorPlayer.kt | 5 +++-- .../com/lagradost/cloudstream3/utils/SubtitleHelper.kt | 9 +++++++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/OpenSubtitlesApi.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/OpenSubtitlesApi.kt index ed48ad04..bfa65f62 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/OpenSubtitlesApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/OpenSubtitlesApi.kt @@ -143,8 +143,9 @@ class OpenSubtitlesApi(index: Int) : InAppAuthAPIManager(index), AbstractSubApi /** * Some languages do not use the normal country codes on OpenSubtitles * */ - private val languageExceptions = mapOf( - "pt" to "pt-PT" + private val languageExceptions = mapOf( +// "pt" to "pt-PT", +// "pt" to "pt-BR" ) private fun fixLanguage(language: String?) : String? { return languageExceptions[language] ?: language diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt index d0500e83..c0c24f85 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt @@ -734,7 +734,7 @@ class GeneratorPlayer : FullScreenPlayer() { if ((currentMeta as? ResultEpisode)?.tvType?.isLiveStream() == true) return val (position, duration) = posDur - if(duration == 0L) return // idk how you achieved this, but div by zero crash + if (duration == 0L) return // idk how you achieved this, but div by zero crash viewModel.getId()?.let { DataStoreHelper.setViewPos(it, position, duration) @@ -1015,7 +1015,8 @@ class GeneratorPlayer : FullScreenPlayer() { limitTitle = settingsManager.getInt(ctx.getString(R.string.prefer_limit_title_key), 0) updateForcedEncoding(ctx) - filterSubByLang = settingsManager.getBoolean(getString(R.string.filter_sub_lang_key), false) + filterSubByLang = + settingsManager.getBoolean(getString(R.string.filter_sub_lang_key), false) if (filterSubByLang) { val langFromPrefMedia = settingsManager.getStringSet( this.getString(R.string.provider_lang_key), diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/SubtitleHelper.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/SubtitleHelper.kt index 13b72664..33f1b6ff 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/SubtitleHelper.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/SubtitleHelper.kt @@ -71,7 +71,8 @@ object SubtitleHelper { /** ISO_639_1 -> lang*/ fun fromTwoLettersToLanguage(input: String): String? { - if (input.length != 2) return null + // pr-BR + if (input.substringBefore("-").length != 2) return null if (ISO_639_1Map.isEmpty()) { initISO6391Map() } @@ -269,6 +270,8 @@ object SubtitleHelper { "pl" to "PL", "ps" to "AF", "pt" to "PT", + "pt-pt" to "PT", + "pt-br" to "BR", "rm" to "CH", "rn" to "BI", "ro" to "RO", @@ -452,7 +455,9 @@ object SubtitleHelper { Language639("Persian", "فارسی", "fa", "fas", "", "fas", ""), Language639("Polish", "język polski, polszczyzna", "pl", "pol", "pol", "pol", "pols"), Language639("Pashto", "پښتو", "ps", "pus", "pus", "pus", ""), - Language639("Portuguese", "português", "pt", "por", "por", "por", ""), + Language639("Portuguese", "português", "pt-pt", "por", "por", "por", ""), + // Addition to support Brazilian Portuguese properly, might break other things + Language639("Portuguese (Brazilian)", "português", "pt-br", "por", "por", "por", ""), Language639("Quechua", "Runa Simi, Kichwa", "qu", "que", "que", "que", ""), Language639("Romansh", "rumantsch grischun", "rm", "roh", "roh", "roh", ""), Language639("Kirundi", "Ikirundi", "rn", "run", "run", "run", ""),