Search in sources :

Example 26 with JsonParserException

use of com.grack.nanojson.JsonParserException in project NewPipeExtractor by TeamNewPipe.

the class PeertubeInstance method fetchInstanceMetaData.

public void fetchInstanceMetaData() throws Exception {
    Downloader downloader = NewPipe.getDownloader();
    Response response = null;
    try {
        response = downloader.get(url + "/api/v1/config");
    } catch (ReCaptchaException | IOException e) {
        throw new Exception("unable to configure instance " + url, e);
    }
    if (response == null || Utils.isBlank(response.responseBody())) {
        throw new Exception("unable to configure instance " + url);
    }
    try {
        JsonObject json = JsonParser.object().from(response.responseBody());
        this.name = JsonUtils.getString(json, "instance.name");
    } catch (JsonParserException | ParsingException e) {
        throw new Exception("unable to parse instance config", e);
    }
}
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) IOException(java.io.IOException) ReCaptchaException(org.schabi.newpipe.extractor.exceptions.ReCaptchaException) JsonParserException(com.grack.nanojson.JsonParserException) IOException(java.io.IOException) ParsingException(org.schabi.newpipe.extractor.exceptions.ParsingException) ReCaptchaException(org.schabi.newpipe.extractor.exceptions.ReCaptchaException)

Example 27 with JsonParserException

use of com.grack.nanojson.JsonParserException in project NewPipeExtractor by TeamNewPipe.

the class PeertubePlaylistExtractor method onFetchPage.

@Override
public void onFetchPage(@Nonnull final Downloader downloader) throws IOException, ExtractionException {
    final Response response = downloader.get(getUrl());
    try {
        playlistInfo = JsonParser.object().from(response.responseBody());
    } catch (JsonParserException jpe) {
        throw new ExtractionException("Could not parse json", jpe);
    }
    PeertubeParsingHelper.validate(playlistInfo);
}
Also used : Response(org.schabi.newpipe.extractor.downloader.Response) ExtractionException(org.schabi.newpipe.extractor.exceptions.ExtractionException) JsonParserException(com.grack.nanojson.JsonParserException)

Example 28 with JsonParserException

use of com.grack.nanojson.JsonParserException in project NewPipeExtractor by TeamNewPipe.

the class BandcampPlaylistExtractor method onFetchPage.

@Override
public void onFetchPage(@Nonnull final Downloader downloader) throws IOException, ExtractionException {
    final String html = downloader.get(getLinkHandler().getUrl()).responseBody();
    document = Jsoup.parse(html);
    albumJson = getAlbumInfoJson(html);
    trackInfo = albumJson.getArray("trackinfo");
    try {
        name = getJsonData(html, "data-embed").getString("album_title");
    } catch (final JsonParserException e) {
        throw new ParsingException("Faulty JSON; page likely does not contain album data", e);
    } catch (final ArrayIndexOutOfBoundsException e) {
        throw new ParsingException("JSON does not exist", e);
    }
    if (trackInfo.size() <= 0) {
        // Albums without trackInfo need to be purchased before they can be played
        throw new ContentNotAvailableException("Album needs to be purchased");
    }
}
Also used : JsonParserException(com.grack.nanojson.JsonParserException) ParsingException(org.schabi.newpipe.extractor.exceptions.ParsingException) ContentNotAvailableException(org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException)

Example 29 with JsonParserException

use of com.grack.nanojson.JsonParserException in project NewPipeExtractor by TeamNewPipe.

the class MediaCCCSearchExtractor method onFetchPage.

@Override
public void onFetchPage(@Nonnull final Downloader downloader) throws IOException, ExtractionException {
    if (getLinkHandler().getContentFilters().contains(EVENTS) || getLinkHandler().getContentFilters().contains(ALL) || getLinkHandler().getContentFilters().isEmpty()) {
        final String site;
        final String url = getUrl();
        site = downloader.get(url, getExtractorLocalization()).responseBody();
        try {
            doc = JsonParser.object().from(site);
        } catch (JsonParserException jpe) {
            throw new ExtractionException("Could not parse JSON.", jpe);
        }
    }
    if (getLinkHandler().getContentFilters().contains(CONFERENCES) || getLinkHandler().getContentFilters().contains(ALL) || getLinkHandler().getContentFilters().isEmpty()) {
        conferenceKiosk.fetchPage();
    }
}
Also used : ExtractionException(org.schabi.newpipe.extractor.exceptions.ExtractionException) JsonParserException(com.grack.nanojson.JsonParserException)

Example 30 with JsonParserException

use of com.grack.nanojson.JsonParserException in project NewPipeExtractor by TeamNewPipe.

the class MediaCCCStreamExtractor method onFetchPage.

@Override
public void onFetchPage(@Nonnull final Downloader downloader) throws IOException, ExtractionException {
    final String videoUrl = MediaCCCStreamLinkHandlerFactory.VIDEO_API_ENDPOINT + getId();
    try {
        data = JsonParser.object().from(downloader.get(videoUrl).responseBody());
        conferenceData = JsonParser.object().from(downloader.get(data.getString("conference_url")).responseBody());
    } catch (JsonParserException jpe) {
        throw new ExtractionException("Could not parse json returned by url: " + videoUrl, jpe);
    }
}
Also used : ExtractionException(org.schabi.newpipe.extractor.exceptions.ExtractionException) JsonParserException(com.grack.nanojson.JsonParserException)

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