public static String getStreamsFromApi(StreamInfoItemsCollector collector, String apiUrl) throws ReCaptchaException, ParsingException, IOException { return getStreamsFromApi(collector, apiUrl, false); }
/** * Fetch the streams from the given api and commit each of them to the collector. * <p> * This differ from {@link #getStreamsFromApi(StreamInfoItemsCollector, String)} in the sense that they will always * get MIN_ITEMS or more items. * * @param minItems the method will return only when it have extracted that many items (equal or more) */ public static String getStreamsFromApiMinItems(int minItems, StreamInfoItemsCollector collector, String apiUrl) throws IOException, ReCaptchaException, ParsingException { String nextPageUrl = SoundcloudParsingHelper.getStreamsFromApi(collector, apiUrl); while (!nextPageUrl.isEmpty() && collector.getItems().size() < minItems) { nextPageUrl = SoundcloudParsingHelper.getStreamsFromApi(collector, nextPageUrl); } return nextPageUrl; }
@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")); } StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId()); String nextPageUrl = SoundcloudParsingHelper.getStreamsFromApi(collector, pageUrl, true); return new InfoItemsPage<>(collector, nextPageUrl); }
private void computNextPageAndStreams() throws IOException, ExtractionException { collector = new StreamInfoItemsCollector(getServiceId()); String apiUrl = "https://api-v2.soundcloud.com/charts" + "?genre=soundcloud:genres:all-music" + "&client_id=" + SoundcloudParsingHelper.clientId(); if (getId().equals("Top 50")) { apiUrl += "&kind=top"; } else { apiUrl += "&kind=trending"; } /*List<String> supportedCountries = Arrays.asList("AU", "CA", "FR", "DE", "IE", "NL", "NZ", "GB", "US"); String contentCountry = getContentCountry(); if (supportedCountries.contains(contentCountry)) { apiUrl += "®ion=soundcloud:regions:" + contentCountry; }*/ nextPageUrl = SoundcloudParsingHelper.getStreamsFromApi(collector, apiUrl, true); }
@Override public StreamInfoItemsCollector getRelatedStreams() throws IOException, ExtractionException { StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId()); String apiUrl = "https://api-v2.soundcloud.com/tracks/" + urlEncode(getId()) + "/related" + "?client_id=" + urlEncode(SoundcloudParsingHelper.clientId()); SoundcloudParsingHelper.getStreamsFromApi(collector, apiUrl); return collector; }