SponsorBlock: Now using nanojson instead of org.json
This commit is contained in:
parent
d17745a4ea
commit
7b62bf656c
1 changed files with 12 additions and 11 deletions
|
@ -6,30 +6,31 @@ import android.net.ConnectivityManager;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import com.grack.nanojson.JsonArray;
|
||||||
import org.json.JSONException;
|
import com.grack.nanojson.JsonObject;
|
||||||
import org.json.JSONObject;
|
import com.grack.nanojson.JsonParser;
|
||||||
|
|
||||||
import org.schabi.newpipe.util.SponsorTimeInfo;
|
import org.schabi.newpipe.util.SponsorTimeInfo;
|
||||||
import org.schabi.newpipe.util.TimeFrame;
|
import org.schabi.newpipe.util.TimeFrame;
|
||||||
|
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
public class SponsorBlockApiTask extends AsyncTask<String, Void, JSONObject> {
|
public class SponsorBlockApiTask extends AsyncTask<String, Void, JsonObject> {
|
||||||
private static final Application APP = App.getApp();
|
private static final Application APP = App.getApp();
|
||||||
private static final String SPONSOR_BLOCK_API_URL = "https://sponsor.ajay.app/api/";
|
private static final String SPONSOR_BLOCK_API_URL = "https://sponsor.ajay.app/api/";
|
||||||
private static final String TAG = SponsorBlockApiTask.class.getSimpleName();
|
private static final String TAG = SponsorBlockApiTask.class.getSimpleName();
|
||||||
private static final boolean DEBUG = MainActivity.DEBUG;
|
private static final boolean DEBUG = MainActivity.DEBUG;
|
||||||
|
|
||||||
public SponsorTimeInfo getYouTubeVideoSponsorTimes(final String videoId)
|
public SponsorTimeInfo getYouTubeVideoSponsorTimes(final String videoId)
|
||||||
throws ExecutionException, InterruptedException, JSONException {
|
throws ExecutionException, InterruptedException {
|
||||||
|
|
||||||
JSONObject obj = execute("getVideoSponsorTimes?videoID=" + videoId).get();
|
JsonObject obj = execute("getVideoSponsorTimes?videoID=" + videoId).get();
|
||||||
JSONArray arrayObj = obj.getJSONArray("sponsorTimes");
|
JsonArray arrayObj = obj.getArray("sponsorTimes");
|
||||||
|
|
||||||
SponsorTimeInfo result = new SponsorTimeInfo();
|
SponsorTimeInfo result = new SponsorTimeInfo();
|
||||||
|
|
||||||
for (int i = 0; i < arrayObj.length(); i++) {
|
for (int i = 0; i < arrayObj.size(); i++) {
|
||||||
JSONArray subArrayObj = arrayObj.getJSONArray(i);
|
JsonArray subArrayObj = arrayObj.getArray(i);
|
||||||
|
|
||||||
double startTime = subArrayObj.getDouble(0) * 1000;
|
double startTime = subArrayObj.getDouble(0) * 1000;
|
||||||
double endTime = subArrayObj.getDouble(1) * 1000;
|
double endTime = subArrayObj.getDouble(1) * 1000;
|
||||||
|
@ -43,7 +44,7 @@ public class SponsorBlockApiTask extends AsyncTask<String, Void, JSONObject> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected JSONObject doInBackground(final String... strings) {
|
protected JsonObject doInBackground(final String... strings) {
|
||||||
if (isCancelled() || !isConnected()) {
|
if (isCancelled() || !isConnected()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -55,7 +56,7 @@ public class SponsorBlockApiTask extends AsyncTask<String, Void, JSONObject> {
|
||||||
.get(SPONSOR_BLOCK_API_URL + strings[0])
|
.get(SPONSOR_BLOCK_API_URL + strings[0])
|
||||||
.responseBody();
|
.responseBody();
|
||||||
|
|
||||||
return new JSONObject(responseBody);
|
return JsonParser.object().from(responseBody);
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
|
|
Loading…
Reference in a new issue