1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-14 12:50:33 +01:00

added: caption language stem utility to support language variant conversion between videos.

This commit is contained in:
karyogamy 2022-04-08 18:21:30 -04:00
parent 724eac9168
commit 55fc3fc177
2 changed files with 20 additions and 2 deletions

View File

@ -46,6 +46,7 @@ import static org.schabi.newpipe.player.helper.PlayerHelper.MinimizeMode.MINIMIZ
import static org.schabi.newpipe.player.helper.PlayerHelper.MinimizeMode.MINIMIZE_ON_EXIT_MODE_NONE;
import static org.schabi.newpipe.player.helper.PlayerHelper.MinimizeMode.MINIMIZE_ON_EXIT_MODE_POPUP;
import static org.schabi.newpipe.player.helper.PlayerHelper.buildCloseOverlayLayoutParams;
import static org.schabi.newpipe.player.helper.PlayerHelper.captionLanguageStemOf;
import static org.schabi.newpipe.player.helper.PlayerHelper.formatSpeed;
import static org.schabi.newpipe.player.helper.PlayerHelper.getMinimizeOnExitAction;
import static org.schabi.newpipe.player.helper.PlayerHelper.getMinimumVideoHeight;
@ -3542,7 +3543,8 @@ public final class Player implements
// if a track of userPreferredLanguage is not found
// This means (auto-generated) will be resolved automatically.
trackSelector.setParameters(trackSelector.buildUponParameters()
.setPreferredTextLanguage(captionLanguage)
.setPreferredTextLanguages(captionLanguage,
captionLanguageStemOf(captionLanguage))
.setRendererDisabled(textRendererIndex, false));
prefs.edit().putString(context.getString(R.string.caption_user_set_key),
captionLanguage).apply();
@ -3563,7 +3565,8 @@ public final class Player implements
&& !selectedPreferredLanguages.contains(userPreferredLanguage)
&& textRendererIndex != RENDERER_UNAVAILABLE) {
trackSelector.setParameters(trackSelector.buildUponParameters()
.setPreferredTextLanguage(userPreferredLanguage)
.setPreferredTextLanguages(userPreferredLanguage,
captionLanguageStemOf(userPreferredLanguage))
.setRendererDisabled(textRendererIndex, false));
}
}

View File

@ -144,6 +144,21 @@ public final class PlayerHelper {
? " (" + context.getString(R.string.caption_auto_generated) + ")" : "");
}
@NonNull
public static String captionLanguageStemOf(@NonNull final String language) {
if (!language.contains("(") || !language.contains(")")) {
return language;
}
if (language.startsWith("(")) {
// language text is right-to-left
final String[] parts = language.split("\\)");
return parts[parts.length - 1].trim();
}
return language.split("\\(")[0].trim();
}
@NonNull
public static String resizeTypeOf(@NonNull final Context context,
@ResizeMode final int resizeMode) {