use of com.grack.nanojson.JsonParserException in project NewPipeExtractor by TeamNewPipe.
the class BandcampChannelLinkHandlerFactory method getId.
@Override
public String getId(final String url) throws ParsingException {
try {
final String response = NewPipe.getDownloader().get(url).responseBody();
// Use band data embedded in website to extract ID
final JsonObject bandData = JsonUtils.getJsonData(response, "data-band");
return String.valueOf(bandData.getLong("id"));
} catch (final IOException | ReCaptchaException | ArrayIndexOutOfBoundsException | JsonParserException e) {
throw new ParsingException("Download failed", e);
}
}
use of com.grack.nanojson.JsonParserException in project NewPipeExtractor by TeamNewPipe.
the class PeertubeAccountExtractor method getSubscriberCount.
@Override
public long getSubscriberCount() throws ParsingException {
// The subscriber count cannot be retrieved directly. It needs to be calculated.
// An accounts subscriber count is the number of the channel owner's subscriptions
// plus the sum of all sub channels subscriptions.
long subscribersCount = json.getLong("followersCount");
String accountVideoChannelUrl = baseUrl + PeertubeChannelLinkHandlerFactory.API_ENDPOINT;
if (getId().contains(ACCOUNTS)) {
accountVideoChannelUrl += getId();
} else {
accountVideoChannelUrl += ACCOUNTS + getId();
}
accountVideoChannelUrl += "/video-channels";
try {
final String responseBody = getDownloader().get(accountVideoChannelUrl).responseBody();
final JsonObject jsonResponse = JsonParser.object().from(responseBody);
final JsonArray videoChannels = jsonResponse.getArray("data");
for (final Object videoChannel : videoChannels) {
final JsonObject videoChannelJsonObject = (JsonObject) videoChannel;
subscribersCount += videoChannelJsonObject.getInt("followersCount");
}
} catch (final IOException | JsonParserException | ReCaptchaException ignored) {
// something went wrong during video channels extraction, only return subscribers of ownerAccount
}
return subscribersCount;
}
use of com.grack.nanojson.JsonParserException in project NewPipeExtractor by TeamNewPipe.
the class PeertubeStreamExtractor method getStreamsFromApi.
private void getStreamsFromApi(final StreamInfoItemsCollector collector, final String apiUrl) throws ReCaptchaException, IOException, ParsingException {
final Response response = getDownloader().get(apiUrl);
JsonObject relatedVideosJson = null;
if (response != null && !Utils.isBlank(response.responseBody())) {
try {
relatedVideosJson = JsonParser.object().from(response.responseBody());
} catch (JsonParserException e) {
throw new ParsingException("Could not parse json data for related videos", e);
}
}
if (relatedVideosJson != null) {
collectStreamsFrom(collector, relatedVideosJson);
}
}
use of com.grack.nanojson.JsonParserException in project NewPipeExtractor by TeamNewPipe.
the class SoundcloudParsingHelper method getStreamsFromApi.
/**
* Fetch the streams from the given API and commit each of them to the collector.
*
* @return the next streams url, empty if don't have
*/
public static String getStreamsFromApi(final StreamInfoItemsCollector collector, final String apiUrl, final boolean charts) throws IOException, ReCaptchaException, ParsingException {
final Response response = NewPipe.getDownloader().get(apiUrl, SoundCloud.getLocalization());
if (response.responseCode() >= 400) {
throw new IOException("Could not get streams from API, HTTP " + response.responseCode());
}
final JsonObject responseObject;
try {
responseObject = JsonParser.object().from(response.responseBody());
} catch (final JsonParserException e) {
throw new ParsingException("Could not parse json response", e);
}
final JsonArray responseCollection = responseObject.getArray("collection");
for (final Object o : responseCollection) {
if (o instanceof JsonObject) {
final JsonObject object = (JsonObject) o;
collector.commit(new SoundcloudStreamInfoItemExtractor(charts ? object.getObject("track") : object));
}
}
String nextPageUrl;
try {
nextPageUrl = responseObject.getString("next_href");
if (!nextPageUrl.contains("client_id="))
nextPageUrl += "&client_id=" + SoundcloudParsingHelper.clientId();
} catch (final Exception ignored) {
nextPageUrl = "";
}
return nextPageUrl;
}
use of com.grack.nanojson.JsonParserException in project NewPipeExtractor by TeamNewPipe.
the class MediaCCCParsingHelper method getLiveStreams.
/**
* Get currently available live streams from
* <a href="https://streaming.media.ccc.de/streams/v2.json">https://streaming.media.ccc.de/streams/v2.json</a>.
* Use this method to cache requests, because they can get quite big.
* TODO: implement better caching policy (max-age: 3 min)
* @param downloader The downloader to use for making the request
* @param localization The localization to be used. Will most likely be ignored.
* @return {@link JsonArray} containing current conferences and info about their rooms and streams.
* @throws ExtractionException if the data could not be fetched or the retrieved data could not be parsed to a {@link JsonArray}
*/
public static JsonArray getLiveStreams(final Downloader downloader, final Localization localization) throws ExtractionException {
if (liveStreams == null) {
try {
final String site = downloader.get("https://streaming.media.ccc.de/streams/v2.json", localization).responseBody();
liveStreams = JsonParser.array().from(site);
} catch (IOException | ReCaptchaException e) {
throw new ExtractionException("Could not get live stream JSON.", e);
} catch (JsonParserException e) {
throw new ExtractionException("Could not parse JSON.", e);
}
}
return liveStreams;
}
Aggregations