Search in sources :

Example 1 with JsonParserException

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);
    }
}
Also used : JsonParserException(com.grack.nanojson.JsonParserException) ParsingException(org.schabi.newpipe.extractor.exceptions.ParsingException)

Example 2 with JsonParserException

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")));
}
Also used : Response(org.schabi.newpipe.extractor.downloader.Response) JsonParserException(com.grack.nanojson.JsonParserException) ParsingException(org.schabi.newpipe.extractor.exceptions.ParsingException) Downloader(org.schabi.newpipe.extractor.downloader.Downloader) JsonObject(com.grack.nanojson.JsonObject) CommentsInfoItemsCollector(org.schabi.newpipe.extractor.comments.CommentsInfoItemsCollector) Page(org.schabi.newpipe.extractor.Page)

Example 3 with JsonParserException

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);
    }
}
Also used : JsonParserException(com.grack.nanojson.JsonParserException) ParsingException(org.schabi.newpipe.extractor.exceptions.ParsingException)

Example 4 with JsonParserException

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));
}
Also used : JsonArray(com.grack.nanojson.JsonArray) StreamInfoItemsCollector(org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector) JsonParserException(com.grack.nanojson.JsonParserException) ParsingException(org.schabi.newpipe.extractor.exceptions.ParsingException) JsonObject(com.grack.nanojson.JsonObject) JsonObject(com.grack.nanojson.JsonObject) Page(org.schabi.newpipe.extractor.Page)

Example 5 with JsonParserException

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();
    }
}
Also used : JsonArray(com.grack.nanojson.JsonArray) JsonParserException(com.grack.nanojson.JsonParserException) ArrayList(java.util.ArrayList) Downloader(org.schabi.newpipe.extractor.downloader.Downloader) JsonObject(com.grack.nanojson.JsonObject) JsonObject(com.grack.nanojson.JsonObject)

Aggregations

JsonParserException (com.grack.nanojson.JsonParserException)30 JsonObject (com.grack.nanojson.JsonObject)20 ParsingException (org.schabi.newpipe.extractor.exceptions.ParsingException)18 JsonArray (com.grack.nanojson.JsonArray)11 Downloader (org.schabi.newpipe.extractor.downloader.Downloader)11 IOException (java.io.IOException)10 ReCaptchaException (org.schabi.newpipe.extractor.exceptions.ReCaptchaException)9 Response (org.schabi.newpipe.extractor.downloader.Response)8 ExtractionException (org.schabi.newpipe.extractor.exceptions.ExtractionException)8 ArrayList (java.util.ArrayList)5 MalformedURLException (java.net.MalformedURLException)4 Nonnull (javax.annotation.Nonnull)4 Page (org.schabi.newpipe.extractor.Page)3 SharedPreferences (android.content.SharedPreferences)2 URL (java.net.URL)2 DateTimeParseException (java.time.format.DateTimeParseException)2 CommentsInfoItemsCollector (org.schabi.newpipe.extractor.comments.CommentsInfoItemsCollector)2 PeertubeInstance (org.schabi.newpipe.extractor.services.peertube.PeertubeInstance)2 RegexException (org.schabi.newpipe.extractor.utils.Parser.RegexException)2 Caffeine (com.github.benmanes.caffeine.cache.Caffeine)1