diff --git a/src/main/java/org/schabi/newpipe/extractor/ListExtractor.java b/src/main/java/org/schabi/newpipe/extractor/ListExtractor.java index d4746270b..584bb4283 100644 --- a/src/main/java/org/schabi/newpipe/extractor/ListExtractor.java +++ b/src/main/java/org/schabi/newpipe/extractor/ListExtractor.java @@ -69,9 +69,19 @@ public abstract class ListExtractor extends Extractor { */ public final String nextItemsUrl; - public NextItemsResult(List nextItemsList, String nextItemsUrl) { + /** + * Errors that happened during the extraction + */ + public final List errors; + + public NextItemsResult(InfoItemCollector collector, String nextItemsUrl) { + this(collector.getItemList(), nextItemsUrl, collector.getErrors()); + } + + public NextItemsResult(List nextItemsList, String nextItemsUrl, List errors) { this.nextItemsList = nextItemsList; this.nextItemsUrl = nextItemsUrl; + this.errors = errors; } public boolean hasMoreStreams() { diff --git a/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractor.java b/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractor.java index 42c1bd141..0097729f3 100644 --- a/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractor.java +++ b/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractor.java @@ -102,6 +102,6 @@ public class SoundcloudChannelExtractor extends ChannelExtractor { StreamInfoItemCollector collector = new StreamInfoItemCollector(getServiceId()); nextStreamsUrl = SoundcloudParsingHelper.getStreamsFromApiMinItems(15, collector, nextStreamsUrl); - return new NextItemsResult(collector.getItemList(), nextStreamsUrl); + return new NextItemsResult(collector, nextStreamsUrl); } } diff --git a/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractor.java b/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractor.java index 7be086fa1..17e2cf8a2 100644 --- a/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractor.java +++ b/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractor.java @@ -104,6 +104,6 @@ public class SoundcloudPlaylistExtractor extends PlaylistExtractor { StreamInfoItemCollector collector = new StreamInfoItemCollector(getServiceId()); nextStreamsUrl = SoundcloudParsingHelper.getStreamsFromApiMinItems(15, collector, nextStreamsUrl); - return new NextItemsResult(collector.getItemList(), nextStreamsUrl); + return new NextItemsResult(collector, nextStreamsUrl); } } diff --git a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractor.java b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractor.java index 35397a4e2..1250e48ef 100644 --- a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractor.java +++ b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractor.java @@ -153,7 +153,7 @@ public class YoutubeChannelExtractor extends ChannelExtractor { setupNextStreamsAjax(NewPipe.getDownloader()); collectStreamsFrom(collector, nextStreamsAjax.select("body").first()); - return new NextItemsResult(collector.getItemList(), nextStreamsUrl); + return new NextItemsResult(collector, nextStreamsUrl); } private void setupNextStreamsAjax(Downloader downloader) throws IOException, ReCaptchaException, ParsingException { diff --git a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractor.java b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractor.java index f03b6c0f2..9ec6eba46 100644 --- a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractor.java +++ b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractor.java @@ -157,7 +157,7 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor { setupNextStreamsAjax(NewPipe.getDownloader()); collectStreamsFrom(collector, nextStreamsAjax.select("tbody[id=\"pl-load-more-destination\"]").first()); - return new NextItemsResult(collector.getItemList(), nextStreamsUrl); + return new NextItemsResult(collector, nextStreamsUrl); } private void setupNextStreamsAjax(Downloader downloader) throws IOException, ReCaptchaException, ParsingException { diff --git a/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractorTest.java b/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractorTest.java index ef1e723e1..eae5afbb3 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractorTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractorTest.java @@ -3,6 +3,7 @@ package org.schabi.newpipe.extractor.services.soundcloud; import org.junit.Before; import org.junit.Test; import org.schabi.newpipe.Downloader; +import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.channel.ChannelExtractor; @@ -70,7 +71,9 @@ public class SoundcloudChannelExtractorTest { public void testGetNextStreams() throws Exception { // Setup the streams extractor.getStreams(); - assertTrue("extractor didn't have next streams", !extractor.getNextStreams().nextItemsList.isEmpty()); + ListExtractor.NextItemsResult nextItemsResult = extractor.getNextStreams(); + assertTrue("extractor didn't have next streams", !nextItemsResult.nextItemsList.isEmpty()); + assertTrue("errors occurred during extraction of the next streams", nextItemsResult.errors.isEmpty()); assertTrue("extractor didn't have more streams after getNextStreams", extractor.hasMoreStreams()); } diff --git a/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractorTest.java b/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractorTest.java index 480101055..c5956746a 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractorTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractorTest.java @@ -4,6 +4,7 @@ import org.junit.Before; import org.junit.Test; import org.schabi.newpipe.Downloader; import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.playlist.PlaylistExtractor; import static org.junit.Assert.*; @@ -79,4 +80,15 @@ public class SoundcloudPlaylistExtractorTest { extractor.getStreams(); assertTrue("extractor didn't have more streams", !extractor.hasMoreStreams()); } + + @Test(expected = ExtractionException.class) + public void testGetNextStreamsNonExistent() throws Exception { + // Setup the streams + extractor.getStreams(); + + // This playlist don't have more streams, it should throw an error + extractor.getNextStreams(); + + fail("Expected exception wasn't thrown"); + } } diff --git a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractorTest.java b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractorTest.java index 646c6be97..d346b972c 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractorTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractorTest.java @@ -3,6 +3,7 @@ package org.schabi.newpipe.extractor.services.youtube; import org.junit.Before; import org.junit.Test; import org.schabi.newpipe.Downloader; +import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.channel.ChannelExtractor; @@ -99,7 +100,9 @@ public class YoutubeChannelExtractorTest { public void testGetNextStreams() throws Exception { // Setup the streams extractor.getStreams(); - assertTrue("extractor didn't have next streams", !extractor.getNextStreams().nextItemsList.isEmpty()); + ListExtractor.NextItemsResult nextItemsResult = extractor.getNextStreams(); + assertTrue("extractor didn't have next streams", !nextItemsResult.nextItemsList.isEmpty()); + assertTrue("errors occurred during extraction of the next streams", nextItemsResult.errors.isEmpty()); assertTrue("extractor didn't have more streams after getNextStreams", extractor.hasMoreStreams()); } diff --git a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java index 5c1fbbd79..384f67f4c 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java @@ -3,6 +3,7 @@ package org.schabi.newpipe.extractor.services.youtube; import org.junit.Before; import org.junit.Test; import org.schabi.newpipe.Downloader; +import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.playlist.PlaylistExtractor; @@ -89,7 +90,9 @@ public class YoutubePlaylistExtractorTest { public void testGetNextStreams() throws Exception { // Setup the streams extractor.getStreams(); - assertTrue("extractor didn't have next streams", !extractor.getNextStreams().nextItemsList.isEmpty()); + ListExtractor.NextItemsResult nextItemsResult = extractor.getNextStreams(); + assertTrue("extractor didn't have next streams", !nextItemsResult.nextItemsList.isEmpty()); + assertTrue("errors occurred during extraction of the next streams", nextItemsResult.errors.isEmpty()); assertTrue("extractor didn't have more streams after getNextStreams", extractor.hasMoreStreams()); }