outerJsonObject = JsonParser.object().from(tabsJson); final JsonArray tabsArray = outerJsonObject.getArray(JSON_TABS_ARRAY_KEY);
@Override public List<String> suggestionList(String query) throws IOException, ExtractionException { Downloader dl = NewPipe.getDownloader(); List<String> suggestions = new ArrayList<>(); String url = "https://suggestqueries.google.com/complete/search" + "?client=" + "youtube" //"firefox" for JSON, 'toolbar' for xml + "&jsonp=" + "JP" + "&ds=" + "yt" + "&hl=" + URLEncoder.encode(getLocalization().getCountry(), CHARSET_UTF_8) + "&q=" + URLEncoder.encode(query, CHARSET_UTF_8); String response = dl.download(url); // trim JSONP part "JP(...)" response = response.substring(3, response.length()-1); try { JsonArray collection = JsonParser.array().from(response).getArray(1, new JsonArray()); for (Object suggestion : collection) { if (!(suggestion instanceof JsonArray)) continue; String suggestionStr = ((JsonArray)suggestion).getString(0); if (suggestionStr == null) continue; suggestions.add(suggestionStr); } return suggestions; } catch (JsonParserException e) { throw new ParsingException("Could not parse json response", e); } } }
JsonObject parentObject = JsonParser.object().from(in); JsonArray channelsArray = parentObject.getArray(JSON_SUBSCRIPTIONS_ARRAY_KEY); if (eventListener != null) eventListener.onSizeReceived(channelsArray.size());
private boolean isTabsArrayEmpty(String returnedJson) throws JsonParserException { JsonObject jsonObject = JsonParser.object().from(returnedJson); assertTrue(jsonObject.containsKey(JSON_TABS_ARRAY_KEY)); return jsonObject.getArray(JSON_TABS_ARRAY_KEY).size() == 0; }
final JsonObject jsonObject = JsonParser.object().from(returnedJson); assertTrue(jsonObject.containsKey(JSON_TABS_ARRAY_KEY)); final JsonArray tabsFromArray = jsonObject.getArray(JSON_TABS_ARRAY_KEY);
/** * Call the endpoint "/resolve" of the api.<p> * * See https://developers.soundcloud.com/docs/api/reference#resolve */ public static JsonObject resolveFor(Downloader downloader, String url) throws IOException, ReCaptchaException, ParsingException { String apiUrl = "https://api.soundcloud.com/resolve" + "?url=" + URLEncoder.encode(url, "UTF-8") + "&client_id=" + clientId(); try { return JsonParser.object().from(downloader.download(apiUrl)); } catch (JsonParserException e) { throw new ParsingException("Could not parse json response", e); } }
@Benchmark @Override public Object nanojson() throws Exception { return com.grack.nanojson.JsonParser.object().from(JSON_SOURCE().nextInputStream()); }
@Override public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException { userId = getLinkHandler().getId(); String apiUrl = "https://api-v2.soundcloud.com/users/" + userId + "?client_id=" + SoundcloudParsingHelper.clientId(); String response = downloader.download(apiUrl); try { user = JsonParser.object().from(response); } catch (JsonParserException e) { throw new ParsingException("Could not parse json response", e); } }
@Override public List<String> suggestionList(String query) throws IOException, ExtractionException { List<String> suggestions = new ArrayList<>(); Downloader dl = NewPipe.getDownloader(); String url = "https://api-v2.soundcloud.com/search/queries" + "?q=" + URLEncoder.encode(query, CHARSET_UTF_8) + "&client_id=" + SoundcloudParsingHelper.clientId() + "&limit=10"; String response = dl.download(url); try { JsonArray collection = JsonParser.object().from(response).getArray("collection"); for (Object suggestion : collection) { if (suggestion instanceof JsonObject) suggestions.add(((JsonObject) suggestion).getString("query")); } return suggestions; } catch (JsonParserException e) { throw new ParsingException("Could not parse json response", e); } } }
@Override public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException { playlistId = getLinkHandler().getId(); String apiUrl = "https://api.soundcloud.com/playlists/" + playlistId + "?client_id=" + SoundcloudParsingHelper.clientId() + "&representation=compact"; String response = downloader.download(apiUrl); try { playlist = JsonParser.object().from(response); } catch (JsonParserException e) { throw new ParsingException("Could not parse json response", e); } }
@Override public InfoItemsPage<StreamInfoItem> getPage(final String pageUrl) throws IOException, ExtractionException { if (pageUrl == null || pageUrl.isEmpty()) { throw new ExtractionException(new IllegalArgumentException("Page url is empty or null")); } StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId()); JsonObject pageJson; try { pageJson = JsonParser.object().from(getDownloader().download(pageUrl)); } catch (JsonParserException pe) { throw new ParsingException("Could not parse ajax json", pe); } final Document pageHtml = Jsoup.parse("<table><tbody id=\"pl-load-more-destination\">" + pageJson.getString("content_html") + "</tbody></table>", pageUrl); collectStreamsFrom(collector, pageHtml.select("tbody[id=\"pl-load-more-destination\"]").first()); return new InfoItemsPage<>(collector, getNextPageUrlFromAjax(pageJson, pageUrl)); }
@Override public InfoItemsPage<StreamInfoItem> getPage(String pageUrl) throws IOException, ExtractionException { if (pageUrl == null || pageUrl.isEmpty()) { throw new ExtractionException(new IllegalArgumentException("Page url is empty or null")); } // Unfortunately, we have to fetch the page even if we are only getting next streams, // as they don't deliver enough information on their own (the channel name, for example). fetchPage(); StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId()); JsonObject ajaxJson; try { ajaxJson = JsonParser.object().from(NewPipe.getDownloader().download(pageUrl)); } catch (JsonParserException pe) { throw new ParsingException("Could not parse json data for next streams", pe); } final Document ajaxHtml = Jsoup.parse(ajaxJson.getString("content_html"), pageUrl); collectStreamsFrom(collector, ajaxHtml.select("body").first()); return new InfoItemsPage<>(collector, getNextPageUrlFromAjaxPage(ajaxJson, pageUrl)); }
@Override public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException { final Downloader dl = getDownloader(); final String url = getUrl(); try { searchCollection = JsonParser.object().from(dl.download(url)).getArray("collection"); } catch (JsonParserException e) { throw new ParsingException("Could not parse json response", e); } if (searchCollection.size() == 0) { throw new SearchExtractor.NothingFoundException("Nothing found"); } }
@Override public List<AudioStream> getAudioStreams() throws IOException, ExtractionException { List<AudioStream> audioStreams = new ArrayList<>(); Downloader dl = NewPipe.getDownloader(); String apiUrl = "https://api.soundcloud.com/i1/tracks/" + urlEncode(getId()) + "/streams" + "?client_id=" + urlEncode(SoundcloudParsingHelper.clientId()); String response = dl.download(apiUrl); JsonObject responseObject; try { responseObject = JsonParser.object().from(response); } catch (JsonParserException e) { throw new ParsingException("Could not parse json response", e); } String mp3Url = responseObject.getString("http_mp3_128_url"); if (mp3Url != null && !mp3Url.isEmpty()) { audioStreams.add(new AudioStream(mp3Url, MediaFormat.MP3, 128)); } else { throw new ExtractionException("Could not get SoundCloud's track audio url"); } return audioStreams; }
@Nonnull @Override public String getHlsUrl() throws ParsingException { assertPageFetched(); try { String hlsvp = ""; if (playerArgs != null) { if( playerArgs.isString("hlsvp") ) { hlsvp = playerArgs.getString("hlsvp", ""); }else { hlsvp = JsonParser.object() .from(playerArgs.getString("player_response", "{}")) .getObject("streamingData", new JsonObject()) .getString("hlsManifestUrl", ""); } } return hlsvp; } catch (Exception e) { throw new ParsingException("Could not get hls manifest url", e); } }
@Override public InfoItemsPage<InfoItem> getPage(String pageUrl) throws IOException, ExtractionException { final Downloader dl = getDownloader(); try { searchCollection = JsonParser.object().from(dl.download(pageUrl)).getArray("collection"); } catch (JsonParserException e) { throw new ParsingException("Could not parse json response", e); } return new InfoItemsPage<>(collectItems(searchCollection), getNextPageUrlFromCurrentUrl(pageUrl)); }
private JsonObject getPlayerConfig(String pageContent) throws ParsingException { try { String ytPlayerConfigRaw = Parser.matchGroup1("ytplayer.config\\s*=\\s*(\\{.*?\\});", pageContent); return JsonParser.object().from(ytPlayerConfigRaw); } catch (Parser.RegexException e) { String errorReason = getErrorMessage(); switch (errorReason) { case "GEMA": throw new GemaException(errorReason); case "": throw new ContentNotAvailableException("Content not available: player config empty", e); default: throw new ContentNotAvailableException("Content not available", e); } } catch (Exception e) { throw new ParsingException("Could not parse yt player config", e); } }
/** * Fetch the user items 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 getUsersFromApi(ChannelInfoItemsCollector collector, String apiUrl) throws IOException, ReCaptchaException, ParsingException { String response = NewPipe.getDownloader().download(apiUrl); JsonObject responseObject; try { responseObject = JsonParser.object().from(response); } catch (JsonParserException e) { throw new ParsingException("Could not parse json response", e); } JsonArray responseCollection = responseObject.getArray("collection"); for (Object o : responseCollection) { if (o instanceof JsonObject) { JsonObject object = (JsonObject) o; collector.commit(new SoundcloudChannelInfoItemExtractor(object)); } } String nextPageUrl; try { nextPageUrl = responseObject.getString("next_href"); if (!nextPageUrl.contains("client_id=")) nextPageUrl += "&client_id=" + SoundcloudParsingHelper.clientId(); } catch (Exception ignored) { nextPageUrl = ""; } return nextPageUrl; }
/** * 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(StreamInfoItemsCollector collector, String apiUrl, boolean charts) throws IOException, ReCaptchaException, ParsingException { String response = NewPipe.getDownloader().download(apiUrl); JsonObject responseObject; try { responseObject = JsonParser.object().from(response); } catch (JsonParserException e) { throw new ParsingException("Could not parse json response", e); } JsonArray responseCollection = responseObject.getArray("collection"); for (Object o : responseCollection) { if (o instanceof JsonObject) { 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 (Exception ignored) { nextPageUrl = ""; } return nextPageUrl; }