From 28f52dedefcf9733de0a835e64a32806c23e74d6 Mon Sep 17 00:00:00 2001 From: Tobias123567 <42582100+Tobias123567@users.noreply.github.com> Date: Sat, 8 Apr 2023 19:03:46 +0200 Subject: [PATCH] Merge pull request #113, add missing onError calls to callback --- .../kiulian/downloader/parser/ParserImpl.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/github/kiulian/downloader/parser/ParserImpl.java b/src/main/java/com/github/kiulian/downloader/parser/ParserImpl.java index e8ed663..8417032 100644 --- a/src/main/java/com/github/kiulian/downloader/parser/ParserImpl.java +++ b/src/main/java/com/github/kiulian/downloader/parser/ParserImpl.java @@ -60,7 +60,7 @@ public Response parseVideo(RequestVideoInfo request) { private VideoInfo parseVideo(String videoId, YoutubeCallback 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); } @@ -70,7 +70,7 @@ private VideoInfo parseVideo(String videoId, YoutubeCallback callback return videoInfo; } - private VideoInfo parseVideoAndroid(String videoId) throws YoutubeException { + private VideoInfo parseVideoAndroid(String videoId, YoutubeCallback callback) throws YoutubeException { String url = "https://youtubei.googleapis.com/youtubei/v1/player?key=" + ANDROID_APIKEY; String body = @@ -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 formats = parseFormats(playerResponse, null, clientVersion); + List formats; + try { + formats = parseFormats(playerResponse, null, clientVersion); + } catch (YoutubeException e) { + if (callback != null) { + callback.onError(e); + } + throw e; + } List subtitlesInfo = parseCaptions(playerResponse); return new VideoInfo(videoDetails, formats, subtitlesInfo);