Skip to content

Commit 9184fc5

Browse files
committed
Store errors that can happen during extraction of the next page
- Closes #24
1 parent 82824cd commit 9184fc5

9 files changed

Lines changed: 39 additions & 8 deletions

File tree

src/main/java/org/schabi/newpipe/extractor/ListExtractor.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,19 @@ public static class NextItemsResult {
6969
*/
7070
public final String nextItemsUrl;
7171

72-
public NextItemsResult(List<InfoItem> nextItemsList, String nextItemsUrl) {
72+
/**
73+
* Errors that happened during the extraction
74+
*/
75+
public final List<Throwable> errors;
76+
77+
public NextItemsResult(InfoItemCollector collector, String nextItemsUrl) {
78+
this(collector.getItemList(), nextItemsUrl, collector.getErrors());
79+
}
80+
81+
public NextItemsResult(List<InfoItem> nextItemsList, String nextItemsUrl, List<Throwable> errors) {
7382
this.nextItemsList = nextItemsList;
7483
this.nextItemsUrl = nextItemsUrl;
84+
this.errors = errors;
7585
}
7686

7787
public boolean hasMoreStreams() {

src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,6 @@ public NextItemsResult getNextStreams() throws IOException, ExtractionException
102102
StreamInfoItemCollector collector = new StreamInfoItemCollector(getServiceId());
103103
nextStreamsUrl = SoundcloudParsingHelper.getStreamsFromApiMinItems(15, collector, nextStreamsUrl);
104104

105-
return new NextItemsResult(collector.getItemList(), nextStreamsUrl);
105+
return new NextItemsResult(collector, nextStreamsUrl);
106106
}
107107
}

src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,6 @@ public NextItemsResult getNextStreams() throws IOException, ExtractionException
104104
StreamInfoItemCollector collector = new StreamInfoItemCollector(getServiceId());
105105
nextStreamsUrl = SoundcloudParsingHelper.getStreamsFromApiMinItems(15, collector, nextStreamsUrl);
106106

107-
return new NextItemsResult(collector.getItemList(), nextStreamsUrl);
107+
return new NextItemsResult(collector, nextStreamsUrl);
108108
}
109109
}

src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public NextItemsResult getNextStreams() throws IOException, ExtractionException
153153
setupNextStreamsAjax(NewPipe.getDownloader());
154154
collectStreamsFrom(collector, nextStreamsAjax.select("body").first());
155155

156-
return new NextItemsResult(collector.getItemList(), nextStreamsUrl);
156+
return new NextItemsResult(collector, nextStreamsUrl);
157157
}
158158

159159
private void setupNextStreamsAjax(Downloader downloader) throws IOException, ReCaptchaException, ParsingException {

src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public NextItemsResult getNextStreams() throws IOException, ExtractionException
157157
setupNextStreamsAjax(NewPipe.getDownloader());
158158
collectStreamsFrom(collector, nextStreamsAjax.select("tbody[id=\"pl-load-more-destination\"]").first());
159159

160-
return new NextItemsResult(collector.getItemList(), nextStreamsUrl);
160+
return new NextItemsResult(collector, nextStreamsUrl);
161161
}
162162

163163
private void setupNextStreamsAjax(Downloader downloader) throws IOException, ReCaptchaException, ParsingException {

src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractorTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.junit.Before;
44
import org.junit.Test;
55
import org.schabi.newpipe.Downloader;
6+
import org.schabi.newpipe.extractor.ListExtractor;
67
import org.schabi.newpipe.extractor.NewPipe;
78
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
89

@@ -70,7 +71,9 @@ public void testGetSubscriberCount() throws Exception {
7071
public void testGetNextStreams() throws Exception {
7172
// Setup the streams
7273
extractor.getStreams();
73-
assertTrue("extractor didn't have next streams", !extractor.getNextStreams().nextItemsList.isEmpty());
74+
ListExtractor.NextItemsResult nextItemsResult = extractor.getNextStreams();
75+
assertTrue("extractor didn't have next streams", !nextItemsResult.nextItemsList.isEmpty());
76+
assertTrue("errors occurred during extraction of the next streams", nextItemsResult.errors.isEmpty());
7477
assertTrue("extractor didn't have more streams after getNextStreams", extractor.hasMoreStreams());
7578
}
7679

src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractorTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.junit.Test;
55
import org.schabi.newpipe.Downloader;
66
import org.schabi.newpipe.extractor.NewPipe;
7+
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
78
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
89

910
import static org.junit.Assert.*;
@@ -79,4 +80,15 @@ public void testHasMoreStreams() throws Exception {
7980
extractor.getStreams();
8081
assertTrue("extractor didn't have more streams", !extractor.hasMoreStreams());
8182
}
83+
84+
@Test(expected = ExtractionException.class)
85+
public void testGetNextStreamsNonExistent() throws Exception {
86+
// Setup the streams
87+
extractor.getStreams();
88+
89+
// This playlist don't have more streams, it should throw an error
90+
extractor.getNextStreams();
91+
92+
fail("Expected exception wasn't thrown");
93+
}
8294
}

src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractorTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.junit.Before;
44
import org.junit.Test;
55
import org.schabi.newpipe.Downloader;
6+
import org.schabi.newpipe.extractor.ListExtractor;
67
import org.schabi.newpipe.extractor.NewPipe;
78
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
89

@@ -99,7 +100,9 @@ public void testGetSubscriberCount() throws Exception {
99100
public void testGetNextStreams() throws Exception {
100101
// Setup the streams
101102
extractor.getStreams();
102-
assertTrue("extractor didn't have next streams", !extractor.getNextStreams().nextItemsList.isEmpty());
103+
ListExtractor.NextItemsResult nextItemsResult = extractor.getNextStreams();
104+
assertTrue("extractor didn't have next streams", !nextItemsResult.nextItemsList.isEmpty());
105+
assertTrue("errors occurred during extraction of the next streams", nextItemsResult.errors.isEmpty());
103106
assertTrue("extractor didn't have more streams after getNextStreams", extractor.hasMoreStreams());
104107
}
105108

src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.junit.Before;
44
import org.junit.Test;
55
import org.schabi.newpipe.Downloader;
6+
import org.schabi.newpipe.extractor.ListExtractor;
67
import org.schabi.newpipe.extractor.NewPipe;
78
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
89

@@ -89,7 +90,9 @@ public void testHasMoreStreams() throws Exception {
8990
public void testGetNextStreams() throws Exception {
9091
// Setup the streams
9192
extractor.getStreams();
92-
assertTrue("extractor didn't have next streams", !extractor.getNextStreams().nextItemsList.isEmpty());
93+
ListExtractor.NextItemsResult nextItemsResult = extractor.getNextStreams();
94+
assertTrue("extractor didn't have next streams", !nextItemsResult.nextItemsList.isEmpty());
95+
assertTrue("errors occurred during extraction of the next streams", nextItemsResult.errors.isEmpty());
9396
assertTrue("extractor didn't have more streams after getNextStreams", extractor.hasMoreStreams());
9497
}
9598

0 commit comments

Comments
 (0)