Skip to content

Commit

Permalink
Change dash parser exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mauriciocolli committed Jul 12, 2017
1 parent b5b25a4 commit 12bfdf5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
9 changes: 8 additions & 1 deletion stream/StreamInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
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;

Expand Down Expand Up @@ -137,7 +139,12 @@ private static StreamInfo extractStreams(StreamInfo streamInfo, StreamExtractor
// 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));
}
}
}

Expand Down
17 changes: 17 additions & 0 deletions utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,21 @@ private 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;
}
}

0 comments on commit 12bfdf5

Please sign in to comment.