Skip to content

Commit a70cb02

Browse files
authored
Merge pull request #314 from wb9688/remove-getnextpageurl
Next page stuff
2 parents e5d23a8 + 0a5a905 commit a70cb02

53 files changed

Lines changed: 778 additions & 932 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,18 @@
22

33
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
44
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
5-
import org.schabi.newpipe.extractor.utils.Utils;
65

76
import java.io.IOException;
87
import java.util.Collections;
98
import java.util.List;
109

1110
import javax.annotation.Nonnull;
1211

13-
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
1412

1513
/**
1614
* Base class to extractors that have a list (e.g. playlists, users).
1715
*/
1816
public abstract class ListExtractor<R extends InfoItem> extends Extractor {
19-
2017
/**
2118
* Constant that should be returned whenever
2219
* a list has an unknown number of items.
@@ -38,36 +35,22 @@ public ListExtractor(StreamingService service, ListLinkHandler linkHandler) {
3835
}
3936

4037
/**
41-
* A {@link InfoItemsPage InfoItemsPage} corresponding to the initial page where the items are from the initial request and
42-
* the nextPageUrl relative to it.
38+
* A {@link InfoItemsPage InfoItemsPage} corresponding to the initial page
39+
* where the items are from the initial request and the nextPage relative to it.
4340
*
4441
* @return a {@link InfoItemsPage} corresponding to the initial page
4542
*/
4643
@Nonnull
4744
public abstract InfoItemsPage<R> getInitialPage() throws IOException, ExtractionException;
4845

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-
5846
/**
5947
* Get a list of items corresponding to the specific requested page.
6048
*
61-
* @param pageUrl any page url got from the exclusive implementation of the list extractor
49+
* @param page any page got from the exclusive implementation of the list extractor
6250
* @return a {@link InfoItemsPage} corresponding to the requested page
63-
* @see #getNextPageUrl()
64-
* @see InfoItemsPage#getNextPageUrl()
51+
* @see InfoItemsPage#getNextPage()
6552
*/
66-
public abstract InfoItemsPage<R> getPage(final String pageUrl) throws IOException, ExtractionException;
67-
68-
public boolean hasNextPage() throws IOException, ExtractionException {
69-
return !isNullOrEmpty(getNextPageUrl());
70-
}
53+
public abstract InfoItemsPage<R> getPage(final Page page) throws IOException, ExtractionException;
7154

7255
@Override
7356
public ListLinkHandler getLinkHandler() {
@@ -80,23 +63,22 @@ public ListLinkHandler getLinkHandler() {
8063

8164
/**
8265
* A class that is used to wrap a list of gathered items and eventual errors, it
83-
* also contains a field that points to the next available page ({@link #nextPageUrl}).
66+
* also contains a field that points to the next available page ({@link #nextPage}).
8467
*/
8568
public static class InfoItemsPage<T extends InfoItem> {
8669
private static final InfoItemsPage<InfoItem> EMPTY =
87-
new InfoItemsPage<>(Collections.<InfoItem>emptyList(), "", Collections.<Throwable>emptyList());
70+
new InfoItemsPage<>(Collections.<InfoItem>emptyList(), null, Collections.<Throwable>emptyList());
8871

8972
/**
9073
* A convenient method that returns a representation of an empty page.
9174
*
92-
* @return a type-safe page with the list of items and errors empty and the nextPageUrl set to an empty string.
75+
* @return a type-safe page with the list of items and errors empty and the nextPage set to {@code null}.
9376
*/
9477
public static <T extends InfoItem> InfoItemsPage<T> emptyPage() {
9578
//noinspection unchecked
9679
return (InfoItemsPage<T>) EMPTY;
9780
}
9881

99-
10082
/**
10183
* The current list of items of this page
10284
*/
@@ -105,40 +87,40 @@ public static <T extends InfoItem> InfoItemsPage<T> emptyPage() {
10587
/**
10688
* Url pointing to the next page relative to this one
10789
*
108-
* @see ListExtractor#getPage(String)
90+
* @see ListExtractor#getPage(Page)
91+
* @see Page
10992
*/
110-
private final String nextPageUrl;
93+
private final Page nextPage;
11194

11295
/**
11396
* Errors that happened during the extraction
11497
*/
11598
private final List<Throwable> errors;
11699

117-
public InfoItemsPage(InfoItemsCollector<T, ?> collector, String nextPageUrl) {
118-
this(collector.getItems(), nextPageUrl, collector.getErrors());
100+
public InfoItemsPage(InfoItemsCollector<T, ?> collector, Page nextPage) {
101+
this(collector.getItems(), nextPage, collector.getErrors());
119102
}
120103

121-
public InfoItemsPage(List<T> itemsList, String nextPageUrl, List<Throwable> errors) {
104+
public InfoItemsPage(List<T> itemsList, Page nextPage, List<Throwable> errors) {
122105
this.itemsList = itemsList;
123-
this.nextPageUrl = nextPageUrl;
106+
this.nextPage = nextPage;
124107
this.errors = errors;
125108
}
126109

127110
public boolean hasNextPage() {
128-
return !isNullOrEmpty(nextPageUrl);
111+
return Page.isValid(nextPage);
129112
}
130113

131114
public List<T> getItems() {
132115
return itemsList;
133116
}
134117

135-
public String getNextPageUrl() {
136-
return nextPageUrl;
118+
public Page getNextPage() {
119+
return nextPage;
137120
}
138121

139122
public List<Throwable> getErrors() {
140123
return errors;
141124
}
142125
}
143-
144126
}

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44

55
import java.util.List;
66

7-
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
8-
97
public abstract class ListInfo<T extends InfoItem> extends Info {
108
private List<T> relatedItems;
11-
private String nextPageUrl = null;
9+
private Page nextPage = null;
1210
private final List<String> contentFilters;
1311
private final String sortFilter;
1412

@@ -39,15 +37,15 @@ public void setRelatedItems(List<T> relatedItems) {
3937
}
4038

4139
public boolean hasNextPage() {
42-
return !isNullOrEmpty(nextPageUrl);
40+
return Page.isValid(nextPage);
4341
}
4442

45-
public String getNextPageUrl() {
46-
return nextPageUrl;
43+
public Page getNextPage() {
44+
return nextPage;
4745
}
4846

49-
public void setNextPageUrl(String pageUrl) {
50-
this.nextPageUrl = pageUrl;
47+
public void setNextPage(Page page) {
48+
this.nextPage = page;
5149
}
5250

5351
public List<String> getContentFilters() {
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package org.schabi.newpipe.extractor;
2+
3+
import java.io.Serializable;
4+
import java.util.List;
5+
import java.util.Map;
6+
7+
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
8+
9+
public class Page implements Serializable {
10+
private final String url;
11+
private final List<String> ids;
12+
private final Map<String, String> cookies;
13+
14+
public Page(final String url, final List<String> ids, final Map<String, String> cookies) {
15+
this.url = url;
16+
this.ids = ids;
17+
this.cookies = cookies;
18+
}
19+
20+
public Page(final String url) {
21+
this(url, null, null);
22+
}
23+
24+
public Page(final String url, final Map<String, String> cookies) {
25+
this(url, null, cookies);
26+
}
27+
28+
public Page(final List<String> ids) {
29+
this(null, ids, null);
30+
}
31+
32+
public Page(final List<String> ids, final Map<String, String> cookies) {
33+
this(null, ids, cookies);
34+
}
35+
36+
public String getUrl() {
37+
return url;
38+
}
39+
40+
public List<String> getIds() {
41+
return ids;
42+
}
43+
44+
public Map<String, String> getCookies() {
45+
return cookies;
46+
}
47+
48+
public static boolean isValid(final Page page) {
49+
return page != null && (!isNullOrEmpty(page.getUrl())
50+
|| !isNullOrEmpty(page.getIds()));
51+
}
52+
}

extractor/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfo.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage;
44
import org.schabi.newpipe.extractor.ListInfo;
55
import org.schabi.newpipe.extractor.NewPipe;
6+
import org.schabi.newpipe.extractor.Page;
67
import org.schabi.newpipe.extractor.StreamingService;
78
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
89
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
@@ -49,8 +50,8 @@ public static ChannelInfo getInfo(StreamingService service, String url) throws I
4950

5051
public static InfoItemsPage<StreamInfoItem> getMoreItems(StreamingService service,
5152
String url,
52-
String pageUrl) throws IOException, ExtractionException {
53-
return service.getChannelExtractor(url).getPage(pageUrl);
53+
Page page) throws IOException, ExtractionException {
54+
return service.getChannelExtractor(url).getPage(page);
5455
}
5556

5657
public static ChannelInfo getInfo(ChannelExtractor extractor) throws IOException, ExtractionException {
@@ -81,7 +82,7 @@ public static ChannelInfo getInfo(ChannelExtractor extractor) throws IOException
8182

8283
final InfoItemsPage<StreamInfoItem> itemsPage = ExtractorHelper.getItemsPageOrLogError(info, extractor);
8384
info.setRelatedItems(itemsPage.getItems());
84-
info.setNextPageUrl(itemsPage.getNextPageUrl());
85+
info.setNextPage(itemsPage.getNextPage());
8586

8687
try {
8788
info.setSubscriberCount(extractor.getSubscriberCount());

extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfo.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage;
44
import org.schabi.newpipe.extractor.ListInfo;
55
import org.schabi.newpipe.extractor.NewPipe;
6+
import org.schabi.newpipe.extractor.Page;
67
import org.schabi.newpipe.extractor.StreamingService;
78
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
89
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
@@ -39,23 +40,23 @@ private static CommentsInfo getInfo(CommentsExtractor commentsExtractor) throws
3940
InfoItemsPage<CommentsInfoItem> initialCommentsPage = ExtractorHelper.getItemsPageOrLogError(commentsInfo,
4041
commentsExtractor);
4142
commentsInfo.setRelatedItems(initialCommentsPage.getItems());
42-
commentsInfo.setNextPageUrl(initialCommentsPage.getNextPageUrl());
43+
commentsInfo.setNextPage(initialCommentsPage.getNextPage());
4344

4445
return commentsInfo;
4546
}
4647

47-
public static InfoItemsPage<CommentsInfoItem> getMoreItems(CommentsInfo commentsInfo, String pageUrl)
48+
public static InfoItemsPage<CommentsInfoItem> getMoreItems(CommentsInfo commentsInfo, Page page)
4849
throws ExtractionException, IOException {
49-
return getMoreItems(NewPipe.getService(commentsInfo.getServiceId()), commentsInfo, pageUrl);
50+
return getMoreItems(NewPipe.getService(commentsInfo.getServiceId()), commentsInfo, page);
5051
}
5152

5253
public static InfoItemsPage<CommentsInfoItem> getMoreItems(StreamingService service, CommentsInfo commentsInfo,
53-
String pageUrl) throws IOException, ExtractionException {
54+
Page page) throws IOException, ExtractionException {
5455
if (null == commentsInfo.getCommentsExtractor()) {
5556
commentsInfo.setCommentsExtractor(service.getCommentsExtractor(commentsInfo.getUrl()));
5657
commentsInfo.getCommentsExtractor().fetchPage();
5758
}
58-
return commentsInfo.getCommentsExtractor().getPage(pageUrl);
59+
return commentsInfo.getCommentsExtractor().getPage(page);
5960
}
6061

6162
private transient CommentsExtractor commentsExtractor;

extractor/src/main/java/org/schabi/newpipe/extractor/feed/FeedInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static FeedInfo getInfo(FeedExtractor extractor) throws IOException, Extr
4545

4646
final InfoItemsPage<StreamInfoItem> itemsPage = ExtractorHelper.getItemsPageOrLogError(info, extractor);
4747
info.setRelatedItems(itemsPage.getItems());
48-
info.setNextPageUrl(itemsPage.getNextPageUrl());
48+
info.setNextPage(itemsPage.getNextPage());
4949

5050
return info;
5151
}

extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskInfo.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.schabi.newpipe.extractor.ListExtractor;
2424
import org.schabi.newpipe.extractor.ListInfo;
2525
import org.schabi.newpipe.extractor.NewPipe;
26+
import org.schabi.newpipe.extractor.Page;
2627
import org.schabi.newpipe.extractor.StreamingService;
2728
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
2829
import org.schabi.newpipe.extractor.exceptions.ParsingException;
@@ -33,18 +34,17 @@
3334
import java.io.IOException;
3435

3536
public class KioskInfo extends ListInfo<StreamInfoItem> {
36-
3737
private KioskInfo(int serviceId, ListLinkHandler linkHandler, String name) throws ParsingException {
3838
super(serviceId, linkHandler, name);
3939
}
4040

4141
public static ListExtractor.InfoItemsPage<StreamInfoItem> getMoreItems(StreamingService service,
4242
String url,
43-
String pageUrl)
43+
Page page)
4444
throws IOException, ExtractionException {
4545
KioskList kl = service.getKioskList();
46-
KioskExtractor extractor = kl.getExtractorByUrl(url, pageUrl);
47-
return extractor.getPage(pageUrl);
46+
KioskExtractor extractor = kl.getExtractorByUrl(url, page);
47+
return extractor.getPage(page);
4848
}
4949

5050
public static KioskInfo getInfo(String url) throws IOException, ExtractionException {
@@ -71,7 +71,7 @@ public static KioskInfo getInfo(KioskExtractor extractor) throws ExtractionExcep
7171

7272
final ListExtractor.InfoItemsPage<StreamInfoItem> itemsPage = ExtractorHelper.getItemsPageOrLogError(info, extractor);
7373
info.setRelatedItems(itemsPage.getItems());
74-
info.setNextPageUrl(itemsPage.getNextPageUrl());
74+
info.setNextPage(itemsPage.getNextPage());
7575

7676
return info;
7777
}

0 commit comments

Comments
 (0)