Skip to content

Commit e960a41

Browse files
committed
[YouTube] Fix extraction of fps, audioSampleRate and audioChannels fields for ItagItems of live streams and post live streams
These values were only set before for video streams. A fallback for the audio channels count has been added, in order to prevent exceptions when generating DASH manifests of audio streams: the fallback value is 2, because most audio streams on YouTube have 2 audio channels.
1 parent c8a77da commit e960a41

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,13 +1358,20 @@ private ItagInfo buildAndAddItagInfoToList(
13581358

13591359
if (streamType == StreamType.LIVE_STREAM || streamType == StreamType.POST_LIVE_STREAM) {
13601360
itagItem.setTargetDurationSec(formatData.getInt("targetDurationSec"));
1361-
} else if (itagType == ItagItem.ItagType.VIDEO
1362-
|| itagType == ItagItem.ItagType.VIDEO_ONLY) {
1361+
}
1362+
1363+
if (itagType == ItagItem.ItagType.VIDEO || itagType == ItagItem.ItagType.VIDEO_ONLY) {
13631364
itagItem.setFps(formatData.getInt("fps"));
13641365
} else if (itagType == ItagItem.ItagType.AUDIO) {
13651366
// YouTube return the audio sample rate as a string
13661367
itagItem.setSampleRate(Integer.parseInt(formatData.getString("audioSampleRate")));
1367-
itagItem.setAudioChannels(formatData.getInt("audioChannels"));
1368+
itagItem.setAudioChannels(formatData.getInt("audioChannels",
1369+
// Most audio streams have two audio channels, so use this value if the real
1370+
// count cannot be extracted
1371+
// Doing this prevents an exception when generating the
1372+
// AudioChannelConfiguration element of DASH manifests of audio streams in
1373+
// YoutubeDashManifestCreatorUtils
1374+
2));
13681375
}
13691376

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

0 commit comments

Comments
 (0)