Skip to content

Commit 86db415

Browse files
committed
architecture refacturing
1 parent 9dfcb3b commit 86db415

40 files changed

Lines changed: 298 additions & 279 deletions

src/main/java/org/schabi/newpipe/extractor/InfoItemCollector.java renamed to src/main/java/org/schabi/newpipe/extractor/InfoItemsCollector.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Created by Christian Schabesberger on 12.02.17.
1212
*
1313
* Copyright (C) Christian Schabesberger 2017 <chris.schabesberger@mailbox.org>
14-
* InfoItemCollector.java is part of NewPipe.
14+
* InfoItemsCollector.java is part of NewPipe.
1515
*
1616
* NewPipe is free software: you can redistribute it and/or modify
1717
* it under the terms of the GNU General Public License as published by
@@ -27,7 +27,7 @@
2727
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
2828
*/
2929

30-
public abstract class InfoItemCollector<I extends InfoItem, E> implements Collector<I,E> {
30+
public abstract class InfoItemsCollector<I extends InfoItem, E> implements Collector<I,E> {
3131

3232
private final List<I> itemList = new ArrayList<>();
3333
private final List<Throwable> errors = new ArrayList<>();
@@ -37,7 +37,7 @@ public abstract class InfoItemCollector<I extends InfoItem, E> implements Collec
3737
* Create a new collector
3838
* @param serviceId the service id
3939
*/
40-
public InfoItemCollector(int serviceId) {
40+
public InfoItemsCollector(int serviceId) {
4141
this.serviceId = serviceId;
4242
}
4343

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

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

33
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
4-
import org.schabi.newpipe.extractor.stream.StreamInfoItemCollector;
54

65
import javax.annotation.Nonnull;
76
import java.io.IOException;
@@ -11,73 +10,73 @@
1110
* Base class to extractors that have a list (e.g. playlists, users).
1211
*/
1312
public abstract class ListExtractor extends Extractor {
14-
protected String nextStreamsUrl;
13+
protected String nextPageUrl;
1514

1615
/**
17-
* Get a new ListExtractor with the given nextStreamsUrl set.
16+
* Get a new ListExtractor with the given nextPageUrl set.
1817
*/
19-
public ListExtractor(StreamingService service, String url, String nextStreamsUrl) throws ExtractionException {
18+
public ListExtractor(StreamingService service, String url, String nextPageUrl) throws ExtractionException {
2019
super(service, url);
21-
setNextStreamsUrl(nextStreamsUrl);
20+
setNextPageUrl(nextPageUrl);
2221
}
2322

2423
@Nonnull
25-
public abstract StreamInfoItemCollector getStreams() throws IOException, ExtractionException;
24+
public abstract InfoItemsCollector getInfoItems() throws IOException, ExtractionException;
2625

27-
public abstract NextItemsResult getNextStreams() throws IOException, ExtractionException;
26+
public abstract InfoItemPage getInfoItemPage() throws IOException, ExtractionException;
2827

29-
public boolean hasMoreStreams() {
30-
return nextStreamsUrl != null && !nextStreamsUrl.isEmpty();
28+
public boolean hasNextPage() {
29+
return nextPageUrl != null && !nextPageUrl.isEmpty();
3130
}
3231

33-
public String getNextStreamsUrl() {
34-
return nextStreamsUrl;
32+
public String getNextPageUrl() {
33+
return nextPageUrl;
3534
}
3635

37-
public void setNextStreamsUrl(String nextStreamsUrl) {
38-
this.nextStreamsUrl = nextStreamsUrl;
36+
public void setNextPageUrl(String nextPageUrl) {
37+
this.nextPageUrl = nextPageUrl;
3938
}
4039

4140
/*//////////////////////////////////////////////////////////////////////////
4241
// Inner
4342
//////////////////////////////////////////////////////////////////////////*/
4443

45-
public static class NextItemsResult {
44+
public static class InfoItemPage {
4645
/**
4746
* The current list of items to this result
4847
*/
49-
public final List<InfoItem> nextItemsList;
48+
public final List<InfoItem> infoItemList;
5049

5150
/**
5251
* Next url to fetch more items
5352
*/
54-
public final String nextItemsUrl;
53+
public final String nextPageUrl;
5554

5655
/**
5756
* Errors that happened during the extraction
5857
*/
5958
public final List<Throwable> errors;
6059

61-
public NextItemsResult(InfoItemCollector collector, String nextItemsUrl) {
62-
this(collector.getItemList(), nextItemsUrl, collector.getErrors());
60+
public InfoItemPage(InfoItemsCollector collector, String nextPageUrl) {
61+
this(collector.getItemList(), nextPageUrl, collector.getErrors());
6362
}
6463

65-
public NextItemsResult(List<InfoItem> nextItemsList, String nextItemsUrl, List<Throwable> errors) {
66-
this.nextItemsList = nextItemsList;
67-
this.nextItemsUrl = nextItemsUrl;
64+
public InfoItemPage(List<InfoItem> infoItemList, String nextPageUrl, List<Throwable> errors) {
65+
this.infoItemList = infoItemList;
66+
this.nextPageUrl = nextPageUrl;
6867
this.errors = errors;
6968
}
7069

71-
public boolean hasMoreStreams() {
72-
return nextItemsUrl != null && !nextItemsUrl.isEmpty();
70+
public boolean hasNextPage() {
71+
return nextPageUrl != null && !nextPageUrl.isEmpty();
7372
}
7473

7574
public List<InfoItem> getNextItemsList() {
76-
return nextItemsList;
75+
return infoItemList;
7776
}
7877

79-
public String getNextItemsUrl() {
80-
return nextItemsUrl;
78+
public String getNextPageUrl() {
79+
return nextPageUrl;
8180
}
8281

8382
public List<Throwable> getErrors() {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ public void setRelatedStreams(List<InfoItem> related_streams) {
1919
this.related_streams = related_streams;
2020
}
2121

22-
public boolean hasMoreStreams() {
22+
public boolean hasNextPage() {
2323
return has_more_streams;
2424
}
2525

2626
public void setHasMoreStreams(boolean has_more_streams) {
2727
this.has_more_streams = has_more_streams;
2828
}
2929

30-
public String getNextStreamsUrl() {
30+
public String getNextPageUrl() {
3131
return next_streams_url;
3232
}
3333

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ public String toString() {
6969
public abstract SearchEngine getSearchEngine();
7070
public abstract SuggestionExtractor getSuggestionExtractor();
7171
public abstract StreamExtractor getStreamExtractor(String url) throws IOException, ExtractionException;
72-
public abstract ChannelExtractor getChannelExtractor(String url, String nextStreamsUrl) throws IOException, ExtractionException;
73-
public abstract PlaylistExtractor getPlaylistExtractor(String url, String nextStreamsUrl) 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;
7474
public abstract KioskList getKioskList() throws ExtractionException;
7575
public abstract SubscriptionExtractor getSubscriptionExtractor();
7676

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

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

3-
import org.schabi.newpipe.extractor.ListExtractor;
4-
import org.schabi.newpipe.extractor.StreamingService;
5-
import org.schabi.newpipe.extractor.UrlIdHandler;
3+
import edu.umd.cs.findbugs.annotations.NonNull;
4+
import org.schabi.newpipe.extractor.*;
65
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
76
import org.schabi.newpipe.extractor.exceptions.ParsingException;
7+
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
88

99
import javax.annotation.Nonnull;
1010
import java.io.IOException;
@@ -31,16 +31,25 @@
3131

3232
public abstract class ChannelExtractor extends ListExtractor {
3333

34-
public ChannelExtractor(StreamingService service, String url, String nextStreamsUrl) throws IOException, ExtractionException {
35-
super(service, url, nextStreamsUrl);
34+
public ChannelExtractor(StreamingService service, String url, String nextPageUrl)
35+
throws ExtractionException {
36+
super(service, url, nextPageUrl);
3637
}
3738

3839
@Nonnull
3940
@Override
40-
protected UrlIdHandler getUrlIdHandler() throws ParsingException {
41+
protected UrlIdHandler getUrlIdHandler() {
4142
return getService().getChannelUrlIdHandler();
4243
}
4344

45+
@NonNull
46+
@Override
47+
public InfoItemsCollector getInfoItems()
48+
throws IOException, ExtractionException {
49+
return getStreams();
50+
}
51+
52+
public abstract StreamInfoItemsCollector getStreams() throws IOException, ExtractionException;
4453
public abstract String getAvatarUrl() throws ParsingException;
4554
public abstract String getBannerUrl() throws ParsingException;
4655
public abstract String getFeedUrl() throws ParsingException;

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

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

3-
import org.schabi.newpipe.extractor.ListExtractor.NextItemsResult;
3+
import org.schabi.newpipe.extractor.ListExtractor.InfoItemPage;
44
import org.schabi.newpipe.extractor.ListInfo;
55
import org.schabi.newpipe.extractor.NewPipe;
66
import org.schabi.newpipe.extractor.StreamingService;
@@ -37,8 +37,9 @@ public ChannelInfo(int serviceId, String url, String id, String name) {
3737
}
3838

3939

40-
public static NextItemsResult getMoreItems(StreamingService service, String url, String nextStreamsUrl) throws IOException, ExtractionException {
41-
return service.getChannelExtractor(url, nextStreamsUrl).getNextStreams();
40+
public static InfoItemPage getMoreItems(StreamingService service, String url, String nextPageUrl)
41+
throws IOException, ExtractionException {
42+
return service.getChannelExtractor(url, nextPageUrl).getInfoItemPage();
4243
}
4344

4445
public static ChannelInfo getInfo(String url) throws IOException, ExtractionException {
@@ -78,7 +79,7 @@ public static ChannelInfo getInfo(ChannelExtractor extractor) throws ParsingExce
7879
info.addError(e);
7980
}
8081

81-
info.setRelatedStreams(ExtractorHelper.getStreamsOrLogError(info, extractor));
82+
info.setRelatedStreams(ExtractorHelper.getInfoItemsOrLogError(info, extractor));
8283

8384
try {
8485
info.setSubscriberCount(extractor.getSubscriberCount());
@@ -91,8 +92,8 @@ public static ChannelInfo getInfo(ChannelExtractor extractor) throws ParsingExce
9192
info.addError(e);
9293
}
9394

94-
info.setHasMoreStreams(extractor.hasMoreStreams());
95-
info.setNextStreamsUrl(extractor.getNextStreamsUrl());
95+
info.setHasMoreStreams(extractor.hasNextPage());
96+
info.setNextStreamsUrl(extractor.getNextPageUrl());
9697
return info;
9798
}
9899

src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfoItemCollector.java renamed to src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfoItemsCollector.java

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

3-
import org.schabi.newpipe.extractor.InfoItemCollector;
3+
import org.schabi.newpipe.extractor.InfoItemsCollector;
44
import org.schabi.newpipe.extractor.exceptions.ParsingException;
55

66
/*
77
* Created by Christian Schabesberger on 12.02.17.
88
*
99
* Copyright (C) Christian Schabesberger 2017 <chris.schabesberger@mailbox.org>
10-
* ChannelInfoItemCollector.java is part of NewPipe.
10+
* ChannelInfoItemsCollector.java is part of NewPipe.
1111
*
1212
* NewPipe is free software: you can redistribute it and/or modify
1313
* it under the terms of the GNU General Public License as published by
@@ -23,8 +23,8 @@
2323
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
2424
*/
2525

26-
public class ChannelInfoItemCollector extends InfoItemCollector<ChannelInfoItem, ChannelInfoItemExtractor> {
27-
public ChannelInfoItemCollector(int serviceId) {
26+
public class ChannelInfoItemsCollector extends InfoItemsCollector<ChannelInfoItem, ChannelInfoItemExtractor> {
27+
public ChannelInfoItemsCollector(int serviceId) {
2828
super(serviceId);
2929
}
3030

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

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

3535
public KioskExtractor(StreamingService streamingService,
3636
String url,
37-
String nextStreamsUrl,
37+
String nextPageUrl,
3838
String kioskId)
39-
throws IOException, ExtractionException {
40-
super(streamingService, url, nextStreamsUrl);
39+
throws ExtractionException {
40+
super(streamingService, url, nextPageUrl);
4141
this.id = kioskId;
4242
}
4343

@@ -54,12 +54,12 @@ public void setContentCountry(String contentCountry) {
5454

5555
@Nonnull
5656
@Override
57-
public String getId() throws ParsingException {
57+
public String getId() {
5858
return id;
5959
}
6060

6161
/**
62-
* Id should be the name of the kiosk, tho Id is used for identifing it in the programm,
62+
* Id should be the name of the kiosk, tho Id is used for identifing it in the frontend,
6363
* so id should be kept in english.
6464
* In order to get the name of the kiosk in the desired language we have to
6565
* crawl if from the website.

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ private KioskInfo(int serviceId, String id, String url, String name) {
3535
super(serviceId, id, url, name);
3636
}
3737

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

4848
public static KioskInfo getInfo(String url,
@@ -74,7 +74,7 @@ public static KioskInfo getInfo(KioskExtractor extractor) throws ExtractionExcep
7474

7575
KioskInfo info = new KioskInfo(serviceId, id, name, url);
7676

77-
info.related_streams = ExtractorHelper.getStreamsOrLogError(info, extractor);
77+
info.related_streams = ExtractorHelper.getInfoItemsOrLogError(info, extractor);
7878

7979
return info;
8080
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class KioskList {
1414
public interface KioskExtractorFactory {
1515
KioskExtractor createNewKiosk(final StreamingService streamingService,
1616
final String url,
17-
final String nextStreamUrl,
17+
final String nextPageUrl,
1818
final String kioskId)
1919
throws ExtractionException, IOException;
2020
}
@@ -48,15 +48,15 @@ public void setDefaultKiosk(String kioskType) {
4848
defaultKiosk = kioskType;
4949
}
5050

51-
public KioskExtractor getDefaultKioskExtractor(String nextStreamUrl)
51+
public KioskExtractor getDefaultKioskExtractor(String nextPageUrl)
5252
throws ExtractionException, IOException {
5353
if(defaultKiosk != null && !defaultKiosk.equals("")) {
54-
return getExtractorById(defaultKiosk, nextStreamUrl);
54+
return getExtractorById(defaultKiosk, nextPageUrl);
5555
} else {
5656
if(!kioskList.isEmpty()) {
5757
// if not set get any entry
5858
Object[] keySet = kioskList.keySet().toArray();
59-
return getExtractorById(keySet[0].toString(), nextStreamUrl);
59+
return getExtractorById(keySet[0].toString(), nextPageUrl);
6060
} else {
6161
return null;
6262
}
@@ -67,28 +67,28 @@ public String getDefaultKioskId() {
6767
return defaultKiosk;
6868
}
6969

70-
public KioskExtractor getExtractorById(String kioskId, String nextStreamsUrl)
70+
public KioskExtractor getExtractorById(String kioskId, String nextPageUrl)
7171
throws ExtractionException, IOException {
7272
KioskEntry ke = kioskList.get(kioskId);
7373
if(ke == null) {
7474
throw new ExtractionException("No kiosk found with the type: " + kioskId);
7575
} else {
7676
return ke.extractorFactory.createNewKiosk(NewPipe.getService(service_id),
7777
ke.handler.getUrl(kioskId),
78-
nextStreamsUrl, kioskId);
78+
nextPageUrl, kioskId);
7979
}
8080
}
8181

8282
public Set<String> getAvailableKiosks() {
8383
return kioskList.keySet();
8484
}
8585

86-
public KioskExtractor getExtractorByUrl(String url, String nextStreamsUrl)
86+
public KioskExtractor getExtractorByUrl(String url, String nextPageUrl)
8787
throws ExtractionException, IOException {
8888
for(Map.Entry<String, KioskEntry> e : kioskList.entrySet()) {
8989
KioskEntry ke = e.getValue();
9090
if(ke.handler.acceptUrl(url)) {
91-
return getExtractorById(e.getKey(), nextStreamsUrl);
91+
return getExtractorById(e.getKey(), nextPageUrl);
9292
}
9393
}
9494
throw new ExtractionException("Could not find a kiosk that fits to the url: " + url);

0 commit comments

Comments
 (0)