Skip to content

Commit 07bfb23

Browse files
author
Yevhen Babiichuk (DustDFG)
committed
Refactor Extractor#getDownloader to be a static shorthand
The downloader is global there is no sense to store reference to it in every instance of Extractor. So eliminate the field, make getDownloader shorthand for Newpipe.getDownloader and make it static to be accesible in static functions of extractors
1 parent f6b9808 commit 07bfb23

7 files changed

Lines changed: 8 additions & 21 deletions

File tree

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,10 @@ public abstract class Extractor {
2929
private ContentCountry forcedContentCountry = null;
3030

3131
private boolean pageFetched = false;
32-
// called like this to prevent checkstyle errors about "hiding a field"
33-
private final Downloader downloader;
3432

3533
protected Extractor(final StreamingService service, final LinkHandler linkHandler) {
3634
this.service = Objects.requireNonNull(service, "service is null");
3735
this.linkHandler = Objects.requireNonNull(linkHandler, "LinkHandler is null");
38-
this.downloader = Objects.requireNonNull(NewPipe.getDownloader(), "downloader is null");
3936
}
4037

4138
/**
@@ -117,8 +114,8 @@ public int getServiceId() {
117114
return service.getServiceId();
118115
}
119116

120-
public Downloader getDownloader() {
121-
return downloader;
117+
public static Downloader getDownloader() {
118+
return NewPipe.getDownloader();
122119
}
123120

124121
/*//////////////////////////////////////////////////////////////////////////

extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampRadioStreamExtractor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import org.schabi.newpipe.extractor.Image;
1616
import org.schabi.newpipe.extractor.Image.ResolutionLevel;
1717
import org.schabi.newpipe.extractor.MediaFormat;
18-
import org.schabi.newpipe.extractor.NewPipe;
1918
import org.schabi.newpipe.extractor.StreamingService;
2019
import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException;
2120
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
@@ -48,7 +47,7 @@ public BandcampRadioStreamExtractor(final StreamingService service,
4847

4948
static JsonObject query(final int id) throws ParsingException {
5049
try {
51-
return JsonParser.object().from(NewPipe.getDownloader()
50+
return JsonParser.object().from(getDownloader()
5251
.get(BASE_API_URL + "/bcweekly/1/get?id=" + id).responseBody());
5352
} catch (final IOException | ReCaptchaException | JsonParserException e) {
5453
throw new ParsingException("could not get show data", e);

extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCConferenceExtractor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import com.grack.nanojson.JsonParserException;
88

99
import org.schabi.newpipe.extractor.Image;
10-
import org.schabi.newpipe.extractor.NewPipe;
1110
import org.schabi.newpipe.extractor.StreamingService;
1211
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
1312
import org.schabi.newpipe.extractor.channel.tabs.ChannelTabs;
@@ -36,7 +35,7 @@ static JsonObject fetchConferenceData(@Nonnull final String conferenceId)
3635
final String conferenceUrl
3736
= MediaCCCConferenceLinkHandlerFactory.CONFERENCE_API_ENDPOINT + conferenceId;
3837
try {
39-
return JsonParser.object().from(NewPipe.getDownloader()
38+
return JsonParser.object().from(getDownloader()
4039
.get(conferenceUrl).responseBody());
4140
} catch (final JsonParserException jpe) {
4241
throw new ExtractionException("Could not parse json returned by URL: " + conferenceUrl);

extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamExtractor.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
import com.grack.nanojson.JsonParserException;
1212
import org.schabi.newpipe.extractor.Image;
1313
import org.schabi.newpipe.extractor.MediaFormat;
14-
import org.schabi.newpipe.extractor.NewPipe;
1514
import org.schabi.newpipe.extractor.StreamingService;
16-
import org.schabi.newpipe.extractor.downloader.Downloader;
1715
import org.schabi.newpipe.extractor.downloader.Response;
1816
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
1917
import org.schabi.newpipe.extractor.exceptions.ParsingException;
@@ -99,9 +97,8 @@ public Description getDescription() throws ParsingException {
9997
}
10098
if (text.length() == 250 && text.substring(247).equals("...")) {
10199
// If description is shortened, get full description
102-
final Downloader dl = NewPipe.getDownloader();
103100
try {
104-
final Response response = dl.get(baseUrl
101+
final Response response = getDownloader().get(baseUrl
105102
+ PeertubeStreamLinkHandlerFactory.VIDEO_API_ENDPOINT
106103
+ getId() + "/description");
107104
final JsonObject jsonObject = JsonParser.object().from(response.responseBody());

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudCommentsExtractor.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
import com.grack.nanojson.JsonParser;
66
import com.grack.nanojson.JsonParserException;
77

8-
import org.schabi.newpipe.extractor.NewPipe;
98
import org.schabi.newpipe.extractor.Page;
109
import org.schabi.newpipe.extractor.StreamingService;
1110
import org.schabi.newpipe.extractor.comments.CommentsExtractor;
1211
import org.schabi.newpipe.extractor.comments.CommentsInfoItem;
1312
import org.schabi.newpipe.extractor.comments.CommentsInfoItemsCollector;
14-
import org.schabi.newpipe.extractor.downloader.Downloader;
1513
import org.schabi.newpipe.extractor.downloader.Response;
1614
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
1715
import org.schabi.newpipe.extractor.exceptions.ParsingException;
@@ -49,8 +47,7 @@ public InfoItemsPage<CommentsInfoItem> getPage(final Page page) throws Extractio
4947
@Nonnull
5048
private InfoItemsPage<CommentsInfoItem> getPage(@Nonnull final String url)
5149
throws ParsingException, IOException, ReCaptchaException {
52-
final Downloader downloader = NewPipe.getDownloader();
53-
final Response response = downloader.get(url);
50+
final Response response = getDownloader().get(url);
5451

5552
final JsonObject json;
5653
try {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import com.grack.nanojson.JsonParserException;
1212

1313
import org.schabi.newpipe.extractor.Image;
14-
import org.schabi.newpipe.extractor.NewPipe;
1514
import org.schabi.newpipe.extractor.Page;
1615
import org.schabi.newpipe.extractor.StreamingService;
1716
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
@@ -178,7 +177,7 @@ public InfoItemsPage<StreamInfoItem> getPage(final Page page) throws IOException
178177
+ SoundcloudParsingHelper.clientId() + "&ids=" + String.join(",", currentIds);
179178

180179
final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
181-
final String response = NewPipe.getDownloader().get(currentPageUrl,
180+
final String response = getDownloader().get(currentPageUrl,
182181
getExtractorLocalization()).responseBody();
183182

184183
try {

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudStreamExtractor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import org.schabi.newpipe.extractor.Image;
1818
import org.schabi.newpipe.extractor.MediaFormat;
19-
import org.schabi.newpipe.extractor.NewPipe;
2019
import org.schabi.newpipe.extractor.StreamingService;
2120
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
2221
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
@@ -189,7 +188,7 @@ private String getTranscodingUrl(final String endpointUrl)
189188
apiStreamUrl += "&track_authorization=" + trackAuthorization;
190189
}
191190

192-
final String response = NewPipe.getDownloader().get(apiStreamUrl).responseBody();
191+
final String response = getDownloader().get(apiStreamUrl).responseBody();
193192
final JsonObject urlObject;
194193
try {
195194
urlObject = JsonParser.object().from(response);

0 commit comments

Comments
 (0)