From 54ef23c35760b1da140eac688cbb94bbcf213de1 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Sat, 23 Jan 2021 09:56:13 +0800 Subject: Prevent a potential parsing error using the gfycat API. --- .../infinityforreddit/FetchGfycatOrRedgifsVideoLinks.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchGfycatOrRedgifsVideoLinks.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchGfycatOrRedgifsVideoLinks.java index a2a7d129..0aeb5eeb 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchGfycatOrRedgifsVideoLinks.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchGfycatOrRedgifsVideoLinks.java @@ -104,7 +104,12 @@ public class FetchGfycatOrRedgifsVideoLinks { .getJSONObject(JSONUtils.CONTENT_URLS_KEY) .getJSONObject(JSONUtils.WEBM_KEY) .getString(JSONUtils.URL_KEY); - mp4 = jsonObject.getJSONObject(JSONUtils.GFY_ITEM_KEY).getString(JSONUtils.MP4_URL_KEY); + mp4 = jsonObject.getJSONObject(JSONUtils.GFY_ITEM_KEY).has(JSONUtils.MP4_URL_KEY) ? + jsonObject.getJSONObject(JSONUtils.GFY_ITEM_KEY).getString(JSONUtils.MP4_URL_KEY) + : jsonObject.getJSONObject(JSONUtils.GFY_ITEM_KEY) + .getJSONObject(JSONUtils.CONTENT_URLS_KEY) + .getJSONObject(JSONUtils.MP4_KEY) + .getString(JSONUtils.URL_KEY); } catch (JSONException e) { e.printStackTrace(); parseFailed = true; -- cgit v1.2.3