Skip to content

Commit 18e486d

Browse files
committed
Merge branch 'bugfix-dont-call-fetch-page-in-constructor' of https://github.com/coffeemakr/NewPipeExtractor into f
2 parents 1cb025e + 4fa14b3 commit 18e486d

30 files changed

Lines changed: 104 additions & 62 deletions

build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,12 @@ task sourcesJar(type: Jar, dependsOn: classes) {
2424

2525
artifacts {
2626
archives sourcesJar
27+
}
28+
29+
tasks.withType(Test) {
30+
testLogging {
31+
events "skipped", "failed"
32+
showStandardStreams = true
33+
exceptionFormat = 'full'
34+
}
2735
}

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,16 @@ public abstract class Extractor {
3333
*/
3434
@Nullable
3535
private String cleanUrl;
36+
private boolean pageFetched = false;
37+
private final Downloader downloader;
3638

3739
public Extractor(StreamingService service, String url) throws ExtractionException {
3840
if(service == null) throw new NullPointerException("service is null");
3941
if(url == null) throw new NullPointerException("url is null");
4042
this.service = service;
4143
this.originalUrl = url;
44+
this.downloader = NewPipe.getDownloader();
45+
if(downloader == null) throw new NullPointerException("downloader is null");
4246
}
4347

4448
/**
@@ -49,8 +53,26 @@ public Extractor(StreamingService service, String url) throws ExtractionExceptio
4953

5054
/**
5155
* Fetch the current page.
56+
* @throws IOException if the page can not be loaded
57+
* @throws ExtractionException if the pages content is not understood
5258
*/
53-
public abstract void fetchPage() throws IOException, ExtractionException;
59+
public void fetchPage() throws IOException, ExtractionException {
60+
if(pageFetched) return;
61+
onFetchPage(downloader);
62+
pageFetched = true;
63+
}
64+
65+
protected void assertPageFetched() {
66+
if(!pageFetched) throw new IllegalStateException("Page is not fetched. Make sure you call fetchPage()");
67+
}
68+
69+
/**
70+
* Fetch the current page.
71+
* @param downloader the download to use
72+
* @throws IOException if the page can not be loaded
73+
* @throws ExtractionException if the pages content is not understood
74+
*/
75+
public abstract void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException;
5476

5577
@Nonnull
5678
public abstract String getId() throws ParsingException;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public abstract class Info implements Serializable {
1616
public final String url;
1717
public final String name;
1818

19-
public List<Throwable> errors = new ArrayList<>();
19+
public final List<Throwable> errors = new ArrayList<>();
2020

2121
public void addError(Throwable throwable) {
2222
this.errors.add(throwable);

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import org.schabi.newpipe.extractor.stream.SubtitlesFormat;
44

55
public class Subtitles {
6-
private SubtitlesFormat format;
7-
private String languageCode, URL;
8-
private boolean autoGenerated;
6+
private final SubtitlesFormat format;
7+
private final String languageCode;
8+
private final String URL;
9+
private final boolean autoGenerated;
910

1011
public Subtitles(SubtitlesFormat format, String languageCode, String URL, boolean autoGenerated) {
1112
this.format = format;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
public abstract class SuggestionExtractor {
2929

30-
private int serviceId;
30+
private final int serviceId;
3131

3232
public SuggestionExtractor(int serviceId) {
3333
this.serviceId = serviceId;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
public abstract class KioskExtractor extends ListExtractor {
3232
private String contentCountry = null;
33-
private String id = null;
33+
private final String id;
3434

3535
public KioskExtractor(StreamingService streamingService,
3636
String url,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ KioskExtractor createNewKiosk(final StreamingService streamingService,
1919
throws ExtractionException, IOException;
2020
}
2121

22-
private int service_id;
23-
private HashMap<String, KioskEntry> kioskList = new HashMap<>();
22+
private final int service_id;
23+
private final HashMap<String, KioskEntry> kioskList = new HashMap<>();
2424
private String defaultKiosk = null;
2525

2626
private class KioskEntry {
2727
public KioskEntry(KioskExtractorFactory ef, UrlIdHandler h) {
2828
extractorFactory = ef;
2929
handler = h;
3030
}
31-
KioskExtractorFactory extractorFactory;
32-
UrlIdHandler handler;
31+
final KioskExtractorFactory extractorFactory;
32+
final UrlIdHandler handler;
3333
}
3434

3535
public KioskList(int service_id) {

src/main/java/org/schabi/newpipe/extractor/search/SearchEngine.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public NothingFoundException(String message) {
3535
}
3636
}
3737

38-
private InfoItemSearchCollector collector;
38+
private final InfoItemSearchCollector collector;
3939

4040
public SearchEngine(int serviceId) {
4141
collector = new InfoItemSearchCollector(serviceId);

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@ public SoundcloudChannelExtractor(StreamingService service, String url, String n
2424
}
2525

2626
@Override
27-
public void fetchPage() throws IOException, ExtractionException {
28-
Downloader dl = NewPipe.getDownloader();
27+
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
2928

3029
userId = getUrlIdHandler().getId(getOriginalUrl());
3130
String apiUrl = "https://api.soundcloud.com/users/" + userId +
3231
"?client_id=" + SoundcloudParsingHelper.clientId();
3332

34-
String response = dl.download(apiUrl);
33+
String response = downloader.download(apiUrl);
3534
try {
3635
user = JsonParser.object().from(response);
3736
} catch (JsonParserException e) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import org.schabi.newpipe.extractor.channel.ChannelInfoItemExtractor;
55

66
public class SoundcloudChannelInfoItemExtractor implements ChannelInfoItemExtractor {
7-
private JsonObject searchResult;
7+
private final JsonObject searchResult;
88

99
public SoundcloudChannelInfoItemExtractor(JsonObject searchResult) {
1010
this.searchResult = searchResult;

0 commit comments

Comments
 (0)