Skip to content

Commit 12bfdf5

Browse files
committed
Change dash parser exception handling
1 parent b5b25a4 commit 12bfdf5

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

stream/StreamInfo.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
66
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
77
import org.schabi.newpipe.extractor.utils.DashMpdParser;
8+
import org.schabi.newpipe.extractor.utils.Utils;
89

10+
import java.io.FileNotFoundException;
911
import java.util.List;
1012
import java.util.Vector;
1113

@@ -137,7 +139,12 @@ private static StreamInfo extractStreams(StreamInfo streamInfo, StreamExtractor
137139
// find a similar stream in the respective lists (calling Stream#equalStats).
138140
DashMpdParser.getStreams(streamInfo);
139141
} catch (Exception e) {
140-
streamInfo.addException(new ExtractionException("Couldn't get streams from dash mpd", e));
142+
// Sometimes we receive 403 (forbidden) error when trying to download the manifest,
143+
// (similar to https://github.com/rg3/youtube-dl/blob/master/youtube_dl/extractor/youtube.py#L1888)
144+
// just skip the exception, as we later check if we have any streams
145+
if (!Utils.hasCauseThrowable(e, FileNotFoundException.class)) {
146+
streamInfo.addException(new ExtractionException("Couldn't get streams from dash mpd", e));
147+
}
141148
}
142149
}
143150

utils/Utils.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,21 @@ private Utils() {
1717
public static String removeNonDigitCharacters(String toRemove) {
1818
return toRemove.replaceAll("\\D+", "");
1919
}
20+
21+
/**
22+
* Check if throwable have the cause
23+
*/
24+
public static boolean hasCauseThrowable(Throwable throwable, Class<?> causeToCheck) {
25+
// Check if getCause is not the same as cause (the getCause is already the root),
26+
// as it will cause a infinite loop if it is
27+
Throwable cause, getCause = throwable;
28+
29+
while ((cause = throwable.getCause()) != null && getCause != cause) {
30+
getCause = cause;
31+
if (cause.getClass().isAssignableFrom(causeToCheck)) {
32+
return true;
33+
}
34+
}
35+
return false;
36+
}
2037
}

0 commit comments

Comments
 (0)