Skip to content

Commit d812a11

Browse files
theScrabimauriciocolli
authored andcommitted
made getPage() function be stand alone
1 parent 4366b73 commit d812a11

26 files changed

Lines changed: 215 additions & 163 deletions

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,26 @@
1010
* Base class to extractors that have a list (e.g. playlists, users).
1111
*/
1212
public abstract class ListExtractor extends Extractor {
13-
protected String nextPageUrl;
1413

1514
/**
1615
* Get a new ListExtractor with the given nextPageUrl set.
1716
*/
18-
public ListExtractor(StreamingService service, String url, String nextPageUrl) throws ExtractionException {
17+
public ListExtractor(StreamingService service, String url) throws ExtractionException {
1918
super(service, url);
20-
setNextPageUrl(nextPageUrl);
2119
}
2220

2321
@Nonnull
2422
public abstract InfoItemsCollector getInfoItems() throws IOException, ExtractionException;
2523

26-
public abstract InfoItemPage getInfoItemPage() throws IOException, ExtractionException;
24+
public abstract String getNextPageUrl() throws IOException, ExtractionException;
2725

28-
public boolean hasNextPage() {
29-
return nextPageUrl != null && !nextPageUrl.isEmpty();
30-
}
26+
public abstract InfoItemPage getPage(final String nextPageUrl) throws IOException, ExtractionException;
3127

32-
public String getNextPageUrl() {
33-
return nextPageUrl;
28+
public boolean hasNextPage() throws IOException, ExtractionException {
29+
return getNextPageUrl() != null && !getNextPageUrl().isEmpty();
3430
}
3531

36-
public void setNextPageUrl(String nextPageUrl) {
37-
this.nextPageUrl = nextPageUrl;
38-
}
32+
3933

4034
/*//////////////////////////////////////////////////////////////////////////
4135
// Inner

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,12 @@ public String toString() {
6868
public abstract UrlIdHandler getPlaylistUrlIdHandler();
6969
public abstract SearchEngine getSearchEngine();
7070
public abstract SuggestionExtractor getSuggestionExtractor();
71-
public abstract StreamExtractor getStreamExtractor(String url) throws IOException, ExtractionException;
72-
public abstract ChannelExtractor getChannelExtractor(String url, String nextPageUrl) throws IOException, ExtractionException;
73-
public abstract PlaylistExtractor getPlaylistExtractor(String url, String nextPageUrl) throws IOException, ExtractionException;
71+
public abstract StreamExtractor getStreamExtractor(String url) throws ExtractionException;
7472
public abstract KioskList getKioskList() throws ExtractionException;
73+
public abstract ChannelExtractor getChannelExtractor(String url) throws ExtractionException;
74+
public abstract PlaylistExtractor getPlaylistExtractor(String url) throws ExtractionException;
7575
public abstract SubscriptionExtractor getSubscriptionExtractor();
7676

77-
public ChannelExtractor getChannelExtractor(String url) throws IOException, ExtractionException {
78-
return getChannelExtractor(url, null);
79-
}
80-
81-
public PlaylistExtractor getPlaylistExtractor(String url) throws IOException, ExtractionException {
82-
return getPlaylistExtractor(url, null);
83-
}
84-
8577
/**
8678
* figure out where the link is pointing to (a channel, video, playlist, etc.)
8779
*/

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131

3232
public abstract class ChannelExtractor extends ListExtractor {
3333

34-
public ChannelExtractor(StreamingService service, String url, String nextPageUrl)
34+
public ChannelExtractor(StreamingService service, String url)
3535
throws ExtractionException {
36-
super(service, url, nextPageUrl);
36+
super(service, url);
3737
}
3838

3939
@Nonnull
@@ -55,5 +55,4 @@ public InfoItemsCollector getInfoItems()
5555
public abstract String getFeedUrl() throws ParsingException;
5656
public abstract long getSubscriberCount() throws ParsingException;
5757
public abstract String getDescription() throws ParsingException;
58-
5958
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ public ChannelInfo(int serviceId, String url, String id, String name) {
3737
}
3838

3939

40-
public static InfoItemPage getMoreItems(StreamingService service, String url, String nextPageUrl)
40+
public static InfoItemPage getMoreItems(StreamingService service, String url, String pageUrl)
4141
throws IOException, ExtractionException {
42-
return service.getChannelExtractor(url, nextPageUrl).getInfoItemPage();
42+
return service.getChannelExtractor(url).getPage(pageUrl);
4343
}
4444

4545
public static ChannelInfo getInfo(String url) throws IOException, ExtractionException {
@@ -52,7 +52,7 @@ public static ChannelInfo getInfo(StreamingService service, String url) throws I
5252
return getInfo(extractor);
5353
}
5454

55-
public static ChannelInfo getInfo(ChannelExtractor extractor) throws ParsingException {
55+
public static ChannelInfo getInfo(ChannelExtractor extractor) throws IOException, ExtractionException {
5656

5757
// important data
5858
int serviceId = extractor.getServiceId();

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ public abstract class KioskExtractor extends ListExtractor {
3434

3535
public KioskExtractor(StreamingService streamingService,
3636
String url,
37-
String nextPageUrl,
3837
String kioskId)
3938
throws ExtractionException {
40-
super(streamingService, url, nextPageUrl);
39+
super(streamingService, url);
4140
this.id = kioskId;
4241
}
4342

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ private KioskInfo(int serviceId, String id, String url, String name) {
3737

3838
public static ListExtractor.InfoItemPage getMoreItems(StreamingService service,
3939
String url,
40-
String nextPageUrl,
40+
String pageUrl,
4141
String contentCountry) throws IOException, ExtractionException {
4242
KioskList kl = service.getKioskList();
43-
KioskExtractor extractor = kl.getExtractorByUrl(url, nextPageUrl);
43+
KioskExtractor extractor = kl.getExtractorByUrl(url, pageUrl);
4444
extractor.setContentCountry(contentCountry);
45-
return extractor.getInfoItemPage();
45+
return extractor.getPage(pageUrl);
4646
}
4747

4848
public static KioskInfo getInfo(String url,

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public class KioskList {
1414
public interface KioskExtractorFactory {
1515
KioskExtractor createNewKiosk(final StreamingService streamingService,
1616
final String url,
17-
final String nextPageUrl,
1817
final String kioskId)
1918
throws ExtractionException, IOException;
2019
}
@@ -74,8 +73,7 @@ public KioskExtractor getExtractorById(String kioskId, String nextPageUrl)
7473
throw new ExtractionException("No kiosk found with the type: " + kioskId);
7574
} else {
7675
return ke.extractorFactory.createNewKiosk(NewPipe.getService(service_id),
77-
ke.handler.getUrl(kioskId),
78-
nextPageUrl, kioskId);
76+
ke.handler.getUrl(kioskId), kioskId);
7977
}
8078
}
8179

src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistExtractor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
public abstract class PlaylistExtractor extends ListExtractor {
1616

17-
public PlaylistExtractor(StreamingService service, String url, String nextPageUrl) throws IOException, ExtractionException {
18-
super(service, url, nextPageUrl);
17+
public PlaylistExtractor(StreamingService service, String url) throws ExtractionException {
18+
super(service, url);
1919
}
2020

2121
@Nonnull

src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfo.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import org.schabi.newpipe.extractor.NewPipe;
66
import org.schabi.newpipe.extractor.StreamingService;
77
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
8-
import org.schabi.newpipe.extractor.exceptions.ParsingException;
98

109
import java.io.IOException;
1110

@@ -17,8 +16,8 @@ public PlaylistInfo(int serviceId, String id, String url, String name) {
1716
super(serviceId, id, url, name);
1817
}
1918

20-
public static InfoItemPage getMoreItems(StreamingService service, String url, String nextPageUrl) throws IOException, ExtractionException {
21-
return service.getPlaylistExtractor(url, nextPageUrl).getInfoItemPage();
19+
public static InfoItemPage getMoreItems(StreamingService service, String url, String pageUrl) throws IOException, ExtractionException {
20+
return service.getPlaylistExtractor(url).getPage(pageUrl);
2221
}
2322

2423
public static PlaylistInfo getInfo(String url) throws IOException, ExtractionException {
@@ -36,7 +35,7 @@ public static PlaylistInfo getInfo(StreamingService service, String url) throws
3635
*
3736
* @param extractor an extractor where fetchPage() was already got called on.
3837
*/
39-
public static PlaylistInfo getInfo(PlaylistExtractor extractor) throws ParsingException {
38+
public static PlaylistInfo getInfo(PlaylistExtractor extractor) throws IOException, ExtractionException {
4039

4140
int serviceId = extractor.getServiceId();
4241
String url = extractor.getCleanUrl();

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

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ public class SoundcloudChannelExtractor extends ChannelExtractor {
1818
private String userId;
1919
private JsonObject user;
2020

21-
public SoundcloudChannelExtractor(StreamingService service, String url, String nextPageUrl) throws IOException, ExtractionException {
22-
super(service, url, nextPageUrl);
21+
private StreamInfoItemsCollector streamInfoItemsCollector = null;
22+
private String nextPageUrl = null;
23+
24+
public SoundcloudChannelExtractor(StreamingService service, String url) throws ExtractionException {
25+
super(service, url);
2326
}
2427

2528
@Override
@@ -80,32 +83,50 @@ public long getSubscriberCount() {
8083
}
8184

8285
@Override
83-
public String getDescription() throws ParsingException {
86+
public String getDescription() {
8487
return user.getString("description", "");
8588
}
8689

8790
@Nonnull
8891
@Override
89-
public StreamInfoItemsCollector getStreams() throws IOException, ExtractionException {
90-
StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
92+
public StreamInfoItemsCollector getStreams() throws ExtractionException {
93+
if(streamInfoItemsCollector == null) {
94+
computeNextPageAndGetStreams();
95+
}
96+
return streamInfoItemsCollector;
97+
}
9198

92-
String apiUrl = "https://api-v2.soundcloud.com/users/" + getId() + "/tracks"
93-
+ "?client_id=" + SoundcloudParsingHelper.clientId()
94-
+ "&limit=20"
95-
+ "&linked_partitioning=1";
99+
@Override
100+
public String getNextPageUrl() throws ExtractionException {
101+
if(nextPageUrl == null) {
102+
computeNextPageAndGetStreams();
103+
}
104+
return nextPageUrl;
105+
}
106+
107+
private void computeNextPageAndGetStreams() throws ExtractionException {
108+
try {
109+
streamInfoItemsCollector = new StreamInfoItemsCollector(getServiceId());
96110

97-
nextPageUrl = SoundcloudParsingHelper.getStreamsFromApiMinItems(15, collector, apiUrl);
98-
return collector;
111+
String apiUrl = "https://api-v2.soundcloud.com/users/" + getId() + "/tracks"
112+
+ "?client_id=" + SoundcloudParsingHelper.clientId()
113+
+ "&limit=20"
114+
+ "&linked_partitioning=1";
115+
116+
nextPageUrl = SoundcloudParsingHelper.getStreamsFromApiMinItems(15, streamInfoItemsCollector, apiUrl);
117+
} catch (Exception e) {
118+
throw new ExtractionException("Could not get next page", e);
119+
}
99120
}
100121

101122
@Override
102-
public InfoItemPage getInfoItemPage() throws IOException, ExtractionException {
123+
public InfoItemPage getPage(final String pageUrl) throws IOException, ExtractionException {
103124
if (!hasNextPage()) {
104125
throw new ExtractionException("Channel doesn't have more streams");
105126
}
106127

107128
StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
108-
nextPageUrl = SoundcloudParsingHelper.getStreamsFromApiMinItems(15, collector, nextPageUrl);
129+
String nextPageUrl = SoundcloudParsingHelper.getStreamsFromApiMinItems(15, collector, pageUrl);
109130

110131
return new InfoItemPage(collector, nextPageUrl);
111132
}

0 commit comments

Comments
 (0)