Skip to content

Commit 4c49a34

Browse files
committed
merged upstream/master
2 parents f58c914 + 91b1efc commit 4c49a34

23 files changed

Lines changed: 602 additions & 168 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# NewPipe Extractor
22

3-
[![Build Status](https://travis-ci.org/TeamNewPipe/NewPipeExtractor.svg?branch=master)](https://travis-ci.org/TeamNewPipe/NewPipeExtractor) [![JIT Pack Badge](https://jitpack.io/v/TeamNewPipe/NewPipeExtractor.svg)](https://jitpack.io/#TeamNewPipe/NewPipeExtractor) [Documentation](https://teamnewpipe.github.io/NewPipeExtractor/javadoc/)
3+
[![Build Status](https://travis-ci.org/TeamNewPipe/NewPipeExtractor.svg?branch=master)](https://travis-ci.org/TeamNewPipe/NewPipeExtractor) [![JIT Pack Badge](https://jitpack.io/v/TeamNewPipe/NewPipeExtractor.svg)](https://jitpack.io/#TeamNewPipe/NewPipeExtractor) [Documentation](https://teamnewpipe.github.io/documentation/)
44

55
NewPipe Extractor is a library for extracting things from streaming sites. It is a core component of [NewPipe](https://github.com/TeamNewPipe/NewPipe), but could be used independently.
66

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ public enum MediaFormat {
3636
M4A (0x3, "m4a", "m4a", "audio/mp4"),
3737
WEBMA (0x4, "WebM", "webm", "audio/webm"),
3838
MP3 (0x5, "MP3", "mp3", "audio/mpeg"),
39-
OPUS (0x6, "opus", "opus", "audio/opus");
39+
OPUS (0x6, "opus", "opus", "audio/opus"),
40+
// subtitles formats
41+
VTT (0x7, "WebVTT", "vtt", "text/vtt"),
42+
TTML (0x8, "Timed Text Markup Language", "ttml", "application/ttml+xml"),
43+
TRANSCRIPT1 (0x9, "TranScript v1", "srv1", "text/xml"),
44+
TRANSCRIPT2 (0xA, "TranScript v2", "srv2", "text/xml"),
45+
TRANSCRIPT3 (0xB, "TranScript v3", "srv3", "text/xml"),
46+
SRT (0xC, "SubRip file format", "srt", "text/srt");
4047

4148
public final int id;
4249
public final String name;

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,24 @@
88
import static java.util.Arrays.asList;
99
import static java.util.Collections.unmodifiableList;
1010

11+
/*
12+
* Copyright (C) Christian Schabesberger 2018 <chris.schabesberger@mailbox.org>
13+
* ServiceList.java is part of NewPipe.
14+
*
15+
* NewPipe is free software: you can redistribute it and/or modify
16+
* it under the terms of the GNU General Public License as published by
17+
* the Free Software Foundation, either version 3 of the License, or
18+
* (at your option) any later version.
19+
*
20+
* NewPipe is distributed in the hope that it will be useful,
21+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
22+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23+
* GNU General Public License for more details.
24+
*
25+
* You should have received a copy of the GNU General Public License
26+
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
27+
*/
28+
1129
/**
1230
* A list of supported services.
1331
*/
@@ -19,6 +37,10 @@ private ServiceList() {
1937
public static final YoutubeService YouTube;
2038
public static final SoundcloudService SoundCloud;
2139

40+
/**
41+
* When creating a new service, put this service in the end of this list,
42+
* and give it the next free id.
43+
*/
2244
private static final List<StreamingService> SERVICES = unmodifiableList(
2345
asList(
2446
YouTube = new YoutubeService(0),

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

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,38 @@
2020
import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor;
2121
import org.schabi.newpipe.extractor.utils.Localization;
2222

23+
/*
24+
* Copyright (C) Christian Schabesberger 2018 <chris.schabesberger@mailbox.org>
25+
* StreamingService.java is part of NewPipe.
26+
*
27+
* NewPipe is free software: you can redistribute it and/or modify
28+
* it under the terms of the GNU General Public License as published by
29+
* the Free Software Foundation, either version 3 of the License, or
30+
* (at your option) any later version.
31+
*
32+
* NewPipe is distributed in the hope that it will be useful,
33+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
34+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35+
* GNU General Public License for more details.
36+
*
37+
* You should have received a copy of the GNU General Public License
38+
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
39+
*/
40+
2341
public abstract class StreamingService {
42+
43+
/**
44+
* This class holds meta information about the service implementation.
45+
*/
2446
public static class ServiceInfo {
2547
private final String name;
2648
private final List<MediaCapability> mediaCapabilities;
2749

50+
/**
51+
* Creates a new instance of a ServiceInfo
52+
* @param name the name of the service
53+
* @param mediaCapabilities the type of media this service can handle
54+
*/
2855
public ServiceInfo(String name, List<MediaCapability> mediaCapabilities) {
2956
this.name = name;
3057
this.mediaCapabilities = Collections.unmodifiableList(mediaCapabilities);
@@ -43,6 +70,10 @@ public enum MediaCapability {
4370
}
4471
}
4572

73+
/**
74+
* LinkType will be used to determine which type of URL you are handling, and therefore which part
75+
* of NewPipe should handle a certain URL.
76+
*/
4677
public enum LinkType {
4778
NONE,
4879
STREAM,
@@ -53,6 +84,16 @@ public enum LinkType {
5384
private final int serviceId;
5485
private final ServiceInfo serviceInfo;
5586

87+
/**
88+
* Creates a new Streaming service.
89+
* If you Implement one do not set id within your implementation of this extractor, instead
90+
* set the id when you put the extractor into
91+
* <a href="https://teamnewpipe.github.io/NewPipeExtractor/javadoc/org/schabi/newpipe/extractor/ServiceList.html">ServiceList</a>.
92+
* All other parameters can be set directly from the overriding constructor.
93+
* @param id the number of the service to identify him within the NewPipe frontend
94+
* @param name the name of the service
95+
* @param capabilities the type of media this service can handle
96+
*/
5697
public StreamingService(int id, String name, List<ServiceInfo.MediaCapability> capabilities) {
5798
this.serviceId = id;
5899
this.serviceInfo = new ServiceInfo(name, capabilities);
@@ -74,25 +115,94 @@ public String toString() {
74115
////////////////////////////////////////////
75116
// Url Id handler
76117
////////////////////////////////////////////
118+
119+
/**
120+
* Must return a new instance of an implementation of LinkHandlerFactory for streams.
121+
* @return an instance of a LinkHandlerFactory for streams
122+
*/
77123
public abstract LinkHandlerFactory getStreamLHFactory();
124+
125+
/**
126+
* Must return a new instance of an implementation of ListLinkHandlerFactory for channels.
127+
* If support for channels is not given null must be returned.
128+
* @return an instance of a ListLinkHandlerFactory for channels or null
129+
*/
78130
public abstract ListLinkHandlerFactory getChannelLHFactory();
131+
132+
/**
133+
* Must return a new instance of an implementation of ListLinkHandlerFactory for playlists.
134+
* If support for playlists is not given null must be returned.
135+
* @return an instance of a ListLinkHandlerFactory for playlists or null
136+
*/
79137
public abstract ListLinkHandlerFactory getPlaylistLHFactory();
138+
139+
/**
140+
* Must return an instance of an implementation of SearchQueryHandlerFactory.
141+
* @return an instance of a SearchQueryHandlerFactory
142+
*/
80143
public abstract SearchQueryHandlerFactory getSearchQHFactory();
81144
public abstract ListLinkHandlerFactory getCommentsLHFactory();
82145

83146

84147
////////////////////////////////////////////
85148
// Extractor
86149
////////////////////////////////////////////
150+
151+
/**
152+
* Must create a new instance of a SearchExtractor implementation.
153+
* @param queryHandler specifies the keyword lock for, and the filters which should be applied.
154+
* @param localization specifies the language/country for the extractor.
155+
* @return a new SearchExtractor instance
156+
*/
87157
public abstract SearchExtractor getSearchExtractor(SearchQueryHandler queryHandler, Localization localization);
158+
159+
/**
160+
* Must create a new instance of a SuggestionExtractor implementation.
161+
* @param localization specifies the language/country for the extractor.
162+
* @return a new SuggestionExtractor instance
163+
*/
88164
public abstract SuggestionExtractor getSuggestionExtractor(Localization localization);
165+
166+
/**
167+
* Outdated or obsolete. null can be returned.
168+
* @return just null
169+
*/
89170
public abstract SubscriptionExtractor getSubscriptionExtractor();
171+
172+
/**
173+
* Must create a new instance of a KioskList implementation.
174+
* @return a new KioskList instance
175+
* @throws ExtractionException
176+
*/
90177
public abstract KioskList getKioskList() throws ExtractionException;
91178

179+
/**
180+
* Must create a new instance of a ChannelExtractor implementation.
181+
* @param linkHandler is pointing to the channel which should be handled by this new instance.
182+
* @param localization specifies the language used for the request.
183+
* @return a new ChannelExtractor
184+
* @throws ExtractionException
185+
*/
92186
public abstract ChannelExtractor getChannelExtractor(ListLinkHandler linkHandler,
93187
Localization localization) throws ExtractionException;
188+
189+
/**
190+
* Must crete a new instance of a PlaylistExtractor implementation.
191+
* @param linkHandler is pointing to the playlist which should be handled by this new instance.
192+
* @param localization specifies the language used for the request.
193+
* @return a new PlaylistExtractor
194+
* @throws ExtractionException
195+
*/
94196
public abstract PlaylistExtractor getPlaylistExtractor(ListLinkHandler linkHandler,
95197
Localization localization) throws ExtractionException;
198+
199+
/**
200+
* Must create a new instance of a StreamExtractor implementation.
201+
* @param linkHandler is pointing to the stream which should be handled by this new instance.
202+
* @param localization specifies the language used for the request.
203+
* @return a new StreamExtractor
204+
* @throws ExtractionException
205+
*/
96206
public abstract StreamExtractor getStreamExtractor(LinkHandler linkHandler,
97207
Localization localization) throws ExtractionException;
98208
public abstract CommentsExtractor getCommentsExtractor(ListLinkHandler linkHandler,
@@ -192,6 +302,11 @@ public CommentsExtractor getCommentsExtractor(String url) throws ExtractionExcep
192302

193303
/**
194304
* figure out where the link is pointing to (a channel, video, playlist, etc.)
305+
/**
306+
* Figures out where the link is pointing to (a channel, a video, a playlist, etc.)
307+
* @param url the url on which it should be decided of which link type it is
308+
* @return the link type of url
309+
* @throws ParsingException
195310
*/
196311
public final LinkType getLinkTypeByUrl(String url) throws ParsingException {
197312
LinkHandlerFactory sH = getStreamLHFactory();

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

Lines changed: 0 additions & 34 deletions
This file was deleted.

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,13 @@ public List<VideoStream> getVideoOnlyStreams() throws IOException, ExtractionExc
172172

173173
@Override
174174
@Nonnull
175-
public List<Subtitles> getSubtitlesDefault() throws IOException, ExtractionException {
175+
public List<SubtitlesStream> getSubtitlesDefault() throws IOException, ExtractionException {
176176
return Collections.emptyList();
177177
}
178178

179179
@Override
180180
@Nonnull
181-
public List<Subtitles> getSubtitles(SubtitlesFormat format) throws IOException, ExtractionException {
181+
public List<SubtitlesStream> getSubtitles(MediaFormat format) throws IOException, ExtractionException {
182182
return Collections.emptyList();
183183
}
184184

@@ -188,12 +188,12 @@ public StreamType getStreamType() {
188188
}
189189

190190
@Override
191-
public StreamInfoItem getNextVideo() throws IOException, ExtractionException {
191+
public StreamInfoItem getNextStream() throws IOException, ExtractionException {
192192
return null;
193193
}
194194

195195
@Override
196-
public StreamInfoItemsCollector getRelatedVideos() throws IOException, ExtractionException {
196+
public StreamInfoItemsCollector getRelatedStreams() throws IOException, ExtractionException {
197197
StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
198198

199199
String apiUrl = "https://api-v2.soundcloud.com/tracks/" + urlEncode(getId()) + "/related"

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSearchExtractor.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,19 @@ public YoutubeSearchExtractor(StreamingService service,
5353
@Override
5454
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
5555
final String site;
56-
final String url = getUrl() + "?gl="+ getLocalization().getCountry();
56+
final String url = getUrl();
5757
//String url = builder.build().toString();
5858
//if we've been passed a valid language code, append it to the URL
5959
site = downloader.download(url, getLocalization());
6060

6161
doc = Jsoup.parse(site, url);
6262
}
6363

64+
@Override
65+
public String getUrl() throws ParsingException {
66+
return super.getUrl() + "&gl="+ getLocalization().getCountry();
67+
}
68+
6469
@Override
6570
public String getSearchSuggestion() {
6671
final Element el = doc.select("div[class*=\"spell-correction\"]").first();
@@ -79,7 +84,7 @@ public InfoItemsPage<InfoItem> getInitialPage() throws ExtractionException {
7984

8085
@Override
8186
public String getNextPageUrl() throws ExtractionException {
82-
return getUrl() + "&page=" + 2 + "&gl=" + getLocalization().getCountry();
87+
return getUrl() + "&page=" + 2;
8388
}
8489

8590
@Override

0 commit comments

Comments
 (0)