Skip to content

Commit 76b7c19

Browse files
committed
[YouTube] Extract whether a track is a descriptive audio and audio locale when available
Also use audio track setters only for audio itags.
1 parent 3bb5eee commit 76b7c19

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
import org.schabi.newpipe.extractor.stream.SubtitlesStream;
8383
import org.schabi.newpipe.extractor.stream.VideoStream;
8484
import org.schabi.newpipe.extractor.utils.JsonUtils;
85+
import org.schabi.newpipe.extractor.utils.LocaleCompat;
8586
import org.schabi.newpipe.extractor.utils.Pair;
8687
import org.schabi.newpipe.extractor.utils.Parser;
8788
import org.schabi.newpipe.extractor.utils.Utils;
@@ -1323,6 +1324,8 @@ private java.util.function.Function<ItagInfo, AudioStream> getAudioStreamBuilder
13231324
.setAverageBitrate(itagItem.getAverageBitrate())
13241325
.setAudioTrackId(itagItem.getAudioTrackId())
13251326
.setAudioTrackName(itagItem.getAudioTrackName())
1327+
.setAudioLocale(itagItem.getAudioLocale())
1328+
.setIsDescriptive(itagItem.isDescriptiveAudio())
13261329
.setItagItem(itagItem);
13271330

13281331
if (streamType == StreamType.LIVE_STREAM
@@ -1468,9 +1471,6 @@ private ItagInfo buildAndAddItagInfoToList(
14681471
itagItem.setQuality(formatData.getString("quality"));
14691472
itagItem.setCodec(codec);
14701473

1471-
itagItem.setAudioTrackId(formatData.getObject("audioTrack").getString("id"));
1472-
itagItem.setAudioTrackName(formatData.getObject("audioTrack").getString("displayName"));
1473-
14741474
if (streamType == StreamType.LIVE_STREAM || streamType == StreamType.POST_LIVE_STREAM) {
14751475
itagItem.setTargetDurationSec(formatData.getInt("targetDurationSec"));
14761476
}
@@ -1487,6 +1487,27 @@ private ItagInfo buildAndAddItagInfoToList(
14871487
// AudioChannelConfiguration element of DASH manifests of audio streams in
14881488
// YoutubeDashManifestCreatorUtils
14891489
2));
1490+
1491+
final String audioTrackId = formatData.getObject("audioTrack")
1492+
.getString("id");
1493+
if (!isNullOrEmpty(audioTrackId)) {
1494+
itagItem.setAudioTrackId(audioTrackId);
1495+
final int audioTrackIdLastLocaleCharacter = audioTrackId.indexOf(".");
1496+
if (audioTrackIdLastLocaleCharacter != -1) {
1497+
// Audio tracks IDs are in the form LANGUAGE_CODE.TRACK_NUMBER
1498+
itagItem.setAudioLocale(LocaleCompat.forLanguageTag(
1499+
audioTrackId.substring(0, audioTrackIdLastLocaleCharacter)));
1500+
}
1501+
}
1502+
1503+
itagItem.setAudioTrackName(formatData.getObject("audioTrack")
1504+
.getString("displayName"));
1505+
1506+
// Descriptive audio tracks
1507+
// This information is also provided as a protobuf object in the formatData
1508+
itagItem.setIsDescriptiveAudio(streamUrl.contains("acont%3Ddescriptive")
1509+
// Support "decoded" URLs
1510+
|| streamUrl.contains("acont=descriptive"));
14901511
}
14911512

14921513
// YouTube return the content length and the approximate duration as strings

0 commit comments

Comments
 (0)