-
Notifications
You must be signed in to change notification settings - Fork 1k
fix: group subtitles by language #3127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
refirestream
wants to merge
1
commit into
recloudstream:master
Choose a base branch
from
Sarlay:fix/subtitle-language-grouping
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+28
−15
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,7 @@ import androidx.preference.PreferenceManager | |
| import androidx.recyclerview.widget.LinearLayoutManager | ||
| import androidx.recyclerview.widget.RecyclerView | ||
| import com.lagradost.cloudstream3.APIHolder.getApiFromNameNull | ||
| import com.lagradost.cloudstream3.AllLanguagesName | ||
| import com.lagradost.cloudstream3.CloudStreamApp | ||
| import com.lagradost.cloudstream3.CloudStreamApp.Companion.setKey | ||
| import com.lagradost.cloudstream3.CommonActivity.showToast | ||
|
|
@@ -101,6 +102,7 @@ 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 | ||
| import com.lagradost.cloudstream3.utils.AppContextUtils.getApiProviderLangSettings | ||
| import com.lagradost.cloudstream3.utils.AppContextUtils.getShortSeasonText | ||
| import com.lagradost.cloudstream3.utils.AppContextUtils.html | ||
| import com.lagradost.cloudstream3.utils.AppContextUtils.sortSubs | ||
|
|
@@ -112,7 +114,7 @@ import com.lagradost.cloudstream3.utils.ExtractorLink | |
| import com.lagradost.cloudstream3.utils.ExtractorLinkType | ||
| import com.lagradost.cloudstream3.utils.Qualities | ||
| import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showDialog | ||
| import com.lagradost.cloudstream3.utils.SubtitleHelper.fromTagToEnglishLanguageName | ||
| import com.lagradost.cloudstream3.utils.SubtitleHelper.fromCodeToLangTagIETF | ||
| import com.lagradost.cloudstream3.utils.SubtitleHelper.fromTagToLanguageName | ||
| import com.lagradost.cloudstream3.utils.SubtitleHelper.languages | ||
| import com.lagradost.cloudstream3.utils.UIHelper.clipboardHelper | ||
|
|
@@ -1195,20 +1197,26 @@ class GeneratorPlayer : FullScreenPlayer() { | |
| ArrayAdapter<Spanned>(ctx, R.layout.sort_bottom_single_choice) | ||
| subsArrayAdapter.add(ctx.getString(R.string.no_subtitles).html()) | ||
|
|
||
| val unknownGroupName = ctx.getString(R.string.subtitles_group_unknown) | ||
| fun groupName(sub: SubtitleData): String { | ||
| return fromTagToLanguageName(sub.getIETF_tag())?.takeIf { it.isNotBlank() } | ||
| ?: unknownGroupName | ||
| } | ||
|
|
||
| val subtitlesGrouped = | ||
| currentSubtitles.groupBy { it.originalName }.map { (key, value) -> | ||
| currentSubtitles.groupBy { groupName(it) }.map { (key, value) -> | ||
| key to value.sortedBy { it.nameSuffix.toIntOrNull() ?: 0 } | ||
| }.toMap() | ||
| val subtitlesGroupedList = subtitlesGrouped.entries.toList() | ||
|
|
||
| val subtitles = subtitlesGrouped.map { it.key.html() } | ||
|
|
||
| val subtitleGroupIndexStart = | ||
| subtitlesGrouped.keys.indexOf(currentSelectedSubtitles?.originalName) + 1 | ||
| subtitlesGrouped.keys.indexOf(currentSelectedSubtitles?.let { groupName(it) }) + 1 | ||
| var subtitleGroupIndex = subtitleGroupIndexStart | ||
|
|
||
| val subtitleOptionIndexStart = | ||
| subtitlesGrouped[currentSelectedSubtitles?.originalName]?.indexOfFirst { it.nameSuffix == currentSelectedSubtitles?.nameSuffix } | ||
| subtitlesGrouped[currentSelectedSubtitles?.let { groupName(it) }]?.indexOfFirst { it.nameSuffix == currentSelectedSubtitles?.nameSuffix } | ||
| ?: 0 | ||
| var subtitleOptionIndex = subtitleOptionIndexStart | ||
|
|
||
|
|
@@ -1232,8 +1240,8 @@ class GeneratorPlayer : FullScreenPlayer() { | |
| val subtitleOptions = | ||
| subtitlesGroupedList | ||
| .getOrNull(subtitleGroupIndex - 1)?.value?.map { subtitle -> | ||
| val nameSuffix = subtitle.nameSuffix.html() | ||
| nameSuffix.ifBlank { | ||
| val label = subtitle.originalName.html() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This completely breaks the subtitle suffix system and makes it very confusing to precisely select between different subtitles of the same language. Is there any reason for this change? |
||
| label.ifBlank { | ||
| when (subtitle.origin) { | ||
| SubtitleOrigin.URL -> txt(R.string.subtitles_from_online) | ||
| SubtitleOrigin.DOWNLOADED_FILE -> txt(R.string.downloaded) | ||
|
|
@@ -2264,12 +2272,10 @@ class GeneratorPlayer : FullScreenPlayer() { | |
| viewModel.filterSubByLang = | ||
| settingsManager.getBoolean(getString(R.string.filter_sub_lang_key), false) | ||
| if (viewModel.filterSubByLang) { | ||
| val langFromPrefMedia = settingsManager.getStringSet( | ||
| this.getString(R.string.provider_lang_key), mutableSetOf("en") | ||
| ) | ||
| viewModel.langFilterList = langFromPrefMedia?.mapNotNull { | ||
| fromTagToEnglishLanguageName(it)?.lowercase() ?: return@mapNotNull null | ||
| } ?: listOf() | ||
| viewModel.langFilterList = ctx.getApiProviderLangSettings().map { tag -> | ||
| if (tag == AllLanguagesName) tag | ||
| else fromCodeToLangTagIETF(tag)?.lowercase() ?: tag.lowercase() | ||
| } | ||
| } | ||
|
|
||
| // Set up TV clock visibility | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer if you save the results to a list instead of calling this function since:
Calling the function again creates an assumption that the function will always return the same value, which can lead to bugs when refactoring in the future.
I dislike calling potentially expensive functions unnecessarily.