Skip to content

Commit

Permalink
Merge pull request #113, add missing onError calls to callback
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias123567 authored Apr 8, 2023
1 parent 443e9cb commit 28f52de
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/main/java/com/github/kiulian/downloader/parser/ParserImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Response<VideoInfo> parseVideo(RequestVideoInfo request) {
private VideoInfo parseVideo(String videoId, YoutubeCallback<VideoInfo> callback) throws YoutubeException {
// try to spoof android
// workaround for issue https://github.com/sealedtx/java-youtube-downloader/issues/97
VideoInfo videoInfo = parseVideoAndroid(videoId);
VideoInfo videoInfo = parseVideoAndroid(videoId, callback);
if (videoInfo == null) {
videoInfo = parseVideoWeb(videoId, callback);
}
Expand All @@ -70,7 +70,7 @@ private VideoInfo parseVideo(String videoId, YoutubeCallback<VideoInfo> callback
return videoInfo;
}

private VideoInfo parseVideoAndroid(String videoId) throws YoutubeException {
private VideoInfo parseVideoAndroid(String videoId, YoutubeCallback<VideoInfo> callback) throws YoutubeException {
String url = "https://youtubei.googleapis.com/youtubei/v1/player?key=" + ANDROID_APIKEY;

String body =
Expand Down Expand Up @@ -105,7 +105,15 @@ private VideoInfo parseVideoAndroid(String videoId) throws YoutubeException {
if (videoDetails.isDownloadable()) {
JSONObject context = playerResponse.getJSONObject("responseContext");
String clientVersion = extractor.extractClientVersionFromContext(context);
List<Format> formats = parseFormats(playerResponse, null, clientVersion);
List<Format> formats;
try {
formats = parseFormats(playerResponse, null, clientVersion);
} catch (YoutubeException e) {
if (callback != null) {
callback.onError(e);
}
throw e;
}

List<SubtitlesInfo> subtitlesInfo = parseCaptions(playerResponse);
return new VideoInfo(videoDetails, formats, subtitlesInfo);
Expand Down

0 comments on commit 28f52de

Please sign in to comment.