From bc3387926e70bbd6ae3ae440a7426c9545a8a652 Mon Sep 17 00:00:00 2001 From: TiA4f8R <74829229+TiA4f8R@users.noreply.github.com> Date: Sat, 26 Feb 2022 18:21:59 +0100 Subject: [PATCH] Adress new requested changes --- .../extractors/BandcampStreamExtractor.java | 12 ++--- .../MediaCCCLiveStreamExtractor.java | 52 ++++++++++--------- 2 files changed, 33 insertions(+), 31 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampStreamExtractor.java index d3f0706b91..99d01ab81c 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampStreamExtractor.java @@ -115,9 +115,9 @@ public DateWrapper getUploadDate() throws ParsingException { public String getThumbnailUrl() throws ParsingException { if (albumJson.isNull("art_id")) { return EMPTY_STRING; - } else { - return getImageUrl(albumJson.getLong("art_id"), true); } + + return getImageUrl(albumJson.getLong("art_id"), true); } @Nonnull @@ -178,11 +178,9 @@ public StreamType getStreamType() { public PlaylistInfoItemsCollector getRelatedItems() { final PlaylistInfoItemsCollector collector = new PlaylistInfoItemsCollector(getServiceId()); - final Elements recommendedAlbums = document.getElementsByClass("recommended-album"); - - for (final Element album : recommendedAlbums) { - collector.commit(new BandcampRelatedPlaylistInfoItemExtractor(album)); - } + document.getElementsByClass("recommended-album").stream() + .map(BandcampRelatedPlaylistInfoItemExtractor::new) + .forEach(collector::commit); return collector; } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCLiveStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCLiveStreamExtractor.java index 96b7e03bb8..47144844ba 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCLiveStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCLiveStreamExtractor.java @@ -104,17 +104,19 @@ public String getUploaderName() throws ParsingException { @Nonnull @Override public String getDashMpdUrl() throws ParsingException { - if (firstDashUrlFound == null) { - for (int s = 0; s < room.getArray("streams").size(); s++) { - final JsonObject stream = room.getArray("streams").getObject(s); - final JsonObject urls = stream.getObject("urls"); - if (urls.has("dash")) { - firstDashUrlFound = urls.getObject("dash").getString("url", EMPTY_STRING); - return firstDashUrlFound; - } + if (firstDashUrlFound != null) { + return firstDashUrlFound; + } + + for (int s = 0; s < room.getArray("streams").size(); s++) { + final JsonObject stream = room.getArray("streams").getObject(s); + final JsonObject urls = stream.getObject("urls"); + if (urls.has("dash")) { + firstDashUrlFound = urls.getObject("dash").getString("url", EMPTY_STRING); + return firstDashUrlFound; } - firstDashUrlFound = EMPTY_STRING; } + firstDashUrlFound = EMPTY_STRING; return firstDashUrlFound; } @@ -129,17 +131,19 @@ public String getDashMpdUrl() throws ParsingException { @Nonnull @Override public String getHlsUrl() { - if (firstHlsUrlFound == null) { - for (int s = 0; s < room.getArray("streams").size(); s++) { - final JsonObject stream = room.getArray("streams").getObject(s); - final JsonObject urls = stream.getObject("urls"); - if (urls.has("hls")) { - firstHlsUrlFound = urls.getObject("hls").getString("url", EMPTY_STRING); - return firstHlsUrlFound; - } + if (firstHlsUrlFound != null) { + return firstHlsUrlFound; + } + + for (int s = 0; s < room.getArray("streams").size(); s++) { + final JsonObject stream = room.getArray("streams").getObject(s); + final JsonObject urls = stream.getObject("urls"); + if (urls.has("hls")) { + firstHlsUrlFound = urls.getObject("hls").getString("url", EMPTY_STRING); + return firstHlsUrlFound; } - firstHlsUrlFound = EMPTY_STRING; } + firstHlsUrlFound = EMPTY_STRING; return firstHlsUrlFound; } @@ -149,7 +153,7 @@ public List getAudioStreams() throws IOException, ExtractionExcepti audioStreams = new ArrayList<>(); IntStream.range(0, room.getArray("streams").size()) .mapToObj(s -> room.getArray("streams").getObject(s)) - .filter(stream -> stream.getString("type").equals("audio")) + .filter(streamJsonObject -> streamJsonObject.getString("type").equals("audio")) .forEachOrdered(stream -> { for (final String type : stream.getObject("urls").keySet()) { final JsonObject urlObject = stream.getObject("urls").getObject(type); @@ -186,11 +190,11 @@ public List getVideoStreams() throws IOException, ExtractionExcepti IntStream.range(0, room.getArray("streams").size()) .mapToObj(s -> room.getArray("streams").getObject(s)) .filter(stream -> stream.getString("type").equals("video")) - .forEachOrdered(stream -> { - final String resolution = stream.getArray("videoSize").getInt(0) + "x" - + stream.getArray("videoSize").getInt(1); - for (final String type : stream.getObject("urls").keySet()) { - final JsonObject urlObject = stream.getObject("urls").getObject(type); + .forEachOrdered(streamJsonObject -> { + final String resolution = streamJsonObject.getArray("videoSize").getInt(0) + + "x" + streamJsonObject.getArray("videoSize").getInt(1); + for (final String type : streamJsonObject.getObject("urls").keySet()) { + final JsonObject urlObject = streamJsonObject.getObject("urls").getObject(type); // The DASH manifest will be extracted with getDashMpdUrl if (!type.equals("dash")) { if (type.equals("hls")) {