use of com.grack.nanojson.JsonParserException in project NewPipe by TeamNewPipe.
the class PeertubeHelper method getInstanceList.
public static List<PeertubeInstance> getInstanceList(final Context context) {
final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
final String savedInstanceListKey = context.getString(R.string.peertube_instance_list_key);
final String savedJson = sharedPreferences.getString(savedInstanceListKey, null);
if (null == savedJson) {
return Collections.singletonList(getCurrentInstance());
}
try {
final JsonArray array = JsonParser.object().from(savedJson).getArray("instances");
final List<PeertubeInstance> result = new ArrayList<>();
for (final Object o : array) {
if (o instanceof JsonObject) {
final JsonObject instance = (JsonObject) o;
final String name = instance.getString("name");
final String url = instance.getString("url");
result.add(new PeertubeInstance(url, name));
}
}
return result;
} catch (final JsonParserException e) {
return Collections.singletonList(getCurrentInstance());
}
}
use of com.grack.nanojson.JsonParserException in project NewPipeExtractor by TeamNewPipe.
the class SoundcloudSearchExtractor method onFetchPage.
@Override
public void onFetchPage(@Nonnull final Downloader downloader) throws IOException, ExtractionException {
final Downloader dl = getDownloader();
final String url = getUrl();
try {
final String response = dl.get(url, getExtractorLocalization()).responseBody();
initialSearchCollection = JsonParser.object().from(response).getArray("collection");
} catch (final JsonParserException e) {
throw new ParsingException("Could not parse json response", e);
}
if (initialSearchCollection.isEmpty()) {
throw new SearchExtractor.NothingFoundException("Nothing found");
}
}
use of com.grack.nanojson.JsonParserException in project NewPipeExtractor by TeamNewPipe.
the class SoundcloudSearchExtractor method getPage.
@Override
public InfoItemsPage<InfoItem> getPage(final Page page) throws IOException, ExtractionException {
if (page == null || isNullOrEmpty(page.getUrl())) {
throw new IllegalArgumentException("Page doesn't contain an URL");
}
final Downloader dl = getDownloader();
final JsonArray searchCollection;
try {
final String response = dl.get(page.getUrl(), getExtractorLocalization()).responseBody();
searchCollection = JsonParser.object().from(response).getArray("collection");
} catch (final JsonParserException e) {
throw new ParsingException("Could not parse json response", e);
}
return new InfoItemsPage<>(collectItems(searchCollection), getNextPageFromCurrentUrl(page.getUrl(), currentOffset -> currentOffset + ITEMS_PER_PAGE));
}
use of com.grack.nanojson.JsonParserException in project NewPipeExtractor by TeamNewPipe.
the class SoundcloudStreamExtractor method getTranscodingUrl.
@Nonnull
private static String getTranscodingUrl(final String endpointUrl, final String protocol) throws IOException, ExtractionException {
final Downloader downloader = NewPipe.getDownloader();
final String apiStreamUrl = endpointUrl + "?client_id=" + SoundcloudParsingHelper.clientId();
final String response = downloader.get(apiStreamUrl).responseBody();
final JsonObject urlObject;
try {
urlObject = JsonParser.object().from(response);
} catch (final JsonParserException e) {
throw new ParsingException("Could not parse streamable url", e);
}
final String urlString = urlObject.getString("url");
if (protocol.equals("progressive")) {
return urlString;
} else if (protocol.equals("hls")) {
try {
return getSingleUrlFromHlsManifest(urlString);
} catch (final ParsingException ignored) {
}
}
// else, unknown protocol
return "";
}
use of com.grack.nanojson.JsonParserException in project NewPipeExtractor by TeamNewPipe.
the class SoundcloudSuggestionExtractor method suggestionList.
@Override
public List<String> suggestionList(final String query) throws IOException, ExtractionException {
final List<String> suggestions = new ArrayList<>();
final Downloader dl = NewPipe.getDownloader();
final String url = SOUNDCLOUD_API_V2_URL + "search/queries" + "?q=" + URLEncoder.encode(query, UTF_8) + "&client_id=" + SoundcloudParsingHelper.clientId() + "&limit=10";
final String response = dl.get(url, getExtractorLocalization()).responseBody();
try {
final JsonArray collection = JsonParser.object().from(response).getArray("collection");
for (final Object suggestion : collection) {
if (suggestion instanceof JsonObject)
suggestions.add(((JsonObject) suggestion).getString("query"));
}
return suggestions;
} catch (final JsonParserException e) {
throw new ParsingException("Could not parse json response", e);
}
}
Aggregations