From e101d58ae76ba09d48c341235f63767ef1d81969 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Tue, 9 Aug 2022 08:21:39 +0530 Subject: [PATCH 1/6] Use EnumMap in PatternsHolder. --- .../newpipe/extractor/timeago/PatternsHolder.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/timeago-parser/src/main/java/org/schabi/newpipe/extractor/timeago/PatternsHolder.java b/timeago-parser/src/main/java/org/schabi/newpipe/extractor/timeago/PatternsHolder.java index f7dc99630..1e87f202d 100644 --- a/timeago-parser/src/main/java/org/schabi/newpipe/extractor/timeago/PatternsHolder.java +++ b/timeago-parser/src/main/java/org/schabi/newpipe/extractor/timeago/PatternsHolder.java @@ -1,12 +1,13 @@ package org.schabi.newpipe.extractor.timeago; +import static java.util.Arrays.asList; + import java.time.temporal.ChronoUnit; import java.util.Collection; +import java.util.EnumMap; import java.util.LinkedHashMap; import java.util.Map; -import static java.util.Arrays.asList; - public abstract class PatternsHolder { private final String wordSeparator; private final Collection seconds; @@ -17,7 +18,8 @@ public abstract class PatternsHolder { private final Collection months; private final Collection years; - private final Map> specialCases = new LinkedHashMap<>(); + private final Map> specialCases = + new EnumMap<>(ChronoUnit.class); protected PatternsHolder(String wordSeparator, Collection seconds, Collection minutes, Collection hours, Collection days, @@ -81,7 +83,7 @@ public abstract class PatternsHolder { } public Map> asMap() { - final Map> returnMap = new LinkedHashMap<>(); + final Map> returnMap = new EnumMap<>(ChronoUnit.class); returnMap.put(ChronoUnit.SECONDS, seconds()); returnMap.put(ChronoUnit.MINUTES, minutes()); returnMap.put(ChronoUnit.HOURS, hours()); From 0e31c86aee8f81e57233cbaec5c822781cebf906 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Wed, 21 Sep 2022 05:40:07 +0530 Subject: [PATCH 2/6] Avoid possible NullPointerException in MediaCCCRecentKiosk. --- .../media_ccc/extractors/MediaCCCRecentKiosk.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCRecentKiosk.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCRecentKiosk.java index 27c1ce9a1..94d3b0a62 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCRecentKiosk.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCRecentKiosk.java @@ -12,6 +12,7 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.kiosk.KioskExtractor; import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler; +import org.schabi.newpipe.extractor.localization.DateWrapper; import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; @@ -49,12 +50,12 @@ public class MediaCCCRecentKiosk extends KioskExtractor { // Streams in the recent kiosk are not ordered by the release date. // Sort them to have the latest stream at the beginning of the list. - Comparator comparator = Comparator.comparing( - streamInfoItem -> streamInfoItem.getUploadDate().offsetDateTime()); - comparator = comparator.reversed(); - - final StreamInfoItemsCollector collector = - new StreamInfoItemsCollector(getServiceId(), comparator); + final Comparator comparator = Comparator + .comparing(StreamInfoItem::getUploadDate, Comparator + .nullsLast(Comparator.comparing(DateWrapper::offsetDateTime))) + .reversed(); + final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId(), + comparator); events.stream() .filter(JsonObject.class::isInstance) From bf70d32eb4ae58e417b419f57cc75381a2d6bc0a Mon Sep 17 00:00:00 2001 From: TurtleArmyMc <44322335+TurtleArmyMc@users.noreply.github.com> Date: Fri, 30 Sep 2022 15:25:10 -0400 Subject: [PATCH 3/6] Fix SoundcloudPlaylistExtractor: tracks are in correct order --- .../SoundcloudPlaylistExtractor.java | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudPlaylistExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudPlaylistExtractor.java index d308eb831..d62522791 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudPlaylistExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudPlaylistExtractor.java @@ -1,13 +1,9 @@ package org.schabi.newpipe.extractor.services.soundcloud.extractors; -import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL; -import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; - import com.grack.nanojson.JsonArray; import com.grack.nanojson.JsonObject; import com.grack.nanojson.JsonParser; import com.grack.nanojson.JsonParserException; - import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.Page; import org.schabi.newpipe.extractor.StreamingService; @@ -20,11 +16,15 @@ import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper; import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; +import javax.annotation.Nonnull; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Objects; -import javax.annotation.Nonnull; +import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL; +import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; public class SoundcloudPlaylistExtractor extends PlaylistExtractor { private static final int STREAMS_PER_REQUESTED_PAGE = 15; @@ -171,9 +171,25 @@ public class SoundcloudPlaylistExtractor extends PlaylistExtractor { try { final JsonArray tracks = JsonParser.array().from(response); + // Response may not contain tracks in the same order as currentIds + final HashMap idToTrack = new HashMap<>(); for (final Object track : tracks) { if (track instanceof JsonObject) { - collector.commit(new SoundcloudStreamInfoItemExtractor((JsonObject) track)); + final JsonObject o = (JsonObject) track; + idToTrack.put(o.getInt("id"), o); + } + } + for (final String strId : currentIds) { + final int id = Integer.parseInt(strId); + try { + collector.commit(new SoundcloudStreamInfoItemExtractor( + Objects.requireNonNull( + idToTrack.get(id), + "no track with id " + id + " in response" + ) + )); + } catch (final NullPointerException e) { + throw new ParsingException("Could not parse json response", e); } } } catch (final JsonParserException e) { From 719664593ffd84ad8dca88f0a1f4aa46352dcb28 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 10 Oct 2022 09:25:42 +0000 Subject: [PATCH 4/6] Bump junit-bom from 5.9.0 to 5.9.1 Bumps [junit-bom](https://github.com/junit-team/junit5) from 5.9.0 to 5.9.1. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.9.0...r5.9.1) --- updated-dependencies: - dependency-name: org.junit:junit-bom dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 0e66a245e..4b94a5f8d 100644 --- a/build.gradle +++ b/build.gradle @@ -29,7 +29,7 @@ allprojects { ext { nanojsonVersion = "1d9e1aea9049fc9f85e68b43ba39fe7be1c1f751" spotbugsVersion = "4.7.1" - junitVersion = "5.9.0" + junitVersion = "5.9.1" checkstyleVersion = "9.3" // do not use latest version (10.0) as it requires compile JDK 11 } } From 08339d6b0c7c6030ee76ab544e72fb7ff1c1f3d1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 10 Oct 2022 09:32:17 +0000 Subject: [PATCH 5/6] Bump spotbugs-annotations from 4.7.1 to 4.7.2 Bumps [spotbugs-annotations](https://github.com/spotbugs/spotbugs) from 4.7.1 to 4.7.2. - [Release notes](https://github.com/spotbugs/spotbugs/releases) - [Changelog](https://github.com/spotbugs/spotbugs/blob/master/CHANGELOG.md) - [Commits](https://github.com/spotbugs/spotbugs/compare/4.7.1...4.7.2) --- updated-dependencies: - dependency-name: com.github.spotbugs:spotbugs-annotations dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 4b94a5f8d..74c12f80e 100644 --- a/build.gradle +++ b/build.gradle @@ -28,7 +28,7 @@ allprojects { ext { nanojsonVersion = "1d9e1aea9049fc9f85e68b43ba39fe7be1c1f751" - spotbugsVersion = "4.7.1" + spotbugsVersion = "4.7.2" junitVersion = "5.9.1" checkstyleVersion = "9.3" // do not use latest version (10.0) as it requires compile JDK 11 } From 02810a7db7f1d5cf017b72b5a8a7809624cb5663 Mon Sep 17 00:00:00 2001 From: TobiGr Date: Mon, 10 Oct 2022 22:22:12 +0200 Subject: [PATCH 6/6] Add a comment --- .../soundcloud/extractors/SoundcloudPlaylistExtractor.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudPlaylistExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudPlaylistExtractor.java index d62522791..13f1f1400 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudPlaylistExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudPlaylistExtractor.java @@ -171,7 +171,8 @@ public class SoundcloudPlaylistExtractor extends PlaylistExtractor { try { final JsonArray tracks = JsonParser.array().from(response); - // Response may not contain tracks in the same order as currentIds + // Response may not contain tracks in the same order as currentIds. + // The streams are displayed in the order which is used in currentIds on SoundCloud. final HashMap idToTrack = new HashMap<>(); for (final Object track : tracks) { if (track instanceof JsonObject) {