From 325a51f73ab68bf52dfefe640a89472f6093abb9 Mon Sep 17 00:00:00 2001 From: Stypox Date: Sat, 14 Mar 2020 14:02:48 +0100 Subject: [PATCH] [YouTube] Do not crash if there is no next stream, but return null Like every other extractor does if there is no next stream --- .../extractors/YoutubeStreamExtractor.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 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 8ee502013..04818de07 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 @@ -523,10 +523,18 @@ public class YoutubeStreamExtractor extends StreamExtractor { if (getAgeLimit() != NO_AGE_LIMIT) return null; try { - final JsonObject videoInfo = initialData.getObject("contents").getObject("twoColumnWatchNextResults") - .getObject("secondaryResults").getObject("secondaryResults").getArray("results") - .getObject(0).getObject("compactAutoplayRenderer").getArray("contents") - .getObject(0).getObject("compactVideoRenderer"); + final JsonObject firstWatchNextItem = initialData.getObject("contents") + .getObject("twoColumnWatchNextResults").getObject("secondaryResults") + .getObject("secondaryResults").getArray("results").getObject(0); + + if (!firstWatchNextItem.has("compactAutoplayRenderer")) { + // there is no "next" stream + return null; + } + + final JsonObject videoInfo = firstWatchNextItem.getObject("compactAutoplayRenderer") + .getArray("contents").getObject(0).getObject("compactVideoRenderer"); + final TimeAgoParser timeAgoParser = getTimeAgoParser(); StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());