Skip to content

Commit 11216f3

Browse files
committed
Fix bug and some re-structure
1 parent 5e34556 commit 11216f3

18 files changed

Lines changed: 133 additions & 133 deletions

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

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,52 +11,46 @@
1111
*/
1212
public abstract class ListExtractor extends Extractor {
1313

14-
/**
15-
* Get a new ListExtractor with the given nextPageUrl set.
16-
*/
1714
public ListExtractor(StreamingService service, String url) {
1815
super(service, url);
1916
}
2017

2118
@Nonnull
22-
public abstract InfoItemsCollector getInfoItems() throws IOException, ExtractionException;
23-
19+
public abstract InfoItemsCollector<? extends InfoItem, ?> getInfoItems() throws IOException, ExtractionException;
2420
public abstract String getNextPageUrl() throws IOException, ExtractionException;
25-
26-
public abstract InfoItemPage getPage(final String nextPageUrl) throws IOException, ExtractionException;
21+
public abstract InfoItemPage<? extends InfoItem> getPage(final String nextPageUrl) throws IOException, ExtractionException;
2722

2823
public boolean hasNextPage() throws IOException, ExtractionException {
29-
return getNextPageUrl() != null && !getNextPageUrl().isEmpty();
24+
final String nextPageUrl = getNextPageUrl();
25+
return nextPageUrl != null && !nextPageUrl.isEmpty();
3026
}
3127

32-
33-
3428
/*//////////////////////////////////////////////////////////////////////////
3529
// Inner
3630
//////////////////////////////////////////////////////////////////////////*/
3731

38-
public static class InfoItemPage {
32+
public static class InfoItemPage<T extends InfoItem> {
3933
/**
4034
* The current list of items to this result
4135
*/
42-
public final List<InfoItem> infoItemList;
36+
private final List<T> itemsList;
4337

4438
/**
4539
* Next url to fetch more items
4640
*/
47-
public final String nextPageUrl;
41+
private final String nextPageUrl;
4842

4943
/**
5044
* Errors that happened during the extraction
5145
*/
52-
public final List<Throwable> errors;
46+
private final List<Throwable> errors;
5347

54-
public InfoItemPage(InfoItemsCollector collector, String nextPageUrl) {
48+
public InfoItemPage(InfoItemsCollector<T, ?> collector, String nextPageUrl) {
5549
this(collector.getItemList(), nextPageUrl, collector.getErrors());
5650
}
5751

58-
public InfoItemPage(List<InfoItem> infoItemList, String nextPageUrl, List<Throwable> errors) {
59-
this.infoItemList = infoItemList;
52+
public InfoItemPage(List<T> itemsList, String nextPageUrl, List<Throwable> errors) {
53+
this.itemsList = itemsList;
6054
this.nextPageUrl = nextPageUrl;
6155
this.errors = errors;
6256
}
@@ -65,8 +59,8 @@ public boolean hasNextPage() {
6559
return nextPageUrl != null && !nextPageUrl.isEmpty();
6660
}
6761

68-
public List<InfoItem> getItemsList() {
69-
return infoItemList;
62+
public List<T> getItemsList() {
63+
return itemsList;
7064
}
7165

7266
public String getNextPageUrl() {

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package org.schabi.newpipe.extractor.channel;
22

33
import edu.umd.cs.findbugs.annotations.NonNull;
4-
import org.schabi.newpipe.extractor.*;
4+
import org.schabi.newpipe.extractor.ListExtractor;
5+
import org.schabi.newpipe.extractor.StreamingService;
6+
import org.schabi.newpipe.extractor.UrlIdHandler;
57
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
68
import org.schabi.newpipe.extractor.exceptions.ParsingException;
9+
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
710
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
811

912
import javax.annotation.Nonnull;
@@ -43,12 +46,10 @@ protected UrlIdHandler getUrlIdHandler() {
4346

4447
@NonNull
4548
@Override
46-
public InfoItemsCollector getInfoItems()
47-
throws IOException, ExtractionException {
48-
return getStreams();
49-
}
49+
public abstract StreamInfoItemsCollector getInfoItems() throws IOException, ExtractionException;
50+
@Override
51+
public abstract InfoItemPage<StreamInfoItem> getPage(String nextPageUrl) throws IOException, ExtractionException;
5052

51-
public abstract StreamInfoItemsCollector getStreams() throws IOException, ExtractionException;
5253
public abstract String getAvatarUrl() throws ParsingException;
5354
public abstract String getBannerUrl() throws ParsingException;
5455
public abstract String getFeedUrl() throws ParsingException;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
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;
8+
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
99
import org.schabi.newpipe.extractor.utils.ExtractorHelper;
1010

1111
import java.io.IOException;
@@ -37,7 +37,7 @@ public ChannelInfo(int serviceId, String url, String id, String name) {
3737
}
3838

3939

40-
public static InfoItemPage getMoreItems(StreamingService service, String url, String pageUrl)
40+
public static InfoItemPage<StreamInfoItem> getMoreItems(StreamingService service, String url, String pageUrl)
4141
throws IOException, ExtractionException {
4242
return service.getChannelExtractor(url).getPage(pageUrl);
4343
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@
2020
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
2121
*/
2222

23+
import edu.umd.cs.findbugs.annotations.NonNull;
2324
import org.schabi.newpipe.extractor.ListExtractor;
2425
import org.schabi.newpipe.extractor.StreamingService;
2526
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
2627
import org.schabi.newpipe.extractor.exceptions.ParsingException;
28+
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
29+
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
2730

2831
import javax.annotation.Nonnull;
2932
import java.io.IOException;
@@ -40,6 +43,12 @@ public KioskExtractor(StreamingService streamingService,
4043
this.id = kioskId;
4144
}
4245

46+
@NonNull
47+
@Override
48+
public abstract StreamInfoItemsCollector getInfoItems() throws IOException, ExtractionException;
49+
@Override
50+
public abstract InfoItemPage<StreamInfoItem> getPage(String nextPageUrl) throws IOException, ExtractionException;
51+
4352
/**
4453
* For certain Websites the content of a kiosk will be different depending
4554
* on the country you want to poen the website in. Therefore you should

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.schabi.newpipe.extractor.NewPipe;
2626
import org.schabi.newpipe.extractor.StreamingService;
2727
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
28+
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
2829
import org.schabi.newpipe.extractor.utils.ExtractorHelper;
2930

3031
import java.io.IOException;
@@ -35,10 +36,10 @@ private KioskInfo(int serviceId, String id, String url, String name) {
3536
super(serviceId, id, url, name);
3637
}
3738

38-
public static ListExtractor.InfoItemPage getMoreItems(StreamingService service,
39-
String url,
40-
String pageUrl,
41-
String contentCountry) throws IOException, ExtractionException {
39+
public static ListExtractor.InfoItemPage<StreamInfoItem> getMoreItems(StreamingService service,
40+
String url,
41+
String pageUrl,
42+
String contentCountry) throws IOException, ExtractionException {
4243
KioskList kl = service.getKioskList();
4344
KioskExtractor extractor = kl.getExtractorByUrl(url, pageUrl);
4445
extractor.setContentCountry(contentCountry);

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package org.schabi.newpipe.extractor.playlist;
22

33
import edu.umd.cs.findbugs.annotations.NonNull;
4-
import org.schabi.newpipe.extractor.InfoItemsCollector;
54
import org.schabi.newpipe.extractor.ListExtractor;
65
import org.schabi.newpipe.extractor.StreamingService;
76
import org.schabi.newpipe.extractor.UrlIdHandler;
87
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
98
import org.schabi.newpipe.extractor.exceptions.ParsingException;
9+
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
1010
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
1111

1212
import javax.annotation.Nonnull;
@@ -26,12 +26,10 @@ protected UrlIdHandler getUrlIdHandler() {
2626

2727
@NonNull
2828
@Override
29-
public InfoItemsCollector getInfoItems()
30-
throws IOException, ExtractionException {
31-
return getStreams();
32-
}
29+
public abstract StreamInfoItemsCollector getInfoItems() throws IOException, ExtractionException;
30+
@Override
31+
public abstract InfoItemPage<StreamInfoItem> getPage(String nextPageUrl) throws IOException, ExtractionException;
3332

34-
public abstract StreamInfoItemsCollector getStreams() throws IOException, ExtractionException;
3533
public abstract String getThumbnailUrl() throws ParsingException;
3634
public abstract String getBannerUrl() throws ParsingException;
3735

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
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.stream.StreamInfoItem;
89

910
import java.io.IOException;
1011

@@ -16,7 +17,7 @@ public PlaylistInfo(int serviceId, String id, String url, String name) {
1617
super(serviceId, id, url, name);
1718
}
1819

19-
public static InfoItemPage getMoreItems(StreamingService service, String url, String pageUrl) throws IOException, ExtractionException {
20+
public static InfoItemPage<StreamInfoItem> getMoreItems(StreamingService service, String url, String pageUrl) throws IOException, ExtractionException {
2021
return service.getPlaylistExtractor(url).getPage(pageUrl);
2122
}
2223

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
99
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
1010
import org.schabi.newpipe.extractor.exceptions.ParsingException;
11+
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
1112
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
1213

1314
import javax.annotation.Nonnull;
@@ -89,7 +90,7 @@ public String getDescription() {
8990

9091
@Nonnull
9192
@Override
92-
public StreamInfoItemsCollector getStreams() throws ExtractionException {
93+
public StreamInfoItemsCollector getInfoItems() throws ExtractionException {
9394
if(streamInfoItemsCollector == null) {
9495
computeNextPageAndGetStreams();
9596
}
@@ -120,14 +121,14 @@ private void computeNextPageAndGetStreams() throws ExtractionException {
120121
}
121122

122123
@Override
123-
public InfoItemPage getPage(final String pageUrl) throws IOException, ExtractionException {
124-
if (!hasNextPage()) {
125-
throw new ExtractionException("Channel doesn't have more streams");
124+
public InfoItemPage<StreamInfoItem> getPage(final String pageUrl) throws IOException, ExtractionException {
125+
if (pageUrl == null || pageUrl.isEmpty()) {
126+
throw new ExtractionException(new IllegalArgumentException("Page url is empty or null"));
126127
}
127128

128129
StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
129130
String nextPageUrl = SoundcloudParsingHelper.getStreamsFromApiMinItems(15, collector, pageUrl);
130131

131-
return new InfoItemPage(collector, nextPageUrl);
132+
return new InfoItemPage<>(collector, nextPageUrl);
132133
}
133134
}

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
package org.schabi.newpipe.extractor.services.soundcloud;
22

3-
import java.io.IOException;
4-
import java.util.Arrays;
5-
import java.util.List;
6-
7-
import org.schabi.newpipe.extractor.Collector;
83
import org.schabi.newpipe.extractor.Downloader;
94
import org.schabi.newpipe.extractor.StreamingService;
105
import org.schabi.newpipe.extractor.UrlIdHandler;
116
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
12-
import org.schabi.newpipe.extractor.exceptions.ParsingException;
137
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
8+
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
149
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
1510

1611
import javax.annotation.Nonnull;
12+
import java.io.IOException;
13+
import java.util.Arrays;
14+
import java.util.List;
1715

1816
public class SoundcloudChartsExtractor extends KioskExtractor {
1917
private String url;
@@ -44,15 +42,15 @@ public UrlIdHandler getUrlIdHandler() {
4442
}
4543

4644
@Override
47-
public InfoItemPage getPage(String pageUrl) throws IOException, ExtractionException {
48-
if (!hasNextPage()) {
49-
throw new ExtractionException("Chart doesn't have more streams");
45+
public InfoItemPage<StreamInfoItem> getPage(String pageUrl) throws IOException, ExtractionException {
46+
if (pageUrl == null || pageUrl.isEmpty()) {
47+
throw new ExtractionException(new IllegalArgumentException("Page url is empty or null"));
5048
}
5149

5250
StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
5351
String nextPageUrl = SoundcloudParsingHelper.getStreamsFromApi(collector, pageUrl, true);
5452

55-
return new InfoItemPage(collector, nextPageUrl);
53+
return new InfoItemPage<>(collector, nextPageUrl);
5654
}
5755

5856

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
99
import org.schabi.newpipe.extractor.exceptions.ParsingException;
1010
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
11+
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
1112
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
1213

1314
import javax.annotation.Nonnull;
@@ -91,7 +92,7 @@ public long getStreamCount() {
9192

9293
@Nonnull
9394
@Override
94-
public StreamInfoItemsCollector getStreams() throws IOException, ExtractionException {
95+
public StreamInfoItemsCollector getInfoItems() throws IOException, ExtractionException {
9596
if(streamInfoItemsCollector == null) {
9697
computeStreamsAndNextPageUrl();
9798
}
@@ -119,14 +120,14 @@ public String getNextPageUrl() throws IOException, ExtractionException {
119120
}
120121

121122
@Override
122-
public InfoItemPage getPage(String pageUrl) throws IOException, ExtractionException {
123-
if (!hasNextPage()) {
124-
throw new ExtractionException("Playlist doesn't have more streams");
123+
public InfoItemPage<StreamInfoItem> getPage(String pageUrl) throws IOException, ExtractionException {
124+
if (pageUrl == null || pageUrl.isEmpty()) {
125+
throw new ExtractionException(new IllegalArgumentException("Page url is empty or null"));
125126
}
126127

127128
StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
128129
String nextPageUrl = SoundcloudParsingHelper.getStreamsFromApiMinItems(15, collector, pageUrl);
129130

130-
return new InfoItemPage(collector, nextPageUrl);
131+
return new InfoItemPage<>(collector, nextPageUrl);
131132
}
132133
}

0 commit comments

Comments
 (0)