Skip to content

Commit 4680928

Browse files
committed
Merge branch 'dev'
2 parents 33961b2 + 4bc5b8d commit 4680928

130 files changed

Lines changed: 1895 additions & 1101 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.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ To test changes quickly you can build the library locally. Using the local Maven
2121
2. It's _recommended_ that you change the `version` of this library (e.g. `LOCAL_SNAPSHOT`).
2222
3. Run gradle's `ìnstall` task to deploy this library to your local repository (using the wrapper, present in the root of this project: `./gradlew install`)
2323
4. Change the dependency version used in your project to match the one you chose in step 2 (`implementation 'com.github.TeamNewPipe:NewPipeExtractor:LOCAL_SNAPSHOT'`)
24-
24+
2525
> Tip for Android Studio users: After you make changes and run the `install` task, use the menu option `File → "Sync with File System"` to refresh the library in your project.
2626
2727
## Supported sites

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: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +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;
7+
import org.schabi.newpipe.extractor.feed.FeedExtractor;
108
import org.schabi.newpipe.extractor.kiosk.KioskList;
11-
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
12-
import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
13-
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
14-
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
15-
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandler;
16-
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandlerFactory;
9+
import org.schabi.newpipe.extractor.linkhandler.*;
1710
import org.schabi.newpipe.extractor.localization.ContentCountry;
1811
import org.schabi.newpipe.extractor.localization.Localization;
1912
import org.schabi.newpipe.extractor.localization.TimeAgoParser;
@@ -24,6 +17,10 @@
2417
import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor;
2518
import org.schabi.newpipe.extractor.suggestion.SuggestionExtractor;
2619

20+
import javax.annotation.Nullable;
21+
import java.util.Collections;
22+
import java.util.List;
23+
2724
/*
2825
* Copyright (C) Christian Schabesberger 2018 <chris.schabesberger@mailbox.org>
2926
* StreamingService.java is part of NewPipe.
@@ -65,7 +62,7 @@ public ServiceInfo(String name, List<MediaCapability> mediaCapabilities) {
6562
public String getName() {
6663
return name;
6764
}
68-
65+
6966
public List<MediaCapability> getMediaCapabilities() {
7067
return mediaCapabilities;
7168
}
@@ -116,7 +113,7 @@ public ServiceInfo getServiceInfo() {
116113
public String toString() {
117114
return serviceId + ":" + serviceInfo.getName();
118115
}
119-
116+
120117
public abstract String getBaseUrl();
121118

122119
/*//////////////////////////////////////////////////////////////////////////
@@ -173,6 +170,19 @@ public String toString() {
173170
*/
174171
public abstract SubscriptionExtractor getSubscriptionExtractor();
175172

173+
/**
174+
* This method decides which strategy will be chosen to fetch the feed. In YouTube, for example, a separate feed
175+
* exists which is lightweight and made specifically to be used like this.
176+
* <p>
177+
* In services which there's no other way to retrieve them, null should be returned.
178+
*
179+
* @return a {@link FeedExtractor} instance or null.
180+
*/
181+
@Nullable
182+
public FeedExtractor getFeedExtractor(String url) throws ExtractionException {
183+
return null;
184+
}
185+
176186
/**
177187
* Must create a new instance of a KioskList implementation.
178188
* @return a new KioskList instance
@@ -253,12 +263,12 @@ public StreamExtractor getStreamExtractor(String url) throws ExtractionException
253263

254264
public CommentsExtractor getCommentsExtractor(String url) throws ExtractionException {
255265
ListLinkHandlerFactory llhf = getCommentsLHFactory();
256-
if(null == llhf) {
266+
if (llhf == null) {
257267
return null;
258268
}
259269
return getCommentsExtractor(llhf.fromUrl(url));
260270
}
261-
271+
262272
/*//////////////////////////////////////////////////////////////////////////
263273
// Utils
264274
//////////////////////////////////////////////////////////////////////////*/

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +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;
98
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
10-
import org.schabi.newpipe.extractor.localization.Localization;
119
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
1210
import org.schabi.newpipe.extractor.utils.ExtractorHelper;
1311

@@ -35,8 +33,8 @@
3533

3634
public class ChannelInfo extends ListInfo<StreamInfoItem> {
3735

38-
public ChannelInfo(int serviceId, ListLinkHandler linkHandler, String name) throws ParsingException {
39-
super(serviceId, linkHandler, name);
36+
public ChannelInfo(int serviceId, String id, String url, String originalUrl, String name, ListLinkHandler listLinkHandler) {
37+
super(serviceId, id, url, originalUrl, name, listLinkHandler.getContentFilters(), listLinkHandler.getSortFilter());
4038
}
4139

4240
public static ChannelInfo getInfo(String url) throws IOException, ExtractionException {
@@ -57,15 +55,14 @@ public static InfoItemsPage<StreamInfoItem> getMoreItems(StreamingService servic
5755

5856
public static ChannelInfo getInfo(ChannelExtractor extractor) throws IOException, ExtractionException {
5957

60-
ChannelInfo info = new ChannelInfo(extractor.getServiceId(),
61-
extractor.getLinkHandler(),
62-
extractor.getName());
58+
final int serviceId = extractor.getServiceId();
59+
final String id = extractor.getId();
60+
final String url = extractor.getUrl();
61+
final String originalUrl = extractor.getOriginalUrl();
62+
final String name = extractor.getName();
63+
64+
final ChannelInfo info = new ChannelInfo(serviceId, id, url, originalUrl, name, extractor.getLinkHandler());
6365

64-
try {
65-
info.setOriginalUrl(extractor.getOriginalUrl());
66-
} catch (Exception e) {
67-
info.addError(e);
68-
}
6966
try {
7067
info.setAvatarUrl(extractor.getAvatarUrl());
7168
} catch (Exception e) {

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() {

0 commit comments

Comments
 (0)