Skip to content

Commit e3bfdba

Browse files
committed
Remove getNextPageUrl() function from ListExtractor
1 parent 54d9e5a commit e3bfdba

29 files changed

Lines changed: 269 additions & 487 deletions

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
* Base class to extractors that have a list (e.g. playlists, users).
1717
*/
1818
public abstract class ListExtractor<R extends InfoItem> extends Extractor {
19-
2019
/**
2120
* Constant that should be returned whenever
2221
* a list has an unknown number of items.
@@ -46,29 +45,15 @@ public ListExtractor(StreamingService service, ListLinkHandler linkHandler) {
4645
@Nonnull
4746
public abstract InfoItemsPage<R> getInitialPage() throws IOException, ExtractionException;
4847

49-
/**
50-
* Returns an url that can be used to get the next page relative to the initial one.
51-
* <p>Usually, these links will only work in the implementation itself.</p>
52-
*
53-
* @return an url pointing to the next page relative to the initial page
54-
* @see #getPage(String)
55-
*/
56-
public abstract String getNextPageUrl() throws IOException, ExtractionException;
57-
5848
/**
5949
* Get a list of items corresponding to the specific requested page.
6050
*
6151
* @param pageUrl any page url got from the exclusive implementation of the list extractor
6252
* @return a {@link InfoItemsPage} corresponding to the requested page
63-
* @see #getNextPageUrl()
6453
* @see InfoItemsPage#getNextPageUrl()
6554
*/
6655
public abstract InfoItemsPage<R> getPage(final String pageUrl) throws IOException, ExtractionException;
6756

68-
public boolean hasNextPage() throws IOException, ExtractionException {
69-
return !isNullOrEmpty(getNextPageUrl());
70-
}
71-
7257
@Override
7358
public ListLinkHandler getLinkHandler() {
7459
return (ListLinkHandler) super.getLinkHandler();
@@ -140,5 +125,4 @@ public List<Throwable> getErrors() {
140125
return errors;
141126
}
142127
}
143-
144128
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCConferenceExtractor.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,6 @@ public InfoItemsPage<StreamInfoItem> getInitialPage() {
7878
return new InfoItemsPage<>(collector, null);
7979
}
8080

81-
@Override
82-
public String getNextPageUrl() {
83-
return null;
84-
}
85-
8681
@Override
8782
public InfoItemsPage<StreamInfoItem> getPage(final String pageUrl) {
8883
return null;

extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCConferenceKiosk.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ public InfoItemsPage<ChannelInfoItem> getInitialPage() {
4040
return new InfoItemsPage<>(collector, "");
4141
}
4242

43-
@Override
44-
public String getNextPageUrl() {
45-
return "";
46-
}
47-
4843
@Override
4944
public InfoItemsPage<ChannelInfoItem> getPage(final String pageUrl) {
5045
return InfoItemsPage.emptyPage();

extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCSearchExtractor.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,6 @@ public InfoItemsPage<InfoItem> getInitialPage() {
7979
return new InfoItemsPage<>(searchItems, null);
8080
}
8181

82-
@Override
83-
public String getNextPageUrl() {
84-
return "";
85-
}
86-
8782
@Override
8883
public InfoItemsPage<InfoItem> getPage(final String pageUrl) {
8984
return InfoItemsPage.emptyPage();

extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeAccountExtractor.java

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,21 @@
2020

2121
import java.io.IOException;
2222

23-
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.*;
23+
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.COUNT_KEY;
24+
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.ITEMS_PER_PAGE;
25+
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.START_KEY;
2426

2527
public class PeertubeAccountExtractor extends ChannelExtractor {
26-
27-
private InfoItemsPage<StreamInfoItem> initPage;
28-
private long total;
29-
3028
private JsonObject json;
3129
private final String baseUrl;
3230

33-
public PeertubeAccountExtractor(StreamingService service, ListLinkHandler linkHandler) throws ParsingException {
31+
public PeertubeAccountExtractor(final StreamingService service, final ListLinkHandler linkHandler) throws ParsingException {
3432
super(service, linkHandler);
3533
this.baseUrl = getBaseUrl();
3634
}
3735

3836
@Override
39-
public String getAvatarUrl() throws ParsingException {
37+
public String getAvatarUrl() {
4038
String value;
4139
try {
4240
value = JsonUtils.getString(json, "avatar.path");
@@ -47,7 +45,7 @@ public String getAvatarUrl() throws ParsingException {
4745
}
4846

4947
@Override
50-
public String getBannerUrl() throws ParsingException {
48+
public String getBannerUrl() {
5149
return null;
5250
}
5351

@@ -58,12 +56,12 @@ public String getFeedUrl() throws ParsingException {
5856

5957
@Override
6058
public long getSubscriberCount() throws ParsingException {
61-
Number number = JsonUtils.getNumber(json, "followersCount");
59+
final Number number = JsonUtils.getNumber(json, "followersCount");
6260
return number.longValue();
6361
}
6462

6563
@Override
66-
public String getDescription() throws ParsingException {
64+
public String getDescription() {
6765
try {
6866
return JsonUtils.getString(json, "description");
6967
} catch (ParsingException e) {
@@ -72,53 +70,46 @@ public String getDescription() throws ParsingException {
7270
}
7371

7472
@Override
75-
public String getParentChannelName() throws ParsingException {
73+
public String getParentChannelName() {
7674
return "";
7775
}
7876

7977
@Override
80-
public String getParentChannelUrl() throws ParsingException {
78+
public String getParentChannelUrl() {
8179
return "";
8280
}
8381

8482
@Override
85-
public String getParentChannelAvatarUrl() throws ParsingException {
83+
public String getParentChannelAvatarUrl() {
8684
return "";
8785
}
8886

8987
@Override
9088
public InfoItemsPage<StreamInfoItem> getInitialPage() throws IOException, ExtractionException {
91-
super.fetchPage();
92-
return initPage;
89+
final String pageUrl = getUrl() + "/videos?" + START_KEY + "=0&" + COUNT_KEY + "=" + ITEMS_PER_PAGE;
90+
return getPage(pageUrl);
9391
}
9492

95-
private void collectStreamsFrom(StreamInfoItemsCollector collector, JsonObject json, String pageUrl) throws ParsingException {
96-
JsonArray contents;
93+
private void collectStreamsFrom(StreamInfoItemsCollector collector, JsonObject json) throws ParsingException {
94+
final JsonArray contents;
9795
try {
9896
contents = (JsonArray) JsonUtils.getValue(json, "data");
9997
} catch (Exception e) {
10098
throw new ParsingException("unable to extract channel streams", e);
10199
}
102100

103-
for (Object c : contents) {
101+
for (final Object c : contents) {
104102
if (c instanceof JsonObject) {
105103
final JsonObject item = (JsonObject) c;
106-
PeertubeStreamInfoItemExtractor extractor = new PeertubeStreamInfoItemExtractor(item, baseUrl);
104+
final PeertubeStreamInfoItemExtractor extractor = new PeertubeStreamInfoItemExtractor(item, baseUrl);
107105
collector.commit(extractor);
108106
}
109107
}
110-
111-
}
112-
113-
@Override
114-
public String getNextPageUrl() throws IOException, ExtractionException {
115-
super.fetchPage();
116-
return initPage.getNextPageUrl();
117108
}
118109

119110
@Override
120-
public InfoItemsPage<StreamInfoItem> getPage(String pageUrl) throws IOException, ExtractionException {
121-
Response response = getDownloader().get(pageUrl);
111+
public InfoItemsPage<StreamInfoItem> getPage(final String pageUrl) throws IOException, ExtractionException {
112+
final Response response = getDownloader().get(pageUrl);
122113
JsonObject json = null;
123114
if (response != null && !Utils.isBlank(response.responseBody())) {
124115
try {
@@ -128,31 +119,29 @@ public InfoItemsPage<StreamInfoItem> getPage(String pageUrl) throws IOException,
128119
}
129120
}
130121

131-
StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
122+
final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
123+
final long total;
132124
if (json != null) {
133125
PeertubeParsingHelper.validate(json);
134126
total = JsonUtils.getNumber(json, "total").longValue();
135-
collectStreamsFrom(collector, json, pageUrl);
127+
collectStreamsFrom(collector, json);
136128
} else {
137129
throw new ExtractionException("Unable to get PeerTube kiosk info");
138130
}
139131
return new InfoItemsPage<>(collector, PeertubeParsingHelper.getNextPageUrl(pageUrl, total));
140132
}
141133

142134
@Override
143-
public void onFetchPage(Downloader downloader) throws IOException, ExtractionException {
144-
Response response = downloader.get(getUrl());
145-
if (null != response && null != response.responseBody()) {
135+
public void onFetchPage(final Downloader downloader) throws IOException, ExtractionException {
136+
final Response response = downloader.get(getUrl());
137+
if (response != null && response.responseBody() != null) {
146138
setInitialData(response.responseBody());
147139
} else {
148140
throw new ExtractionException("Unable to extract PeerTube channel data");
149141
}
150-
151-
String pageUrl = getUrl() + "/videos?" + START_KEY + "=0&" + COUNT_KEY + "=" + ITEMS_PER_PAGE;
152-
this.initPage = getPage(pageUrl);
153142
}
154143

155-
private void setInitialData(String responseBody) throws ExtractionException {
144+
private void setInitialData(final String responseBody) throws ExtractionException {
156145
try {
157146
json = JsonParser.object().from(responseBody);
158147
} catch (JsonParserException e) {
@@ -170,5 +159,4 @@ public String getName() throws ParsingException {
170159
public String getOriginalUrl() throws ParsingException {
171160
return baseUrl + "/" + getId();
172161
}
173-
174162
}

0 commit comments

Comments
 (0)