Skip to content

Commit 4bc5b8d

Browse files
authored
Merge pull request #254 from TeamNewPipe/formatting
Improve code formatting and optimize imports
2 parents fc9f031 + a129c65 commit 4bc5b8d

116 files changed

Lines changed: 805 additions & 808 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

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

3-
import java.io.IOException;
4-
5-
import javax.annotation.Nonnull;
6-
import javax.annotation.Nullable;
7-
83
import org.schabi.newpipe.extractor.downloader.Downloader;
94
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
105
import org.schabi.newpipe.extractor.exceptions.ParsingException;
@@ -13,27 +8,33 @@
138
import org.schabi.newpipe.extractor.localization.Localization;
149
import org.schabi.newpipe.extractor.localization.TimeAgoParser;
1510

16-
public abstract class Extractor{
11+
import javax.annotation.Nonnull;
12+
import javax.annotation.Nullable;
13+
import java.io.IOException;
14+
15+
public abstract class Extractor {
1716
/**
1817
* {@link StreamingService} currently related to this extractor.<br>
1918
* Useful for getting other things from a service (like the url handlers for cleaning/accepting/get id from urls).
2019
*/
2120
private final StreamingService service;
2221
private final LinkHandler linkHandler;
2322

24-
@Nullable private Localization forcedLocalization = null;
25-
@Nullable private ContentCountry forcedContentCountry = null;
23+
@Nullable
24+
private Localization forcedLocalization = null;
25+
@Nullable
26+
private ContentCountry forcedContentCountry = null;
2627

2728
private boolean pageFetched = false;
2829
private final Downloader downloader;
2930

3031
public Extractor(final StreamingService service, final LinkHandler linkHandler) {
31-
if(service == null) throw new NullPointerException("service is null");
32-
if(linkHandler == null) throw new NullPointerException("LinkHandler is null");
32+
if (service == null) throw new NullPointerException("service is null");
33+
if (linkHandler == null) throw new NullPointerException("LinkHandler is null");
3334
this.service = service;
3435
this.linkHandler = linkHandler;
3536
this.downloader = NewPipe.getDownloader();
36-
if(downloader == null) throw new NullPointerException("downloader is null");
37+
if (downloader == null) throw new NullPointerException("downloader is null");
3738
}
3839

3940
/**
@@ -46,11 +47,12 @@ public LinkHandler getLinkHandler() {
4647

4748
/**
4849
* Fetch the current page.
49-
* @throws IOException if the page can not be loaded
50+
*
51+
* @throws IOException if the page can not be loaded
5052
* @throws ExtractionException if the pages content is not understood
5153
*/
5254
public void fetchPage() throws IOException, ExtractionException {
53-
if(pageFetched) return;
55+
if (pageFetched) return;
5456
onFetchPage(downloader);
5557
pageFetched = true;
5658
}
@@ -65,8 +67,9 @@ protected boolean isPageFetched() {
6567

6668
/**
6769
* Fetch the current page.
70+
*
6871
* @param downloader the download to use
69-
* @throws IOException if the page can not be loaded
72+
* @throws IOException if the page can not be loaded
7073
* @throws ExtractionException if the pages content is not understood
7174
*/
7275
public abstract void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException;
@@ -78,6 +81,7 @@ public String getId() throws ParsingException {
7881

7982
/**
8083
* Get the name
84+
*
8185
* @return the name
8286
* @throws ParsingException if the name cannot be extracted
8387
*/
@@ -93,10 +97,10 @@ public String getOriginalUrl() throws ParsingException {
9397
public String getUrl() throws ParsingException {
9498
return linkHandler.getUrl();
9599
}
96-
100+
97101
@Nonnull
98102
public String getBaseUrl() throws ParsingException {
99-
return linkHandler.getBaseUrl();
103+
return linkHandler.getBaseUrl();
100104
}
101105

102106
@Nonnull

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
2828
*/
2929

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

3232
private final List<I> itemList = new ArrayList<>();
3333
private final List<Throwable> errors = new ArrayList<>();

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,26 +115,28 @@ public static MediaFormat getFromMimeType(String mimeType) {
115115
}
116116

117117
/**
118-
* Get the media format by it's id.
118+
* Get the media format by its id.
119+
*
119120
* @param id the id
120121
* @return the id of the media format or null.
121122
*/
122123
public static MediaFormat getFormatById(int id) {
123-
for (MediaFormat vf: values()) {
124+
for (MediaFormat vf : values()) {
124125
if (vf.id == id) return vf;
125126
}
126127
return null;
127128
}
128129

129130
public static MediaFormat getFromSuffix(String suffix) {
130-
for (MediaFormat vf: values()) {
131+
for (MediaFormat vf : values()) {
131132
if (vf.suffix.equals(suffix)) return vf;
132133
}
133134
return null;
134135
}
135-
136+
136137
/**
137138
* Get the name of the format
139+
*
138140
* @return the name of the format
139141
*/
140142
public String getName() {
@@ -143,6 +145,7 @@ public String getName() {
143145

144146
/**
145147
* Get the filename extension
148+
*
146149
* @return the filename extension
147150
*/
148151
public String getSuffix() {
@@ -151,10 +154,11 @@ public String getSuffix() {
151154

152155
/**
153156
* Get the mime type
157+
*
154158
* @return the mime type
155159
*/
156160
public String getMimeType() {
157161
return mimeType;
158162
}
159-
163+
160164
}

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

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

3-
import java.util.Arrays;
4-
import java.util.Collections;
5-
import java.util.List;
6-
73
import org.schabi.newpipe.extractor.services.media_ccc.MediaCCCService;
84
import org.schabi.newpipe.extractor.services.peertube.PeertubeService;
95
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudService;
106
import org.schabi.newpipe.extractor.services.youtube.YoutubeService;
117

8+
import java.util.Arrays;
9+
import java.util.Collections;
10+
import java.util.List;
11+
1212
/*
1313
* Copyright (C) Christian Schabesberger 2018 <chris.schabesberger@mailbox.org>
1414
* ServiceList.java is part of NewPipe.

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

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

3-
import java.util.Collections;
4-
import java.util.List;
5-
63
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
74
import org.schabi.newpipe.extractor.comments.CommentsExtractor;
85
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
96
import org.schabi.newpipe.extractor.exceptions.ParsingException;
107
import org.schabi.newpipe.extractor.feed.FeedExtractor;
118
import org.schabi.newpipe.extractor.kiosk.KioskList;
12-
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
13-
import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
14-
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
15-
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
16-
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandler;
17-
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandlerFactory;
9+
import org.schabi.newpipe.extractor.linkhandler.*;
1810
import org.schabi.newpipe.extractor.localization.ContentCountry;
1911
import org.schabi.newpipe.extractor.localization.Localization;
2012
import org.schabi.newpipe.extractor.localization.TimeAgoParser;
@@ -26,6 +18,8 @@
2618
import org.schabi.newpipe.extractor.suggestion.SuggestionExtractor;
2719

2820
import javax.annotation.Nullable;
21+
import java.util.Collections;
22+
import java.util.List;
2923

3024
/*
3125
* Copyright (C) Christian Schabesberger 2018 <chris.schabesberger@mailbox.org>
@@ -269,7 +263,7 @@ public StreamExtractor getStreamExtractor(String url) throws ExtractionException
269263

270264
public CommentsExtractor getCommentsExtractor(String url) throws ExtractionException {
271265
ListLinkHandlerFactory llhf = getCommentsLHFactory();
272-
if(null == llhf) {
266+
if (llhf == null) {
273267
return null;
274268
}
275269
return getCommentsExtractor(llhf.fromUrl(url));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public ChannelInfoItem extract(ChannelInfoItemExtractor extractor) throws Parsin
3333
// important information
3434
int serviceId = getServiceId();
3535
String name = extractor.getName();
36-
String url = extractor.getUrl();
36+
String url = extractor.getUrl();
3737

3838
ChannelInfoItem resultItem = new ChannelInfoItem(serviceId, url, name);
3939

extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfo.java

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

3-
import java.io.IOException;
4-
53
import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage;
64
import org.schabi.newpipe.extractor.ListInfo;
75
import org.schabi.newpipe.extractor.NewPipe;
@@ -10,20 +8,21 @@
108
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
119
import org.schabi.newpipe.extractor.utils.ExtractorHelper;
1210

13-
public class CommentsInfo extends ListInfo<CommentsInfoItem>{
11+
import java.io.IOException;
12+
13+
public class CommentsInfo extends ListInfo<CommentsInfoItem> {
14+
15+
private CommentsInfo(int serviceId, ListLinkHandler listUrlIdHandler, String name) {
16+
super(serviceId, listUrlIdHandler, name);
17+
}
1418

15-
private CommentsInfo(int serviceId, ListLinkHandler listUrlIdHandler, String name) {
16-
super(serviceId, listUrlIdHandler, name);
17-
// TODO Auto-generated constructor stub
18-
}
19-
20-
public static CommentsInfo getInfo(String url) throws IOException, ExtractionException {
19+
public static CommentsInfo getInfo(String url) throws IOException, ExtractionException {
2120
return getInfo(NewPipe.getServiceByUrl(url), url);
2221
}
2322

24-
public static CommentsInfo getInfo(StreamingService serviceByUrl, String url) throws ExtractionException, IOException {
25-
return getInfo(serviceByUrl.getCommentsExtractor(url));
26-
}
23+
public static CommentsInfo getInfo(StreamingService serviceByUrl, String url) throws ExtractionException, IOException {
24+
return getInfo(serviceByUrl.getCommentsExtractor(url));
25+
}
2726

2827
private static CommentsInfo getInfo(CommentsExtractor commentsExtractor) throws IOException, ExtractionException {
2928
// for services which do not have a comments extractor
@@ -44,21 +43,21 @@ private static CommentsInfo getInfo(CommentsExtractor commentsExtractor) throws
4443

4544
return commentsInfo;
4645
}
47-
46+
4847
public static InfoItemsPage<CommentsInfoItem> getMoreItems(CommentsInfo commentsInfo, String pageUrl)
4948
throws ExtractionException, IOException {
5049
return getMoreItems(NewPipe.getService(commentsInfo.getServiceId()), commentsInfo, pageUrl);
5150
}
52-
51+
5352
public static InfoItemsPage<CommentsInfoItem> getMoreItems(StreamingService service, CommentsInfo commentsInfo,
54-
String pageUrl) throws IOException, ExtractionException {
53+
String pageUrl) throws IOException, ExtractionException {
5554
if (null == commentsInfo.getCommentsExtractor()) {
5655
commentsInfo.setCommentsExtractor(service.getCommentsExtractor(commentsInfo.getUrl()));
5756
commentsInfo.getCommentsExtractor().fetchPage();
5857
}
5958
return commentsInfo.getCommentsExtractor().getPage(pageUrl);
6059
}
61-
60+
6261
private transient CommentsExtractor commentsExtractor;
6362

6463
public CommentsExtractor getCommentsExtractor() {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.schabi.newpipe.extractor.StreamingService;
2626
import org.schabi.newpipe.extractor.exceptions.ParsingException;
2727
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
28-
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
2928

3029
import javax.annotation.Nonnull;
3130

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,30 @@
1313
import java.util.Map;
1414
import java.util.Set;
1515

16-
public class KioskList {
16+
public class KioskList {
1717

1818
public interface KioskExtractorFactory {
1919
KioskExtractor createNewKiosk(final StreamingService streamingService,
2020
final String url,
2121
final String kioskId)
22-
throws ExtractionException, IOException;
22+
throws ExtractionException, IOException;
2323
}
2424

2525
private final StreamingService service;
2626
private final HashMap<String, KioskEntry> kioskList = new HashMap<>();
2727
private String defaultKiosk = null;
2828

29-
@Nullable private Localization forcedLocalization;
30-
@Nullable private ContentCountry forcedContentCountry;
29+
@Nullable
30+
private Localization forcedLocalization;
31+
@Nullable
32+
private ContentCountry forcedContentCountry;
3133

3234
private class KioskEntry {
3335
public KioskEntry(KioskExtractorFactory ef, ListLinkHandlerFactory h) {
3436
extractorFactory = ef;
3537
handlerFactory = h;
3638
}
39+
3740
final KioskExtractorFactory extractorFactory;
3841
final ListLinkHandlerFactory handlerFactory;
3942
}
@@ -43,8 +46,8 @@ public KioskList(StreamingService service) {
4346
}
4447

4548
public void addKioskEntry(KioskExtractorFactory extractorFactory, ListLinkHandlerFactory handlerFactory, String id)
46-
throws Exception {
47-
if(kioskList.get(id) != null) {
49+
throws Exception {
50+
if (kioskList.get(id) != null) {
4851
throw new Exception("Kiosk with type " + id + " already exists.");
4952
}
5053
kioskList.put(id, new KioskEntry(extractorFactory, handlerFactory));
@@ -66,10 +69,10 @@ public KioskExtractor getDefaultKioskExtractor(String nextPageUrl)
6669

6770
public KioskExtractor getDefaultKioskExtractor(String nextPageUrl, Localization localization)
6871
throws ExtractionException, IOException {
69-
if(defaultKiosk != null && !defaultKiosk.equals("")) {
72+
if (defaultKiosk != null && !defaultKiosk.equals("")) {
7073
return getExtractorById(defaultKiosk, nextPageUrl, localization);
7174
} else {
72-
if(!kioskList.isEmpty()) {
75+
if (!kioskList.isEmpty()) {
7376
// if not set get any entry
7477
Object[] keySet = kioskList.keySet().toArray();
7578
return getExtractorById(keySet[0].toString(), nextPageUrl, localization);
@@ -91,7 +94,7 @@ public KioskExtractor getExtractorById(String kioskId, String nextPageUrl)
9194
public KioskExtractor getExtractorById(String kioskId, String nextPageUrl, Localization localization)
9295
throws ExtractionException, IOException {
9396
KioskEntry ke = kioskList.get(kioskId);
94-
if(ke == null) {
97+
if (ke == null) {
9598
throw new ExtractionException("No kiosk found with the type: " + kioskId);
9699
} else {
97100
final KioskExtractor kioskExtractor = ke.extractorFactory.createNewKiosk(service,
@@ -109,15 +112,15 @@ public Set<String> getAvailableKiosks() {
109112
}
110113

111114
public KioskExtractor getExtractorByUrl(String url, String nextPageUrl)
112-
throws ExtractionException, IOException{
115+
throws ExtractionException, IOException {
113116
return getExtractorByUrl(url, nextPageUrl, NewPipe.getPreferredLocalization());
114117
}
115118

116119
public KioskExtractor getExtractorByUrl(String url, String nextPageUrl, Localization localization)
117120
throws ExtractionException, IOException {
118-
for(Map.Entry<String, KioskEntry> e : kioskList.entrySet()) {
121+
for (Map.Entry<String, KioskEntry> e : kioskList.entrySet()) {
119122
KioskEntry ke = e.getValue();
120-
if(ke.handlerFactory.acceptUrl(url)) {
123+
if (ke.handlerFactory.acceptUrl(url)) {
121124
return getExtractorById(ke.handlerFactory.getId(url), nextPageUrl, localization);
122125
}
123126
}

0 commit comments

Comments
 (0)