From 96a8230d39bb80f86a9c431f1e5ad34af767cf60 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Sun, 24 Jan 2021 10:56:44 +0800 Subject: Fix gfycat and redgifs API. --- .../FetchGfycatOrRedgifsVideoLinks.java | 16 ++++++++++++---- .../infinityforreddit/utils/JSONUtils.java | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchGfycatOrRedgifsVideoLinks.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchGfycatOrRedgifsVideoLinks.java index 0aeb5eeb..c59f66a6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchGfycatOrRedgifsVideoLinks.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchGfycatOrRedgifsVideoLinks.java @@ -1,6 +1,7 @@ package ml.docilealligator.infinityforreddit; import android.os.AsyncTask; +import android.util.Log; import androidx.annotation.NonNull; @@ -34,6 +35,7 @@ public class FetchGfycatOrRedgifsVideoLinks { gfycatRetrofit.create(GfycatAPI.class).getGfycatData(gfycatId).enqueue(new Callback() { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { + Log.i("asdfasf", "s " + response.body()); if (response.isSuccessful()) { new ParseGfycatVideoLinksAsyncTask(response.body(), fetchGfycatOrRedgifsVideoLinksListener).execute(); } else { @@ -100,16 +102,22 @@ public class FetchGfycatOrRedgifsVideoLinks { protected Void doInBackground(Void... voids) { try { JSONObject jsonObject = new JSONObject(response); - webm = jsonObject.getJSONObject(JSONUtils.GFY_ITEM_KEY) - .getJSONObject(JSONUtils.CONTENT_URLS_KEY) - .getJSONObject(JSONUtils.WEBM_KEY) - .getString(JSONUtils.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); + if (jsonObject.getJSONObject(JSONUtils.GFY_ITEM_KEY).has(JSONUtils.WEBM_URL_KEY)) { + webm = jsonObject.getJSONObject(JSONUtils.GFY_ITEM_KEY).getString(JSONUtils.WEBM_URL_KEY); + } else if (jsonObject.getJSONObject(JSONUtils.GFY_ITEM_KEY).getJSONObject(JSONUtils.CONTENT_URLS_KEY).has(JSONUtils.WEBM_KEY)) { + webm = jsonObject.getJSONObject(JSONUtils.GFY_ITEM_KEY) + .getJSONObject(JSONUtils.CONTENT_URLS_KEY) + .getJSONObject(JSONUtils.WEBM_KEY) + .getString(JSONUtils.URL_KEY); + } else { + webm = mp4; + } } catch (JSONException e) { e.printStackTrace(); parseFailed = true; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/JSONUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/JSONUtils.java index 989df80f..085ee905 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/JSONUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/JSONUtils.java @@ -131,4 +131,5 @@ public class JSONUtils { public static final String AWARDEE_KARMA_KEY = "awardee_karma"; public static final String CONTENT_URLS_KEY = "content_urls";; public static final String WEBM_KEY = "webm"; + public static final String WEBM_URL_KEY = "webmUrl"; } -- cgit v1.2.3