use of com.grack.nanojson.JsonParserException in project NewPipeExtractor by TeamNewPipe.
the class SoundcloudChannelExtractor method onFetchPage.
@Override
public void onFetchPage(@Nonnull final Downloader downloader) throws IOException, ExtractionException {
userId = getLinkHandler().getId();
final String apiUrl = USERS_ENDPOINT + userId + "?client_id=" + SoundcloudParsingHelper.clientId();
final String response = downloader.get(apiUrl, getExtractorLocalization()).responseBody();
try {
user = JsonParser.object().from(response);
} catch (final JsonParserException e) {
throw new ParsingException("Could not parse json response", e);
}
}
use of com.grack.nanojson.JsonParserException in project NewPipeExtractor by TeamNewPipe.
the class SoundcloudCommentsExtractor method getPage.
@Override
public InfoItemsPage<CommentsInfoItem> getPage(final Page page) throws ExtractionException, IOException {
if (page == null || isNullOrEmpty(page.getUrl())) {
throw new IllegalArgumentException("Page doesn't contain an URL");
}
final Downloader downloader = NewPipe.getDownloader();
final Response response = downloader.get(page.getUrl());
final JsonObject json;
try {
json = JsonParser.object().from(response.responseBody());
} catch (final JsonParserException e) {
throw new ParsingException("Could not parse json", e);
}
final CommentsInfoItemsCollector collector = new CommentsInfoItemsCollector(getServiceId());
collectStreamsFrom(collector, json.getArray("collection"));
return new InfoItemsPage<>(collector, new Page(json.getString("next_href")));
}
use of com.grack.nanojson.JsonParserException in project NewPipeExtractor by TeamNewPipe.
the class SoundcloudPlaylistExtractor method onFetchPage.
@Override
public void onFetchPage(@Nonnull final Downloader downloader) throws IOException, ExtractionException {
playlistId = getLinkHandler().getId();
final String apiUrl = SOUNDCLOUD_API_V2_URL + "playlists/" + playlistId + "?client_id=" + SoundcloudParsingHelper.clientId() + "&representation=compact";
final String response = downloader.get(apiUrl, getExtractorLocalization()).responseBody();
try {
playlist = JsonParser.object().from(response);
} catch (final JsonParserException e) {
throw new ParsingException("Could not parse json response", e);
}
}
use of com.grack.nanojson.JsonParserException in project NewPipeExtractor by TeamNewPipe.
the class SoundcloudPlaylistExtractor method getPage.
@Override
public InfoItemsPage<StreamInfoItem> getPage(final Page page) throws IOException, ExtractionException {
if (page == null || isNullOrEmpty(page.getIds())) {
throw new IllegalArgumentException("Page doesn't contain IDs");
}
final List<String> currentIds;
final List<String> nextIds;
if (page.getIds().size() <= STREAMS_PER_REQUESTED_PAGE) {
// Fetch every remaining stream, there are less than the max
currentIds = page.getIds();
nextIds = null;
} else {
currentIds = page.getIds().subList(0, STREAMS_PER_REQUESTED_PAGE);
nextIds = page.getIds().subList(STREAMS_PER_REQUESTED_PAGE, page.getIds().size());
}
final String currentPageUrl = SOUNDCLOUD_API_V2_URL + "tracks?client_id=" + SoundcloudParsingHelper.clientId() + "&ids=" + Utils.join(",", currentIds);
final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
final String response = NewPipe.getDownloader().get(currentPageUrl, getExtractorLocalization()).responseBody();
try {
final JsonArray tracks = JsonParser.array().from(response);
for (final Object track : tracks) {
if (track instanceof JsonObject) {
collector.commit(new SoundcloudStreamInfoItemExtractor((JsonObject) track));
}
}
} catch (final JsonParserException e) {
throw new ParsingException("Could not parse json response", e);
}
return new InfoItemsPage<>(collector, new Page(nextIds));
}
use of com.grack.nanojson.JsonParserException in project NewPipeExtractor by TeamNewPipe.
the class BandcampSuggestionExtractor method suggestionList.
@Override
public List<String> suggestionList(final String query) throws IOException, ExtractionException {
final Downloader downloader = NewPipe.getDownloader();
try {
final JsonObject fuzzyResults = JsonParser.object().from(downloader.get(AUTOCOMPLETE_URL + URLEncoder.encode(query, "UTF-8")).responseBody());
final JsonArray jsonArray = fuzzyResults.getObject("auto").getArray("results");
final List<String> suggestions = new ArrayList<>();
for (final Object fuzzyResult : jsonArray) {
final String res = ((JsonObject) fuzzyResult).getString("name");
if (!suggestions.contains(res))
suggestions.add(res);
}
return suggestions;
} catch (final JsonParserException e) {
return Collections.emptyList();
}
}
Aggregations