Skip to content

Commit 943a41f

Browse files
committed
Add bullet comments core framework
1 parent 827d206 commit 943a41f

7 files changed

Lines changed: 372 additions & 2 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public enum InfoType {
7676
STREAM,
7777
PLAYLIST,
7878
CHANNEL,
79-
COMMENT
79+
COMMENT,
80+
BULLET_COMMENT
8081
}
8182
}

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
44
import org.schabi.newpipe.extractor.channel.tabs.ChannelTabExtractor;
5+
import org.schabi.newpipe.extractor.bulletComments.BulletCommentsExtractor;
56
import org.schabi.newpipe.extractor.comments.CommentsExtractor;
67
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
78
import org.schabi.newpipe.extractor.exceptions.ParsingException;
@@ -76,7 +77,7 @@ public Set<MediaCapability> getMediaCapabilities() {
7677
}
7778

7879
public enum MediaCapability {
79-
AUDIO, VIDEO, LIVE, COMMENTS
80+
AUDIO, VIDEO, LIVE, COMMENTS, BULLET_COMMENTS
8081
}
8182
}
8283

@@ -163,6 +164,9 @@ public String toString() {
163164
*/
164165
public abstract SearchQueryHandlerFactory getSearchQHFactory();
165166
public abstract ListLinkHandlerFactory getCommentsLHFactory();
167+
public ListLinkHandlerFactory getBulletCommentsLHFactory() {
168+
return null;
169+
}
166170

167171
/*//////////////////////////////////////////////////////////////////////////
168172
// Extractors
@@ -241,6 +245,10 @@ public abstract StreamExtractor getStreamExtractor(LinkHandler linkHandler)
241245

242246
public abstract CommentsExtractor getCommentsExtractor(ListLinkHandler linkHandler)
243247
throws ExtractionException;
248+
public BulletCommentsExtractor getBulletCommentsExtractor(
249+
final ListLinkHandler linkHandler) throws ExtractionException {
250+
return null;
251+
}
244252

245253
/*//////////////////////////////////////////////////////////////////////////
246254
// Extractors without link handler
@@ -303,6 +311,15 @@ public StreamExtractor getStreamExtractor(final String url) throws ExtractionExc
303311
return getStreamExtractor(getStreamLHFactory().fromUrl(url));
304312
}
305313

