Skip to content

Commit 35f3a4a

Browse files
authored
Merge pull request #1082 from AudricV/channel-tabs-and-tags-support
Add support for channel tabs and channel tags
2 parents 3faaf43 + e7d6409 commit 35f3a4a

182 files changed

Lines changed: 16312 additions & 4285 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/StreamingService.java

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

33
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
4+
import org.schabi.newpipe.extractor.channel.tabs.ChannelTabExtractor;
45
import org.schabi.newpipe.extractor.comments.CommentsExtractor;
56
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
67
import org.schabi.newpipe.extractor.exceptions.ParsingException;
@@ -140,6 +141,14 @@ public String toString() {
140141
*/
141142
public abstract ListLinkHandlerFactory getChannelLHFactory();
142143

144+
/**
145+
* Must return a new instance of an implementation of ListLinkHandlerFactory for channel tabs.
146+
* If support for channel tabs is not given null must be returned.
147+
*
148+
* @return an instance of a ListLinkHandlerFactory for channels or null
149+
*/
150+
public abstract ListLinkHandlerFactory getChannelTabLHFactory();
151+
143152
/**
144153
* Must return a new instance of an implementation of ListLinkHandlerFactory for playlists.
145154
* If support for playlists is not given null must be returned.
@@ -204,6 +213,15 @@ public FeedExtractor getFeedExtractor(final String url) throws ExtractionExcepti
204213
public abstract ChannelExtractor getChannelExtractor(ListLinkHandler linkHandler)
205214
throws ExtractionException;
206215

216+
/**
217+
* Must create a new instance of a ChannelTabExtractor implementation.
218+
*
219+
* @param linkHandler is pointing to the channel which should be handled by this new instance.
220+
* @return a new ChannelTabExtractor
221+
*/
222+
public abstract ChannelTabExtractor getChannelTabExtractor(ListLinkHandler linkHandler)
223+
throws ExtractionException;
224+
207225
/**
208226
* Must crete a new instance of a PlaylistExtractor implementation.
209227
* @param linkHandler is pointing to the playlist which should be handled by this new instance.
@@ -262,6 +280,20 @@ public ChannelExtractor getChannelExtractor(final String url) throws ExtractionE
262280
return getChannelExtractor(getChannelLHFactory().fromUrl(url));
263281
}
264282

283+
public ChannelTabExtractor getChannelTabExtractorFromId(final String id, final String tab)
284+
throws ExtractionException {
285+
return getChannelTabExtractor(getChannelTabLHFactory().fromQuery(
286+
id, Collections.singletonList(tab), ""));
287+
}
288+
289+
public ChannelTabExtractor getChannelTabExtractorFromIdAndBaseUrl(final String id,
290+
final String tab,
291+
final String baseUrl)
292+
throws ExtractionException {
293+
return getChannelTabExtractor(getChannelTabLHFactory().fromQuery(
294+
id, Collections.singletonList(tab), "", baseUrl));
295+
}
296+
265297
public PlaylistExtractor getPlaylistExtractor(final String url) throws ExtractionException {
266298
return getPlaylistExtractor(getPlaylistLHFactory().fromUrl(url));
267299
}

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

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

3-
import org.schabi.newpipe.extractor.ListExtractor;
3+
import org.schabi.newpipe.extractor.Extractor;
44
import org.schabi.newpipe.extractor.StreamingService;
55
import org.schabi.newpipe.extractor.exceptions.ParsingException;
66
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
7-
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
7+
8+
import javax.annotation.Nonnull;
9+
import java.util.List;
810

911
/*
1012
* Created by Christian Schabesberger on 25.07.16.
@@ -26,11 +28,11 @@
2628
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
2729
*/
2830

29-
public abstract class ChannelExtractor extends ListExtractor<StreamInfoItem> {
31+
public abstract class ChannelExtractor extends Extractor {
3032

3133
public static final long UNKNOWN_SUBSCRIBER_COUNT = -1;
3234

33-
public ChannelExtractor(final StreamingService service, final ListLinkHandler linkHandler) {
35+
protected ChannelExtractor(final StreamingService service, final ListLinkHandler linkHandler) {
3436
super(service, linkHandler);
3537
}
3638

@@ -43,5 +45,10 @@ public ChannelExtractor(final StreamingService service, final ListLinkHandler li
4345
public abstract String getParentChannelUrl() throws ParsingException;
4446
public abstract String getParentChannelAvatarUrl() throws ParsingException;
4547
public abstract boolean isVerified() throws ParsingException;
46-
48+
@Nonnull
49+
public abstract List<ListLinkHandler> getTabs() throws ParsingException;
50+
@Nonnull
51+
public List<String> getTags() throws ParsingException {
52+
return List.of();
53+
}
4754
}

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

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

3-
import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage;
4-
import org.schabi.newpipe.extractor.ListInfo;
3+
import org.schabi.newpipe.extractor.Info;
54
import org.schabi.newpipe.extractor.NewPipe;
6-
import org.schabi.newpipe.extractor.Page;
75
import org.schabi.newpipe.extractor.StreamingService;
86
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
97
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
10-
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
11-
import org.schabi.newpipe.extractor.utils.ExtractorHelper;
128

139
import java.io.IOException;
10+
import java.util.List;
11+
12+
import javax.annotation.Nonnull;
1413

1514
/*
1615
* Created by Christian Schabesberger on 31.07.16.
@@ -32,16 +31,14 @@
3231
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
3332
*/
3433

35-
public class ChannelInfo extends ListInfo<StreamInfoItem> {
34+
public class ChannelInfo extends Info {
3635

3736
public ChannelInfo(final int serviceId,
3837
final String id,
3938
final String url,
4039
final String originalUrl,
41-
final String name,
42-
final ListLinkHandler listLinkHandler) {
43-
super(serviceId, id, url, originalUrl, name, listLinkHandler.getContentFilters(),
44-
listLinkHandler.getSortFilter());
40+
final String name) {
41+
super(serviceId, id, url, originalUrl, name);
4542
}
4643

4744
public static ChannelInfo getInfo(final String url) throws IOException, ExtractionException {
@@ -55,13 +52,6 @@ public static ChannelInfo getInfo(final StreamingService service, final String u
5552
return getInfo(extractor);
5653
}
5754

58-
public static InfoItemsPage<StreamInfoItem> getMoreItems(final StreamingService service,
59-
final String url,
60-
final Page page)
61-
throws IOException, ExtractionException {
62-
return service.getChannelExtractor(url).getPage(page);
63-
}
64-
6555
public static ChannelInfo getInfo(final ChannelExtractor extractor)
6656
throws IOException, ExtractionException {
6757

@@ -71,35 +61,32 @@ public static ChannelInfo getInfo(final ChannelExtractor extractor)
7161
final String originalUrl = extractor.getOriginalUrl();
7262
final String name = extractor.getName();
7363

74-
final ChannelInfo info =
75-
new ChannelInfo(serviceId, id, url, originalUrl, name, extractor.getLinkHandler());
64+
final ChannelInfo info = new ChannelInfo(serviceId, id, url, originalUrl, name);
7665

7766
try {
7867
info.setAvatarUrl(extractor.getAvatarUrl());
7968
} catch (final Exception e) {
8069
info.addError(e);
8170
}
71+
8272
try {
8373
info.setBannerUrl(extractor.getBannerUrl());
8474
} catch (final Exception e) {
8575
info.addError(e);
8676
}
77+
8778
try {
8879
info.setFeedUrl(extractor.getFeedUrl());
8980
} catch (final Exception e) {
9081
info.addError(e);
9182
}
9283

93-
final InfoItemsPage<StreamInfoItem> itemsPage =
94-
ExtractorHelper.getItemsPageOrLogError(info, extractor);
95-
info.setRelatedItems(itemsPage.getItems());
96-
info.setNextPage(itemsPage.getNextPage());
97-
9884
try {
9985
info.setSubscriberCount(extractor.getSubscriberCount());
10086
} catch (final Exception e) {
10187
info.addError(e);
10288
}
89+
10390
try {
10491
info.setDescription(extractor.getDescription());
10592
} catch (final Exception e) {
@@ -130,6 +117,18 @@ public static ChannelInfo getInfo(final ChannelExtractor extractor)
130117
info.addError(e);
131118
}
132119

120+
try {
121+
info.setTabs(extractor.getTabs());
122+
} catch (final Exception e) {
123+
info.addError(e);
124+
}
125+
126+
try {
127+
info.setTags(extractor.getTags());
128+
} catch (final Exception e) {
129+
info.addError(e);
130+
}
131+
133132
return info;
134133
}
135134

@@ -143,6 +142,8 @@ public static ChannelInfo getInfo(final ChannelExtractor extractor)
143142
private String description;
144143
private String[] donationLinks;
145144
private boolean verified;
145+
private List<ListLinkHandler> tabs = List.of();
146+
private List<String> tags = List.of();
146147

147148
public String getParentChannelName() {
148149
return parentChannelName;
@@ -223,4 +224,22 @@ public boolean isVerified() {
223224
public void setVerified(final boolean verified) {
224225
this.verified = verified;
225226
}
227+
228+
@Nonnull
229+
public List<ListLinkHandler> getTabs() {
230+
return tabs;
231+
}
232+
233+
public void setTabs(@Nonnull final List<ListLinkHandler> tabs) {
234+
this.tabs = tabs;
235+
}
236+
237+
@Nonnull
238+
public List<String> getTags() {
239+
return tags;
240+
}
241+
242+
public void setTags(@Nonnull final List<String> tags) {
243+
this.tags = tags;
244+
}
226245
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.schabi.newpipe.extractor.channel.tabs;
2+
3+
import org.schabi.newpipe.extractor.InfoItem;
4+
import org.schabi.newpipe.extractor.ListExtractor;
5+
import org.schabi.newpipe.extractor.StreamingService;
6+
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
7+
8+
import javax.annotation.Nonnull;
9+
10+
/**
11+
* A {@link ListExtractor} of {@link InfoItem}s for tabs of channels.
12+
*/
13+
public abstract class ChannelTabExtractor extends ListExtractor<InfoItem> {
14+
15+
protected ChannelTabExtractor(@Nonnull final StreamingService service,
16+
@Nonnull final ListLinkHandler linkHandler) {
17+
super(service, linkHandler);
18+
}
19+
20+
@Nonnull
21+
@Override
22+
public String getName() {
23+
return getLinkHandler().getContentFilters().get(0);
24+
}
25+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package org.schabi.newpipe.extractor.channel.tabs;
2+
3+
import org.schabi.newpipe.extractor.InfoItem;
4+
import org.schabi.newpipe.extractor.ListExtractor;
5+
import org.schabi.newpipe.extractor.ListInfo;
6+
import org.schabi.newpipe.extractor.Page;
7+
import org.schabi.newpipe.extractor.StreamingService;
8+
import org.schabi.newpipe.extractor.channel.ChannelInfo;
9+
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
10+
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
11+
import org.schabi.newpipe.extractor.utils.ExtractorHelper;
12+
13+
import javax.annotation.Nonnull;
14+
import java.io.IOException;
15+
16+
public class ChannelTabInfo extends ListInfo<InfoItem> {
17+
18+
public ChannelTabInfo(final int serviceId,
19+
@Nonnull final ListLinkHandler linkHandler) {
20+
super(serviceId, linkHandler, linkHandler.getContentFilters().get(0));
21+
}
22+
23+
/**
24+
* Get a {@link ChannelTabInfo} instance from the given service and tab handler.
25+
*
26+
* @param service streaming service
27+
* @param linkHandler Channel tab handler (from {@link ChannelInfo})
28+
* @return the extracted {@link ChannelTabInfo}
29+
*/
30+
@Nonnull
31+
public static ChannelTabInfo getInfo(@Nonnull final StreamingService service,
32+
@Nonnull final ListLinkHandler linkHandler)
33+
throws ExtractionException, IOException {
34+
final ChannelTabExtractor extractor = service.getChannelTabExtractor(linkHandler);
35+
extractor.fetchPage();
36+
return getInfo(extractor);
37+
}
38+
39+
/**
40+
* Get a {@link ChannelTabInfo} instance from a {@link ChannelTabExtractor}.
41+
*
42+
* @param extractor an extractor where {@code fetchPage()} was already got called on
43+
* @return the extracted {@link ChannelTabInfo}
44+
*/
45+
@Nonnull
46+
public static ChannelTabInfo getInfo(@Nonnull final ChannelTabExtractor extractor) {
47+
final ChannelTabInfo info =
48+
new ChannelTabInfo(extractor.getServiceId(), extractor.getLinkHandler());
49+
50+
try {
51+
info.setOriginalUrl(extractor.getOriginalUrl());
52+
} catch (final Exception e) {
53+
info.addError(e);
54+
}
55+
56+
final ListExtractor.InfoItemsPage<InfoItem> page
57+
= ExtractorHelper.getItemsPageOrLogError(info, extractor);
58+
info.setRelatedItems(page.getItems());
59+
info.setNextPage(page.getNextPage());
60+
61+
return info;
62+
}
63+
64+
public static ListExtractor.InfoItemsPage<InfoItem> getMoreItems(
65+
@Nonnull final StreamingService service,
66+
@Nonnull final ListLinkHandler linkHandler,
67+
@Nonnull final Page page) throws ExtractionException, IOException {
68+
return service.getChannelTabExtractor(linkHandler).getPage(page);
69+
}
70+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.schabi.newpipe.extractor.channel.tabs;
2+
3+
/**
4+
* Constants of channel tabs supported by the extractor.
5+
*/
6+
public final class ChannelTabs {
7+
public static final String VIDEOS = "videos";
8+
public static final String TRACKS = "tracks";
9+
public static final String SHORTS = "shorts";
10+
public static final String LIVESTREAMS = "livestreams";
11+
public static final String CHANNELS = "channels";
12+
public static final String PLAYLISTS = "playlists";
13+
public static final String ALBUMS = "albums";
14+
15+
private ChannelTabs() {
16+
}
17+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.schabi.newpipe.extractor.exceptions;
2+
3+
public final class UnsupportedTabException extends UnsupportedOperationException {
4+
public UnsupportedTabException(final String unsupportedTab) {
5+
super("Unsupported tab " + unsupportedTab);
6+
}
7+
}

extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/LinkHandlerFactory.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ public abstract class LinkHandlerFactory {
3131
// To Override
3232
///////////////////////////////////
3333

34-
public abstract String getId(String url) throws ParsingException;
34+
public abstract String getId(String url) throws ParsingException, UnsupportedOperationException;
3535

36-
public abstract String getUrl(String id) throws ParsingException;
36+
public abstract String getUrl(String id) throws ParsingException, UnsupportedOperationException;
3737

3838
public abstract boolean onAcceptUrl(String url) throws ParsingException;
3939

40-
public String getUrl(final String id, final String baseUrl) throws ParsingException {
40+
public String getUrl(final String id, final String baseUrl)
41+
throws ParsingException, UnsupportedOperationException {
4142
return getUrl(id);
4243
}
4344

0 commit comments

Comments
 (0)