feat: localized audio track names
This commit is contained in:
parent
366c39d4c6
commit
87a88e4df7
|
@ -191,7 +191,7 @@ dependencies {
|
|||
// name and the commit hash with the commit hash of the (pushed) commit you want to test
|
||||
// This works thanks to JitPack: https://jitpack.io/
|
||||
implementation 'com.github.TeamNewPipe:nanojson:1d9e1aea9049fc9f85e68b43ba39fe7be1c1f751'
|
||||
implementation 'com.github.TeamNewPipe:NewPipeExtractor:5a9b6ed2e3306b9152cc6689dd61dbbe43483845'
|
||||
implementation 'com.github.Theta-Dev:NewPipeExtractor:3fb356a7065c75909ee3856a29be92317c295bb9'
|
||||
implementation 'com.github.TeamNewPipe:NoNonsense-FilePicker:5.0.0'
|
||||
|
||||
/** Checkstyle **/
|
||||
|
|
|
@ -5,6 +5,7 @@ import static org.schabi.newpipe.player.helper.PlayerHelper.formatSpeed;
|
|||
import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.Bundle;
|
||||
|
@ -48,7 +49,6 @@ import org.schabi.newpipe.util.ServiceHelper;
|
|||
import org.schabi.newpipe.util.ThemeHelper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
public final class PlayQueueActivity extends AppCompatActivity
|
||||
|
@ -618,14 +618,17 @@ public final class PlayQueueActivity extends AppCompatActivity
|
|||
return;
|
||||
}
|
||||
|
||||
final Context context = player.getContext();
|
||||
final MenuItem audioTrackSelector = menu.findItem(R.id.action_audio_track);
|
||||
final List<AudioStream> availableStreams =
|
||||
Optional.ofNullable(player.getCurrentMetadata())
|
||||
.flatMap(MediaItemTag::getMaybeAudioTrack)
|
||||
.map(MediaItemTag.AudioTrack::getAudioStreams)
|
||||
.orElse(null);
|
||||
final Optional<AudioStream> selectedAudioStream = player.getSelectedAudioStream();
|
||||
|
||||
if (availableStreams == null || availableStreams.size() < 2) {
|
||||
if (availableStreams == null || availableStreams.size() < 2
|
||||
|| selectedAudioStream.isEmpty()) {
|
||||
audioTrackSelector.setVisible(false);
|
||||
} else {
|
||||
final SubMenu audioTrackMenu = audioTrackSelector.getSubMenu();
|
||||
|
@ -633,25 +636,20 @@ public final class PlayQueueActivity extends AppCompatActivity
|
|||
|
||||
for (int i = 0; i < availableStreams.size(); i++) {
|
||||
final AudioStream audioStream = availableStreams.get(i);
|
||||
if (audioStream.getAudioTrackName() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
audioTrackMenu.add(MENU_ID_AUDIO_TRACK, i, Menu.NONE,
|
||||
audioStream.getAudioTrackName());
|
||||
Localization.audioTrackName(context, audioStream));
|
||||
}
|
||||
|
||||
player.getSelectedAudioStream().ifPresent(s -> {
|
||||
final String trackName = Objects.toString(s.getAudioTrackName(), "");
|
||||
audioTrackSelector.setTitle(getString(R.string.play_queue_audio_track) + trackName);
|
||||
final AudioStream s = selectedAudioStream.get();
|
||||
final String trackName = Localization.audioTrackName(context, s);
|
||||
audioTrackSelector.setTitle(
|
||||
context.getString(R.string.play_queue_audio_track, trackName));
|
||||
|
||||
final String shortName = s.getAudioLocale() != null
|
||||
? s.getAudioLocale().getLanguage() : trackName;
|
||||
audioTrackSelector.setTitleCondensed(
|
||||
shortName.substring(0, Math.min(shortName.length(), 2)));
|
||||
audioTrackSelector.setVisible(true);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -79,6 +79,7 @@ import org.schabi.newpipe.player.playqueue.PlayQueueItem;
|
|||
import org.schabi.newpipe.player.seekbarpreview.SeekbarPreviewThumbnailHelper;
|
||||
import org.schabi.newpipe.player.seekbarpreview.SeekbarPreviewThumbnailHolder;
|
||||
import org.schabi.newpipe.util.DeviceUtils;
|
||||
import org.schabi.newpipe.util.Localization;
|
||||
import org.schabi.newpipe.util.NavigationHelper;
|
||||
import org.schabi.newpipe.util.external_communication.KoreUtils;
|
||||
import org.schabi.newpipe.util.external_communication.ShareUtils;
|
||||
|
@ -1093,15 +1094,13 @@ public abstract class VideoPlayerUi extends PlayerUi implements SeekBar.OnSeekBa
|
|||
|
||||
for (int i = 0; i < availableStreams.size(); i++) {
|
||||
final AudioStream audioStream = availableStreams.get(i);
|
||||
if (audioStream.getAudioTrackName() == null) {
|
||||
continue;
|
||||
}
|
||||
audioTrackPopupMenu.getMenu().add(POPUP_MENU_ID_AUDIO_TRACK, i, Menu.NONE,
|
||||
audioStream.getAudioTrackName());
|
||||
Localization.audioTrackName(context, audioStream));
|
||||
}
|
||||
|
||||
player.getSelectedAudioStream()
|
||||
.ifPresent(s -> binding.audioTrackTextView.setText(s.getAudioTrackName()));
|
||||
.ifPresent(s -> binding.audioTrackTextView.setText(
|
||||
Localization.audioTrackName(context, s)));
|
||||
binding.audioTrackTextView.setVisibility(View.VISIBLE);
|
||||
audioTrackPopupMenu.setOnMenuItemClickListener(this);
|
||||
audioTrackPopupMenu.setOnDismissListener(this);
|
||||
|
@ -1218,10 +1217,6 @@ public abstract class VideoPlayerUi extends PlayerUi implements SeekBar.OnSeekBa
|
|||
private void onAudioTracksClicked() {
|
||||
audioTrackPopupMenu.show();
|
||||
isSomePopupMenuVisible = true;
|
||||
|
||||
player.getSelectedAudioStream()
|
||||
.map(AudioStream::getAudioTrackName)
|
||||
.ifPresent(binding.audioTrackTextView::setText);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -13,6 +13,7 @@ import androidx.preference.PreferenceManager;
|
|||
import org.schabi.newpipe.R;
|
||||
import org.schabi.newpipe.extractor.MediaFormat;
|
||||
import org.schabi.newpipe.extractor.stream.AudioStream;
|
||||
import org.schabi.newpipe.extractor.stream.AudioTrackType;
|
||||
import org.schabi.newpipe.extractor.stream.DeliveryMethod;
|
||||
import org.schabi.newpipe.extractor.stream.Stream;
|
||||
import org.schabi.newpipe.extractor.stream.VideoStream;
|
||||
|
@ -244,8 +245,14 @@ public final class ListHelper {
|
|||
final Comparator<AudioStream> trackCmp =
|
||||
getAudioTrackComparator(preferredLanguageOrEnglish, preferDescriptiveAudio);
|
||||
|
||||
// Filter unknown audio tracks if there are multiple tracks
|
||||
java.util.stream.Stream<AudioStream> cs = collectedStreams.values().stream();
|
||||
if (collectedStreams.size() > 1) {
|
||||
cs = cs.filter(s -> s.getAudioTrackId() != null);
|
||||
}
|
||||
|
||||
// Sort collected streams
|
||||
return collectedStreams.values().stream().sorted(trackCmp).collect(Collectors.toList());
|
||||
return cs.sorted(trackCmp).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/*//////////////////////////////////////////////////////////////////////////
|
||||
|
@ -672,7 +679,7 @@ public final class ListHelper {
|
|||
return Comparator.comparing(AudioStream::getAudioLocale, (o1, o2) -> Boolean.compare(
|
||||
o1 == null || !o1.getISO3Language().equals(preferredLanguage),
|
||||
o2 == null || !o2.getISO3Language().equals(preferredLanguage))
|
||||
).thenComparing(AudioStream::isDescriptive, (o1, o2) ->
|
||||
).thenComparing(s -> s.getAudioTrackType() == AudioTrackType.DESCRIPTIVE, (o1, o2) ->
|
||||
Boolean.compare(o1 ^ preferDescriptiveAudio, o2 ^ preferDescriptiveAudio)
|
||||
).thenComparing(AudioStream::getAudioTrackName, (o1, o2) -> {
|
||||
if (o1 != null) {
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.ocpsoft.prettytime.units.Decade;
|
|||
import org.schabi.newpipe.R;
|
||||
import org.schabi.newpipe.extractor.ListExtractor;
|
||||
import org.schabi.newpipe.extractor.localization.ContentCountry;
|
||||
import org.schabi.newpipe.extractor.stream.AudioStream;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
|
@ -261,6 +262,47 @@ public final class Localization {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the localized name of an audio track.
|
||||
* <p>Example:</p>
|
||||
* <p>English (original)</p>
|
||||
* <p>English (descriptive)</p>
|
||||
* <p>Spanish (dubbed)</p>
|
||||
*
|
||||
* @param context used to get app language
|
||||
* @param track a {@link AudioStream} of the track
|
||||
* @return localized track name
|
||||
*/
|
||||
public static String audioTrackName(final Context context, final AudioStream track) {
|
||||
String res;
|
||||
|
||||
if (track.getAudioLocale() != null) {
|
||||
res = track.getAudioLocale().getDisplayLanguage(getAppLocale(context));
|
||||
} else if (track.getAudioTrackName() != null) {
|
||||
res = track.getAudioTrackName();
|
||||
} else {
|
||||
res = context.getString(R.string.unknown_audio_track);
|
||||
}
|
||||
|
||||
if (track.getAudioTrackType() != null) {
|
||||
res += " (";
|
||||
switch (track.getAudioTrackType()) {
|
||||
case ORIGINAL:
|
||||
res += context.getString(R.string.track_type_original);
|
||||
break;
|
||||
case DUBBED:
|
||||
res += context.getString(R.string.track_type_dubbed);
|
||||
break;
|
||||
case DESCRIPTIVE:
|
||||
res += context.getString(R.string.track_type_descriptive);
|
||||
break;
|
||||
}
|
||||
res += ")";
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/*//////////////////////////////////////////////////////////////////////////
|
||||
// Pretty Time
|
||||
//////////////////////////////////////////////////////////////////////////*/
|
||||
|
|
|
@ -413,7 +413,7 @@
|
|||
<string name="play_queue_remove">Remove</string>
|
||||
<string name="play_queue_stream_detail">Details</string>
|
||||
<string name="play_queue_audio_settings">Audio Settings</string>
|
||||
<string name="play_queue_audio_track">Audio: </string>
|
||||
<string name="play_queue_audio_track">Audio: %s</string>
|
||||
<string name="audio_track">Audio track</string>
|
||||
<string name="hold_to_append">Hold to enqueue</string>
|
||||
<string name="show_channel_details">Show channel details</string>
|
||||
|
@ -768,10 +768,14 @@
|
|||
<string name="select_quality_external_players">Select quality for external players</string>
|
||||
<string name="unknown_format">Unknown format</string>
|
||||
<string name="unknown_quality">Unknown quality</string>
|
||||
<string name="unknown_audio_track">Unknown</string>
|
||||
<string name="feed_toggle_show_future_items">Show future items</string>
|
||||
<string name="feed_toggle_hide_future_items">Hide future items</string>
|
||||
<string name="feed_show_watched">Fully watched</string>
|
||||
<string name="feed_show_partially_watched">Partially watched</string>
|
||||
<string name="feed_show_upcoming">Upcoming</string>
|
||||
<string name="sort">Sort</string>
|
||||
<string name="track_type_original">original</string>
|
||||
<string name="track_type_dubbed">dubbed</string>
|
||||
<string name="track_type_descriptive">descriptive</string>
|
||||
</resources>
|
Loading…
Reference in New Issue