From e960a417eca05af1ce842e5e90b9e1456e918862 Mon Sep 17 00:00:00 2001 From: AudricV <74829229+AudricV@users.noreply.github.com> Date: Thu, 16 Jun 2022 11:04:24 +0200 Subject: [PATCH] [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. --- .../youtube/extractors/YoutubeStreamExtractor.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java index a41325f3..3fdd69bf 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java @@ -1358,13 +1358,20 @@ public class YoutubeStreamExtractor extends StreamExtractor { if (streamType == StreamType.LIVE_STREAM || streamType == StreamType.POST_LIVE_STREAM) { itagItem.setTargetDurationSec(formatData.getInt("targetDurationSec")); - } else if (itagType == ItagItem.ItagType.VIDEO - || itagType == ItagItem.ItagType.VIDEO_ONLY) { + } + + if (itagType == ItagItem.ItagType.VIDEO || itagType == ItagItem.ItagType.VIDEO_ONLY) { itagItem.setFps(formatData.getInt("fps")); } else if (itagType == ItagItem.ItagType.AUDIO) { // YouTube return the audio sample rate as a string itagItem.setSampleRate(Integer.parseInt(formatData.getString("audioSampleRate"))); - itagItem.setAudioChannels(formatData.getInt("audioChannels")); + itagItem.setAudioChannels(formatData.getInt("audioChannels", + // Most audio streams have two audio channels, so use this value if the real + // count cannot be extracted + // Doing this prevents an exception when generating the + // AudioChannelConfiguration element of DASH manifests of audio streams in + // YoutubeDashManifestCreatorUtils + 2)); } // YouTube return the content length and the approximate duration as strings