Skip to content

Commit 00b933f

Browse files
committed
Add YouTube bullet comments extractor
1 parent 943a41f commit 00b933f

7 files changed

Lines changed: 493 additions & 1 deletion

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.schabi.newpipe.extractor.services.youtube;
2+
3+
import org.schabi.newpipe.extractor.stream.StreamType;
4+
5+
public class WatchDataCache {
6+
public StreamType streamType;
7+
public long startAt;
8+
public boolean shouldBeLive = true;
9+
public String currentUrl;
10+
// save all the 4 last status
11+
public StreamType lastStreamType;
12+
public long lastStartAt;
13+
public boolean lastShouldBeLive = true;
14+
public String lastCurrentUrl;
15+
// use the url to instance the extractor, then save the current data to lasts
16+
public void init(final String url) {
17+
if (url.equals(currentUrl)) {
18+
return;
19+
}
20+
lastStreamType = streamType;
21+
lastStartAt = startAt;
22+
lastShouldBeLive = shouldBeLive;
23+
lastCurrentUrl = currentUrl;
24+
currentUrl = url;
25+
}
26+
27+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.schabi.newpipe.extractor.services.youtube;
2+
3+
import com.grack.nanojson.JsonObject;
4+
5+
public class YoutubeBulletCommentPair {
6+
private final JsonObject data;
7+
// the expected offset of the comment from the start of the video
8+
private final long offsetDuration;
9+
public YoutubeBulletCommentPair(final JsonObject item, final long offsetDuration) {
10+
this.offsetDuration = offsetDuration;
11+
this.data = item;
12+
}
13+
14+
public JsonObject getData() {
15+
return data;
16+
}
17+
18+
public long getOffsetDuration() {
19+
return offsetDuration;
20+
}
21+
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package org.schabi.newpipe.extractor.services.youtube;
22

33
import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.AUDIO;
4+
import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.BULLET_COMMENTS;
45
import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.COMMENTS;
56
import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.LIVE;
67
import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.VIDEO;
78

89
import org.schabi.newpipe.extractor.StreamingService;
910
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
1011
import org.schabi.newpipe.extractor.channel.tabs.ChannelTabExtractor;
12+
import org.schabi.newpipe.extractor.bulletComments.BulletCommentsExtractor;
1113
import org.schabi.newpipe.extractor.comments.CommentsExtractor;
1214
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
1315
import org.schabi.newpipe.extractor.feed.FeedExtractor;
@@ -25,6 +27,7 @@
2527
import org.schabi.newpipe.extractor.search.SearchExtractor;
2628
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeChannelExtractor;
2729
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeChannelTabExtractor;
30+
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeBulletCommentsExtractor;
2831
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeCommentsExtractor;
2932
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeFeedExtractor;
3033
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeMixPlaylistExtractor;
@@ -42,6 +45,7 @@
4245
import org.schabi.newpipe.extractor.services.youtube.extractors.kiosk.YoutubeTrendingPodcastsEpisodesExtractor;
4346
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeChannelLinkHandlerFactory;
4447
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeChannelTabLinkHandlerFactory;
48+
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeBulletCommentsLinkHandlerFactory;
4549
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeCommentsLinkHandlerFactory;
4650
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeLiveLinkHandlerFactory;
4751
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubePlaylistLinkHandlerFactory;
@@ -82,9 +86,10 @@
8286
*/
8387

8488
public class YoutubeService extends StreamingService {
89+
public WatchDataCache watchDataCache = new WatchDataCache();
8590

8691
public YoutubeService(final int id) {
87-
super(id, "YouTube", EnumSet.of(AUDIO, VIDEO, LIVE, COMMENTS));
92+
super(id, "YouTube", EnumSet.of(AUDIO, VIDEO, LIVE, COMMENTS, BULLET_COMMENTS));
8893
}
8994

9095
@Override
@@ -258,6 +263,17 @@ public CommentsExtractor getCommentsExtractor(final ListLinkHandler urlIdHandler
258263
return new YoutubeCommentsExtractor(this, urlIdHandler);
259264
}
260265

266+
@Override
267+
public ListLinkHandlerFactory getBulletCommentsLHFactory() {
268+
return YoutubeBulletCommentsLinkHandlerFactory.getInstance();
269+
}
270+
271+
@Override
272+
public BulletCommentsExtractor getBulletCommentsExtractor(final ListLinkHandler linkHandler)
273+
throws ExtractionException {
274+
return new YoutubeBulletCommentsExtractor(this, linkHandler, watchDataCache);
275+
}
276+
261277
/*//////////////////////////////////////////////////////////////////////////
262278
// Localization
263279
//////////////////////////////////////////////////////////////////////////*/

0 commit comments

Comments
 (0)