Skip to content

Commit 652c2c8

Browse files
AudricVStypox
andcommitted
Add a ListLinkHandler which can be used to be returned from ChannelInfo.getTabs() when a specific tab's data has already been fetched
This new ListLinkHandler, ReadyChannelTabListLinkHandler, should help saving clients data, energy and time by helping to reduce duplicate requests. Co-authored-by: Stypox <stypox@pm.me>
1 parent de823a6 commit 652c2c8

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package org.schabi.newpipe.extractor.linkhandler;
2+
3+
import org.schabi.newpipe.extractor.StreamingService;
4+
import org.schabi.newpipe.extractor.channel.tabs.ChannelTabExtractor;
5+
6+
import javax.annotation.Nonnull;
7+
import java.io.Serializable;
8+
import java.util.List;
9+
10+
/**
11+
* A {@link ListLinkHandler} which can be used to be returned from {@link
12+
* org.schabi.newpipe.extractor.channel.ChannelInfo#getTabs() ChannelInfo#getTabs()} when a
13+
* specific tab's data has already been fetched.
14+
*
15+
* <p>
16+
* This class allows passing a builder for a {@link ChannelTabExtractor} that can hold references
17+
* to variables.
18+
* </p>
19+
*
20+
* <p>
21+
* Note: a service that wishes to use this class in one of its {@link
22+
* org.schabi.newpipe.extractor.channel.ChannelExtractor ChannelExtractor}s must also add the
23+
* following snippet of code in the service's
24+
* {@link StreamingService#getChannelTabExtractor(ListLinkHandler)}:
25+
* <pre>
26+
* if (linkHandler instanceof ReadyChannelTabListLinkHandler) {
27+
* return ((ReadyChannelTabListLinkHandler) linkHandler).getChannelTabExtractor(this);
28+
* }
29+
* </pre>
30+
* </p>
31+
*/
32+
public class ReadyChannelTabListLinkHandler extends ListLinkHandler {
33+
34+
public interface ChannelTabExtractorBuilder extends Serializable {
35+
@Nonnull
36+
ChannelTabExtractor build(@Nonnull StreamingService service,
37+
@Nonnull ListLinkHandler linkHandler);
38+
}
39+
40+
private final ChannelTabExtractorBuilder extractorBuilder;
41+
42+
public ReadyChannelTabListLinkHandler(
43+
final String url,
44+
final String channelId,
45+
@Nonnull final String channelTab,
46+
@Nonnull final ChannelTabExtractorBuilder extractorBuilder) {
47+
super(url, url, channelId, List.of(channelTab), "");
48+
this.extractorBuilder = extractorBuilder;
49+
}
50+
51+
@Nonnull
52+
public ChannelTabExtractor getChannelTabExtractor(@Nonnull final StreamingService service) {
53+
return extractorBuilder.build(service, new ListLinkHandler(this));
54+
}
55+
}

0 commit comments

Comments
 (0)