Fix gfycat and redgifs API.

This commit is contained in:
Alex Ning 2021-01-24 10:56:44 +08:00
parent 0402a47090
commit 96a8230d39
2 changed files with 13 additions and 4 deletions

View File

@ -1,6 +1,7 @@
package ml.docilealligator.infinityforreddit; package ml.docilealligator.infinityforreddit;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.util.Log;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -34,6 +35,7 @@ public class FetchGfycatOrRedgifsVideoLinks {
gfycatRetrofit.create(GfycatAPI.class).getGfycatData(gfycatId).enqueue(new Callback<String>() { gfycatRetrofit.create(GfycatAPI.class).getGfycatData(gfycatId).enqueue(new Callback<String>() {
@Override @Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) { public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
Log.i("asdfasf", "s " + response.body());
if (response.isSuccessful()) { if (response.isSuccessful()) {
new ParseGfycatVideoLinksAsyncTask(response.body(), fetchGfycatOrRedgifsVideoLinksListener).execute(); new ParseGfycatVideoLinksAsyncTask(response.body(), fetchGfycatOrRedgifsVideoLinksListener).execute();
} else { } else {
@ -100,16 +102,22 @@ public class FetchGfycatOrRedgifsVideoLinks {
protected Void doInBackground(Void... voids) { protected Void doInBackground(Void... voids) {
try { try {
JSONObject jsonObject = new JSONObject(response); 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) ? 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).getString(JSONUtils.MP4_URL_KEY)
: jsonObject.getJSONObject(JSONUtils.GFY_ITEM_KEY) : jsonObject.getJSONObject(JSONUtils.GFY_ITEM_KEY)
.getJSONObject(JSONUtils.CONTENT_URLS_KEY) .getJSONObject(JSONUtils.CONTENT_URLS_KEY)
.getJSONObject(JSONUtils.MP4_KEY) .getJSONObject(JSONUtils.MP4_KEY)
.getString(JSONUtils.URL_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) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
parseFailed = true; parseFailed = true;

View File

@ -131,4 +131,5 @@ public class JSONUtils {
public static final String AWARDEE_KARMA_KEY = "awardee_karma"; public static final String AWARDEE_KARMA_KEY = "awardee_karma";
public static final String CONTENT_URLS_KEY = "content_urls";; public static final String CONTENT_URLS_KEY = "content_urls";;
public static final String WEBM_KEY = "webm"; public static final String WEBM_KEY = "webm";
public static final String WEBM_URL_KEY = "webmUrl";
} }