From 12bfdf523462dbc4b943d9a2176497aa9b024369 Mon Sep 17 00:00:00 2001 From: Mauricio Colli Date: Wed, 12 Jul 2017 13:20:36 -0300 Subject: [PATCH] Change dash parser exception handling --- stream/StreamInfo.java | 9 ++++++++- utils/Utils.java | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/stream/StreamInfo.java b/stream/StreamInfo.java index 9719d9359..6168ae26e 100644 --- a/stream/StreamInfo.java +++ b/stream/StreamInfo.java @@ -5,7 +5,9 @@ import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.utils.DashMpdParser; +import org.schabi.newpipe.extractor.utils.Utils; +import java.io.FileNotFoundException; import java.util.List; import java.util.Vector; @@ -137,7 +139,12 @@ public class StreamInfo extends Info { // find a similar stream in the respective lists (calling Stream#equalStats). DashMpdParser.getStreams(streamInfo); } catch (Exception e) { - streamInfo.addException(new ExtractionException("Couldn't get streams from dash mpd", e)); + // Sometimes we receive 403 (forbidden) error when trying to download the manifest, + // (similar to https://github.com/rg3/youtube-dl/blob/master/youtube_dl/extractor/youtube.py#L1888) + // just skip the exception, as we later check if we have any streams + if (!Utils.hasCauseThrowable(e, FileNotFoundException.class)) { + streamInfo.addException(new ExtractionException("Couldn't get streams from dash mpd", e)); + } } } diff --git a/utils/Utils.java b/utils/Utils.java index 8c4449b11..ff32c88b6 100644 --- a/utils/Utils.java +++ b/utils/Utils.java @@ -17,4 +17,21 @@ public class Utils { public static String removeNonDigitCharacters(String toRemove) { return toRemove.replaceAll("\\D+", ""); } + + /** + * Check if throwable have the cause + */ + public static boolean hasCauseThrowable(Throwable throwable, Class causeToCheck) { + // Check if getCause is not the same as cause (the getCause is already the root), + // as it will cause a infinite loop if it is + Throwable cause, getCause = throwable; + + while ((cause = throwable.getCause()) != null && getCause != cause) { + getCause = cause; + if (cause.getClass().isAssignableFrom(causeToCheck)) { + return true; + } + } + return false; + } }