314+
public BulletCommentsExtractor getBulletCommentsExtractor(final String url)
315+
throws ExtractionException {
316+
final ListLinkHandlerFactory listLinkHandlerFactory = getBulletCommentsLHFactory();
317+
if (listLinkHandlerFactory == null) {
318+
return null;
319+
}
320+
return getBulletCommentsExtractor(listLinkHandlerFactory.fromUrl(url));
321+
}
322+
306323
public CommentsExtractor getCommentsExtractor(final String url) throws ExtractionException {
307324
final ListLinkHandlerFactory listLinkHandlerFactory = getCommentsLHFactory();
308325
if (listLinkHandlerFactory == null) {
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package org.schabi.newpipe.extractor.bulletComments;
2+
3+
import javax.annotation.Nonnull;
4+
5+
import org.schabi.newpipe.extractor.ListExtractor;
6+
import org.schabi.newpipe.extractor.Page;
7+
import org.schabi.newpipe.extractor.StreamingService;
8+
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
9+
import org.schabi.newpipe.extractor.exceptions.ParsingException;
10+
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
11+
12+
import java.io.IOException;
13+
import java.util.List;
14+
15+
public abstract class BulletCommentsExtractor extends ListExtractor<BulletCommentsInfoItem> {
16+
public BulletCommentsExtractor(final StreamingService service,
17+
final ListLinkHandler uiHandler) {
18+
super(service, uiHandler);
19+
}
20+
21+
@Nonnull
22+
@Override
23+
public String getName() throws ParsingException {
24+
return "BulletComments";
25+
}
26+
27+
@Override
28+
public InfoItemsPage<BulletCommentsInfoItem> getPage(final Page page)
29+
throws IOException, ExtractionException {
30+
return null;
31+
}
32+
33+
public List<BulletCommentsInfoItem> getLiveMessages() throws ParsingException {
34+
return null;
35+
}
36+
37+
public boolean isLive() {
38+
return false;
39+
}
40+
41+
public boolean isDisabled() {
42+
return false;
43+
}
44+
45+
public void disconnect() {
46+
47+
}
48+
49+
public void reconnect() {
50+
51+
}
52+
53+
public void setCurrentPlayPosition(final long currentPlayPosition) {
54+
}
55+
56+
public void clearMappingState() {
57+
}
58+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package org.schabi.newpipe.extractor.bulletComments;
2+
3+
import java.io.IOException;
4+
5+
import org.schabi.newpipe.extractor.ListInfo;
6+
import org.schabi.newpipe.extractor.utils.ExtractorLogger;
7+
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
8+
import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage;
9+
import org.schabi.newpipe.extractor.NewPipe;
10+
import org.schabi.newpipe.extractor.Page;
11+
import org.schabi.newpipe.extractor.StreamingService;
12+
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
13+
import org.schabi.newpipe.extractor.utils.ExtractorHelper;
14+
15+
public final class BulletCommentsInfo extends ListInfo<BulletCommentsInfoItem> {
16+
private BulletCommentsInfo(
17+
final int serviceId,
18+
final ListLinkHandler listUrlIdHandler,
19+
final String name) {
20+
super(serviceId, listUrlIdHandler, name);
21+
}
22+
23+
public static BulletCommentsInfo getInfo(final String url)
24+
throws IOException, ExtractionException {
25+
return getInfo(NewPipe.getServiceByUrl(url), url);
26+
}
27+
28+
public static BulletCommentsInfo getInfo(final StreamingService service, final String url)
29+
throws ExtractionException, IOException {
30+
return getInfo(service.getBulletCommentsExtractor(url));
31+
}
32+
33+
public static BulletCommentsInfo getInfo(final BulletCommentsExtractor commentsExtractor)
34+
throws IOException, ExtractionException {
35+
// for services which do not have a comments extractor
36+
if (commentsExtractor == null) {
37+
ExtractorLogger.d("BulletCommentsInfo", "getInfo() extractor is null");
38+
return null;
39+
}
40+
41+
ExtractorLogger.d("BulletCommentsInfo", "getInfo() fetching page for "
42+
+ commentsExtractor.getUrl());
43+
commentsExtractor.fetchPage();
44+
45+
final String name = commentsExtractor.getName();
46+
final int serviceId = commentsExtractor.getServiceId();
47+
final ListLinkHandler listUrlIdHandler = commentsExtractor.getLinkHandler();
48+
49+
final BulletCommentsInfo commentsInfo = new BulletCommentsInfo(
50+
serviceId, listUrlIdHandler, name);
51+
commentsInfo.setBulletCommentsExtractor(commentsExtractor);
52+
final InfoItemsPage<BulletCommentsInfoItem> initialCommentsPage = ExtractorHelper
53+
.getItemsPageOrLogError(commentsInfo, commentsExtractor);
54+
commentsInfo.setRelatedItems(initialCommentsPage.getItems());
55+
commentsInfo.setNextPage(initialCommentsPage.getNextPage());
56+
57+
return commentsInfo;
58+
}
59+
60+
public static InfoItemsPage<BulletCommentsInfoItem> getMoreItems(
61+
final BulletCommentsInfo commentsInfo,
62+
final Page page) throws ExtractionException, IOException {
63+
return getMoreItems(NewPipe.getService(commentsInfo.getServiceId()), commentsInfo.getUrl(),
64+
page);
65+
}
66+
67+
public static InfoItemsPage<BulletCommentsInfoItem> getMoreItems(
68+
final StreamingService service,
69+
final BulletCommentsInfo commentsInfo,
70+
final Page page) throws IOException, ExtractionException {
71+
return getMoreItems(service, commentsInfo.getUrl(), page);
72+
}
73+
74+
public static InfoItemsPage<BulletCommentsInfoItem> getMoreItems(
75+
final StreamingService service,
76+
final String url,
77+
final Page page) throws IOException, ExtractionException {
78+
return service.getBulletCommentsExtractor(url).getPage(page);
79+
}
80+
81+
private transient BulletCommentsExtractor commentsExtractor;
82+
83+
public BulletCommentsExtractor getBulletCommentsExtractor() {
84+
return commentsExtractor;
85+
}
86+
87+
public void setBulletCommentsExtractor(
88+
final BulletCommentsExtractor bulletCommentsExtractor) {
89+
this.commentsExtractor = bulletCommentsExtractor;
90+
}
91+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package org.schabi.newpipe.extractor.bulletComments;
2+
3+
import java.time.Duration;
4+
5+
import org.schabi.newpipe.extractor.InfoItem;
6+
7+
import javax.annotation.Nonnull;
8+
9+
public class BulletCommentsInfoItem extends InfoItem implements Comparable<BulletCommentsInfoItem> {
10+
@Override
11+
public int compareTo(@Nonnull final BulletCommentsInfoItem bulletCommentsInfoItem) {
12+
return this.duration.compareTo(bulletCommentsInfoItem.duration);
13+
}
14+
15+
public enum Position {
16+
REGULAR,
17+
BOTTOM,
18+
TOP,
19+
SUPERCHAT
20+
}
21+
22+
private String commentText;
23+
private int argbColor;
24+
private Position position;
25+
private double relativeFontSize;
26+
/* It really should be named as timePosition or some other thing*/
27+
private Duration duration;
28+
private int lastingTime;
29+
private boolean isLive;
30+
31+
public BulletCommentsInfoItem(final int serviceId, final String url, final String name) {
32+
super(InfoType.COMMENT, serviceId, url, name);
33+
}
34+
35+
public String getCommentText() {
36+
return commentText;
37+
}
38+
39+
public void setCommentText(final String commentText) {
40+
this.commentText = commentText;
41+
}
42+
43+
public int getArgbColor() {
44+
return argbColor;
45+
}
46+
47+
public void setArgbColor(final int argbColor) {
48+
this.argbColor = argbColor;
49+
}
50+
51+
public Position getPosition() {
52+
return position;
53+
}
54+
55+
public void setPosition(final Position position) {
56+
this.position = position;
57+
}
58+
59+
public double getRelativeFontSize() {
60+
return relativeFontSize;
61+
}
62+
63+
public void setRelativeFontSize(final double relativeFontSize) {
64+
this.relativeFontSize = relativeFontSize;
65+
}
66+
67+
public Duration getDuration() {
68+
return duration;
69+
}
70+
71+
public void setDuration(final Duration duration) {
72+
this.duration = duration;
73+
}
74+
75+
public int getLastingTime() {
76+
return -1;
77+
}
78+
79+
public void setLastingTime(final int lastingTime) {
80+
this.lastingTime = lastingTime;
81+
}
82+
83+
public boolean isLive() {
84+
return isLive;
85+
}
86+
87+
public void setLive(final boolean live) {
88+
isLive = live;
89+
}
90+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package org.schabi.newpipe.extractor.bulletComments;
2+
3+
import org.schabi.newpipe.extractor.InfoItemExtractor;
4+
import org.schabi.newpipe.extractor.exceptions.ParsingException;
5+
6+
import java.time.Duration;
7+
import java.util.Collections;
8+
import java.util.List;
9+
10+
public interface BulletCommentsInfoItemExtractor extends InfoItemExtractor {
11+
@Override
12+
default String getName() throws ParsingException {
13+
return null;
14+
}
15+
16+
@Override
17+
default List<org.schabi.newpipe.extractor.Image> getThumbnails() throws ParsingException {
18+
return Collections.emptyList();
19+
}
20+
21+
@Override
22+
default String getUrl() throws ParsingException {
23+
return null;
24+
}
25+
26+
default String getCommentText() throws ParsingException {
27+
return "";
28+
}
29+
30+
/**
31+
* Returns ARGB32 int. White: 0xFFFFFFFF.
32+
* @return ARGB32 int. White: 0xFFFFFFFF.
33+
*/
34+
default int getArgbColor() throws ParsingException {
35+
return 0xFFFFFFFF;
36+
}
37+
38+
default BulletCommentsInfoItem.Position getPosition() throws ParsingException {
39+
return BulletCommentsInfoItem.Position.REGULAR;
40+
}
41+
42+
default double getRelativeFontSize() throws ParsingException {
43+
return 0.7;
44+
}
45+
46+
default int getLastingTime() {
47+
return -1;
48+
}
49+
50+
default boolean isLive() throws ParsingException {
51+
return false;
52+
}
53+
54+
// Must be implemented. If that is a live stream you should at least
55+
// calculate the time from the start of the stream.
56+
Duration getDuration() throws ParsingException;
57+
}

0 commit comments

Comments
 (0)